nl DB 13, 10, '$' ,int 21h详解

nl DB 13, 10, '$'
13是回车
10是换行
 '$'表示已经到了字符串尾,不在打印字符了。
int 21                                         调用参数                                                                                             返回参数
AH=09  显示字符串               DS:DX=串地址,'$'结束字符串
AH=0A  键盘输入到缓冲区      DS:DX=缓冲区首地址                                                  (DS:DX)=缓冲区最大字符数  (DS:DX+1)=实际输入的字符数

#make_COM#
        ORG  100H 

; set data segment:
        MOV AX, CS
        MOV DS, AX
        MOV ES, AX

; input a string:
        MOV DX, OFFSET s1
        MOV AH, 0AH
        INT 21h

; get one line down,by printing new line characters:                        //13 10 "$"打印一个换行
        MOV DX, offset nl
        MOV AH, 9
        INT 21h

; set '$' to the end of inputed string:                                             //为输入的字符串加入 '$'
        MOV DI, offset s1
        XOR BX, BX
; second byte of buffer holds ,the number of inputed,characters : //buffer的第二个字节为字符的长度,即[DI+1]=
        MOV BL, [DI+1]                                                                   //如果你输入wanghj,那么[DI+1]=6,bl也等于6,bx也等于6
        MOV BYTE PTR [DI+BX+2], '$'                                              //所以'$'  放在第8个字节的地方,也是wanghj的尾部

; print the entered string:
        MOV DX, offset s1
; first byte is buffer size, second actual characters;                       //0放的是能输入的最大字符,1放的是输入字符的个数,所以要跳过这两个字符
; these 2 bytes:
        ADD DX, 2
        MOV AH, 9
        INT 21h

; exit to operating
; system:
        MOV AH, 4Ch
        INT 21h

; data:
s1 DB 30, 30 dup(' ')
nl DB 13, 10, '$'

END

posted on 2011-05-15 09:37  wanghj_dz  阅读(1106)  评论(0编辑  收藏  举报

导航