mov dx, offset buffer
mov ah, 0ah
int 21h
jmp print
buffer db 10,?, 10 dup(' ')
print:
xor bx, bx
mov bl, buffer[1]
mov buffer[bx+2], '$'
mov dx, offset buffer + 2
mov ah, 9
int 21h
I know buffer[bx+2]
stands for '$', but offset buffer +2
in mov ah,9
stands for what?
They said,
"Start printing from address
DS:DX + 2
". From addressds:dx +2
.
When a string is captured from keyboard with int 21h, ah=0Ah, the string has next structure:
As you can see, the first two bytes are control, the characters entered by user start at the third byte (byte 2). The last char is chr(13) (ENTER key).
To display this captured string with int 21h, ah=09h, you will have to replace the last chr(13) by '$', then make DX to point to the valid characters that start at the third byte :
or this one (both are equivalent):
The way to replace chr(13) by '$' is explained in next image : notice the length of the captured string is in the second byte (byte 1), we have to add this length to reach the last byte chr(13), now we can replace it:
Next is the code :