NASM equivalent for MASM code

assembly, masm, nasm

Solution

I tried out this code with NASM. Here's what I found:

- eliminate "offset", e.g.: `mov dx, offset nameprompt` -> `mov dx, nameprompt`

- as Brendan commented, lines like `buffer[bx+2]` -> `[buffer+bx+2]`

- `offset buffer + 2` -> `buffer + 2`

- this line appears invalid: `buffer db 255,0,255 dup(0)`; according to the NASM manual, dup isn't available-- look for the TIMES directive (see this section of the manual)

Problem

I'm trying to write a code to read a user input string in assembly language but i'm forced to use NASM. The code below is designed for MASM and I want to 'translate' to NASM but I'm having problem with 'buffer' instructions. Why can't i declare something like buffer[bx+2]? What is the correct 'translation' ? ``` org 100h mov ah, 09h ; print function mov dx, offset nameprompt int 21h mov ah, 0ah ; buffered string input mov dx, offset buffer int 21h mov ah, 09h mov dx, offset crlf int 21h mov dx, offset yourname int 21h xor bx, bx mov bl, buffer[1] mov buffer[bx+2], '$' mov dx, offset buffer + 2 int 21h mov ax, 4c00h int 21h buffer db 255,0,255 dup(0) nameprompt db "Enter your name: $" yourname db "Your name is: $" crlf db 13,10,"$" ```

Original source