What does DX + 2 mean in mov ah,9 int 21h?

自闭症网瘾萝莉.ら 提交于 2019-12-02 11:04:54

问题


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 address ds:dx +2.


回答1:


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 :

mov dx, offset buff + 2

or this one (both are equivalent):

mov dx, offset buff
add dx, 2

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 :

.stack 100h
.data
msg  db 'Enter text : $'
text db 11        ;MAX LENGTH ALLOWED.
     db ?         ;LENGTH ENTERED.
     db 11 dup(?) ;CHARACTERES.
.code
  mov  ax, @data
  mov  ds, ax

;DISPLAY MESSAGE TO USER.  
  mov  dx, offset msg
  mov  ah, 9
  int  21h

;CAPTURE TEXT.  
  mov  dx, offset text
  mov  ah, 0Ah
  int  21h            

;REPLACE ENTER WITH $.
  mov  bl, '$'
  mov  si, offset text + 1  ;◄■ POSITION OF LENGTH ENTERED.
  mov  al, [si]             ;◄■ GET LENGTH ENTERED.
  mov  ah, 0                ;◄■ CLEAR AH TO USE AX.
  add  si, ax               ;◄■ SI POINTS TO LAST CHAR.
  inc  si                   ;◄■ +1 TO POINT TO CHAR 13.
  mov  [si], bl             ;◄■ REPLACE 13 WITH '$'.

  mov  ax, 4c00h
  int  21h


来源:https://stackoverflow.com/questions/30807183/what-does-dx-2-mean-in-mov-ah-9-int-21h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!