CODESG SEGMENT
ASSUME CS:CODESG, DS:CODESG. SS:CODESG
ORG 100H
BEGIN: MOV AX,01
MOV BX,02
MOV DX,03
MOV CX,04
L20: INC AX
ADD BX,AX
SHR DX,1
( )
RET
CODESG ENDS
END BEGIN
答案:
(1)(AX)= 5 (BX)= 16 (CX)= 0 (DX)= 0
(2)(AX)= 2 (BX)= 4 (CX)= 3 (DX)= 1
(3)(AX)= 3 (BX)= 7 (CX)= 2 (DX)= 0
18. 变量N1和N2均为2字节的非压缩BCD数码,请写出计算N1与N2之差的指令序列。
答案:
MOV AX, 0
MOV AL, N1+1
SUB AL, N2+1
AAS
MOV DL, AL
MOV AL, N1
SBB AL, N2
AAS
MOV DH, AL
19. 有两个3位的ASCII数串ASC1和ASC2定义如下:
ASC1 DB '578'
ASC2 DB '694'
ASC3 DB '0000'
请编写程序计算ASC3←ASC1+ASC2。
答案:
CLC
MOV CX, 3
MOV BX, 2
BACK:
MOV AL, ASC1[BX]
ADC AL, ASC2[BX]
AAA
OR ASC3[BX+1], AL
DEC BX
LOOP BACK
RCL CX, 1
OR ASC3[BX], CL
20. 假设(CS)=3000H, (DS)=4000H, (ES)=2000H, (SS)=5000H, (AX)=2060H, (BX)=3000H, (CX)=5, (DX)=0, (SI)=2060H, (DI)=3000H, (43000H)=0A006H, (23000H)=0B116H, (33000H)=0F802H, (25060)=00B0H,.(SP)=0FFFEH, (CF)=1, (DF)=1, 请写出下列各条指令单独执行完后, 有关寄存器及存储单元的内容, 若影响条件码请给出条件码SF、ZF、OF、CF的值。
(1) SBB AX,BX (2) CMP AX,WORD PTR[SI+0FA0H]
(3) MUL BYTE PTR[BX] (4) AAM
(5) DIV BH (6) SAR AX,CL
(7) XOR AX,0FFE7H (8) REP STOSB
(9) JMP WORD PYR[BX] (10) XCHG AX,ES:[BX+SI]
答案:
(1) (AX)=0F05FH, (SF)=1, (ZF)=0, (OF)=0, (CF)=1
(2) (SF)=1, (ZF)=0, (OF)=1, (CF)=1
(3) (AX)=0240H, (OF)=1, (CF)=1
(4) (AX)=0906H, (SF)=0, (ZF)=0
(5) (AX)=20ACH
(6) (AX)=0103H, (CF)=0
(7) (AX)=0DF87H, (CF)=0, (OF)=0, (SF)=1, (ZF)=0
(8) (23000H)~(23004H)=60H, 不影响标志位
(9) (IP)=0A006H, 不影响标志位
(10) (AX)=00B0H, (25060)=2060H, 不影响标志位
第6章 汇编语言程序设计基础
1. 试编写一个汇编语言程序,要求对键盘输入的小写字母用大写字母显示出来。
答案:
abc: mov ah,1
int 21h
cmp al,'a'
jb stop
cmp al,'z'
ja stop
sub al,20h
mov dl,al
mov ah,2
int 21h
jmp abc
stop: ret
2. 编写程序,比较两个字符串STRING1和STRING2所含字符是否完全相同,若相同则显示"MATCH",若不同则显示"NO MATCH"。
答案:
datarea segment
string1 db 'asfioa'
string2 db 'xcviyoaf'
mess1 db 'MATCH','$'
mess2 db 'NO MATCH','$'
datarea ends
prognam segment
main proc far
assume cs:prognam,ds:datarea
start:
push ds