习题课
例1:
设在缓冲区DATA中存放着12个组合的BCD码,求它们的和,把结果放在缓冲区SUM中。
…
DATA DB 23, 45, ……
SUM DB 2DUP( 0 )
…
MOV AX, SEGMENT DATA
MOV DS, AX
MOV BX, OFFSET DATA
MOV CD, 12
XOR AL, AL
NEXT: ADD AL, [BX]
DAA
ADC AH, 0
XCHG AH, AL
DAA
XCHG AH, AL
INC BX
LOOP NEXT
XCHG AH, AL
MOV WORD PTR SUM, AX
例2:
利用DAA指令把一位十六进制数转换为对应ASCII码的子程序 HTOASC
; 子程序名: HTOASC
; 功能 : 把一位十六进制数转换为对应ASCII码
; 入口参数: AL的低4位为要转换的十六进制数
; 出口参数: AL为对应的ASCII码
HTOASC PROC
AND AL, 0FH
ADD AL, 90H
DAA
ADC AL, 60H
DAA
RET
HTOASC ENDP
例3: 编程计算非压缩BCD码的加法运算
SUM <— 962+853
将结果显示在屏幕上
DATA SEGMENT
ASC1 DB '2', '6', '9'
ASC2 DB '3', '5', '8'
ASUM DB 4DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
BEGIN: MOV AX, DATA
MOV DS, AX
MOV ES, AX
CLD
MOV SI, OFFSET ASC1
MOV BX, OFFSET ASC2
MOV DI, OFFSET ASUM
MOV AH, 00H
LOP1: LODS ASC1
SAHF
ADC AL, [BX]
AAA
LAHF
OR AL, 30H
STOSB
INC BX
LOOP LOP1
AND AH, 01H
OR AH, 30H
MOV [DI], AH
MOV AH, 02H
MOV CX, 04H
LOP2: MOV DL, [DI]
INT 21H
DEC DI
LOOP LOP2
例4:
编写一个四字节压缩BCD码减法运算
要求 BSUB=84512458 – 52364785
DATA SEGMENT
BCD1 DB 58H, 24H, 51H, 84H
BCD2 DB 85H, 47H, 36H, 52H
BSUB DB 4DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV CX, 4
MOV SI, 0
CLC
LOP1
MOV AL, BCD1[SI]
SBB AL, BCD2[SI]
DAS
MOV BSUB[SI], AL
INC SI
LOOP LOP1
MOV AH, 4CH
INT 21H
CODE ENDS
END START
例5:
在内存单元中,DVD1中存放着一双字节被除数,DVD2单元存放着一单字节除数,它们均为无符号整数,编程求其商和余数,分别放在DIFD和REM内
DATA SEGMENT
DVD1 DW 2548
DVD2 DW 32
DIFD DW ?
REM DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
BEGIN: MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV AX, DVD1
MOV BL, DVD2
CMP AH, BL
JB DIV_4
DIV_8: XOR DX, DX
XOR BH, BH
DIV BX
MOV DIFD, AX
MOV REM, DX
JMP END
DIV_4: DIV BL
MOV BYTE PTR DIFD, AL
MOV BYTE PTR REM, AH
END: MOV AH, 4CH
INT 21H
CODE ENDS
END BEGIN