DX + 2在mov ah,9 int 21h中是什么意思? [英] What does DX + 2 mean in mov ah,9 int 21h?

查看:947
本文介绍了DX + 2在mov ah,9 int 21h中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我知道 buffer [bx + 2] 代表 $,但 mov中的偏移缓冲区+2 ah,9 代表什么?

I know buffer[bx+2] stands for '$', but offset buffer +2 in mov ah,9 stands for what?

他们说,


从地址 DS:DX + 2 开始打印。从地址 ds:dx +2


推荐答案

当使用int 21h,ah = 0Ah从键盘捕获字符串时,该字符串具有下一个结构:

When a string is captured from keyboard with int 21h, ah=0Ah, the string has next structure:

如您所见,前两个字节是控件,输入的字符由用户从第三个字节(字节2)开始。最后一个字符是chr(13)(输入键)。

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).

要显示此捕获的字符串,其int为21h,ah = 09h,则必须替换最后一个chr( 13)按 $,然后使DX指向以第三个字节开头的有效字符:

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

下图说明了用 $替换chr(13)的方法:注意捕获的字符串的长度在第二个字节(字节1)中,我们必须将此长度添加到到达最后一个字节chr(13),现在我们可以替换它:

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:

接下来的代码是:

.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

这篇关于DX + 2在mov ah,9 int 21h中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆