初级汇编语言

汇编调试程序DEBUG的常用命令和功能,DEBUG环境下调试程序的方法.

 

  1. 两个无符号数相加,将结果数存入指定地址单元。被加数,加数及和存放地址及数据如下:

             地址             数据

被加数 20000000         9FH

       20000001         6BH

 加数  20000002         5CH

       20000003         42H

     20000004          

     ~ 20000006

 

-e 2000:0000 9f 6b 5c 42
-a 1000:0
mov ax,[0000H]
mov bx,[0002H]
add ax,bx
mov 2000:[0004],ax
-r cs
1000
-r ip
0
-t -t -t -t

 

 

 

  2.两个无符号数相减,将差存入指定地址单元。被减数,减数及差的存放地址及数据如下:

             地址             数据

被减数    20000100          8C

          20000101          42

  减数    20000102          92

          20000103          5A

        20000104

          20000105

 

-e 2000:0100 8c 42 92 5a
-a 1000:0
mov ax,2000:[0100H]
mov bx,2000:[0102]
sub ax,bx
mov 2000:[0104],ax
-r cs
1000
-r ip
0
-t -t -t -t

 

 

  3.两个无符号数相乘,将积存入指定地址单元。被乘数,乘数及积存放的地址及数据如下:

              地址            数据

被乘数    20001000           56

          20001001           2C

  乘数    20001002           3A

          20001003           1C

        20001004

        ~ 20001007

 

-e 2000:0200 56 2C 3A 1C
-a 1000:0000
mov ax,2000:[1000]
mov bx,2000:[1002]
mul bx
mov 2000:[1004],ax
mov 20000:[1006],dx
-r cs
1000
-r ip
0
-t -t -t -t -t

 

 

  4.两个无符号数相除,将商及余数存入指定的地址单元。被除数,除数,商及余数存放的地址及数据如下:

             地址             数据

被除数    20000200          2A

          20000201          3B

          20000202          4C

          20000203          5D

  除数    20000204          7C

          20000205          5D

        20000206

          20000207

  余数    20000208

          20000209

 

-e 2000:0200 2a 3b 4c 5d 7c 5d
-a 1000:0
mov ax,2000:[0200]
mov bx,2000:[0202]
div bx
mov 2000:[0206],ax
mov 2000:[0208],dx
-r cs
1000
-r ip
0
-t -t -t -t -t

 

 

屏幕显示计算机提问:

Do you like this book ?

若用户回答N, 计算机回答:

You may go to the next store.

若用户回答Y, 计算机回答:

  I think you will buy it.

 

DATA SEGMENT 
    SEN1 DB 0DH,0AH,"Do you like this book ",0x3fh,0DH,0AH,"$"
    SEN2 db 0DH,0AH,"You may go to the next store.",0DH,0AH,"$"
    SEN3 DB 0DH,0AH,"I think you will buy it",0DH,0AH,"$"
    SEN4 DB 0DH,0AH,"Please input a word(Y or N)",0DH,0AH,"$"
DATA ENDS

CODE SEGMENT
    ASSUME DS:DATA,CS:CODE 
    START:MOV AX,DATA
    MOV DS,AX 
    MOV Ah,2h                 
    MOV BH,0
    MOV DH,5
    MOV DL,12 
    INT 10H
    
   BEAGIN: MOV DX,OFFSET SEN1
    MOV AH,09H
    INT 21H
    
    MOV AH,01H
    INT 21H 
    MOV AH,09H
    CMP AL,'N'
    JE NOT
    CMP AL,'Y'
    JE OK
    CMP AL,'Q'
    JE END
    JMP KEY
    OK: MOV DX,OFFSET SEN2
    INT 21H
    JMP BEAGIN
    
    NOT: MOV DX,OFFSET SEN3
    INT 21H
    JMP BEAGIN
    
    KEY:MOV DX,OFFSET SEN4
    INT 21H
    JMP BEAGIN
    END: NOP 
    MOV AH,4CH
    INT 21H
CODE ENDS
END START

屏幕显示计算机提问:

Would you like tea or coffee?

用户用键盘输入回答,并显示出来.

 

DATA SEGMENT 
    SEN DB 0dh,0ah,"Would you like tea or coffee",0x3fh,0dh,0ah,"$"
    SEN2 DB 0dh,0ah,"Your input is:","$"
    SEN3 DB 0DH,0AH,"$"
    STRING DB 20,0,20 DUP(0)
DATA ENDS

CODE SEGMENT
    ASSUME DS:DATA,CS:CODE 
    START:MOV AX,DATA
    MOV DS,AX 
    MOV Ah,2h                 
    MOV BH,0
    MOV DH,5
    MOV DL,12 
    INT 10H
    
    MOV DX,OFFSET SEN
    MOV AH,09H
    INT 21H
    
    MOV DX,OFFSET STRING
    MOV AH,0AH
    INT 21H
    MOV CL,STRING+1
    XOR CH,CH
    ADD DX,CX
    MOV BX,DX
    MOV BYTE PTR[BX+2],'$'
    MOV AH,09H
    MOV DX,OFFSET SEN3
    INT 21H
    MOV DX,OFFSET STRING
    ADD DX,2
    INT 21H
   
    MOV AH,4CH
    INT 21H
CODE ENDS
END START

 

 

 按宏汇编语言程序的格式,采用INT 21H  0A号功能调用显示一字符串:
   ‘I  hope  you  work  hard
DATA SEGMENT
    SEN DB 30,0,30 DUP(0)
    QUE DB "Please input a string which would be displayed on the screen:",0dh,0ah,"$"
    QUE1 DB 0dh,0ah,"Your input sentence is :",0dh,0ah,"$"
DATA ENDS


CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
    START:MOV AX,DATA
    MOV DS,AX 
    MOV AH,9
    MOV DX,OFFSET QUE
    INT 21H
    
    MOV AH,0AH
    MOV DX,OFFSET SEN
    INT 21H
    MOV CL,SEN+1 
    MOV CH,0
    ADD DX,CX
    MOV BX,DX
    MOV BYTE PTR[BX+2],"$"
    MOV AH,9
    LEA DX,QUE1
    INT 21H
    LEA DX,SEN
    ADD DX,2
    INT 21H
    
    MOV AH,4CH
    INT 21H
    CODE ENDS
END START

按宏汇编语言程序程序的格式,采用INT 21H 2号功能调用显示:
‘ I like computer very much

 

data segment
str db "I like computer very much."
count EQU $-str
data ends

code segment
assume ds:data, cs:code
start:mov ax, data
mov ds, ax

MOV AH,2
MOV DH,10
MOV DL,20
INT 10H
mov di, offset str
mov cx, count
MOV AH,02H
S:PUSH CX
MOV CX,1
MOV BH,0
MOV AH,9
MOV BL,10100101B
INT 10H
MOV AH,2
mov DL,[DI]
int 21h
INC DI
POP CX
LOOP S
 

MOV AH,4CH
INT 21H

code ends
end start

posted @ 2020-05-22 23:23  为红颜  阅读(675)  评论(0编辑  收藏