好吧所以我根据我们的turbo汇编程序手册编写代码...我试图交换寄存器,它只适用于逆减法示例1-2 = -1 ...现在我的问题在这段代码中是当第一个数字大于第二个数字时,我无法得到正确的答案
;Subtract
.MODEL Small
.STACK 100h
.DATA
Start DB 13,10,'Subtract 2 numbers!$'
FOne DB 13,10,'Enter first set number1: $'
FTwo DB 13,10,'Enter first set number2: $'
Diff1 DB 13,10,'Difference is: $'
.CODE
mov ax,@data
mov ds,ax
mov dx,OFFSET Start
mov ah,09h
int 21h
mov dx, OFFSET FOne
mov ah,09h
int 21h
mov ah,01h
int 21h
MOV BL,AL
AND BL,0Fh
mov dx, OFFSET FTwo
mov ah,09h
int 21h
mov ah,01h
int 21h
AND AL,0Fh
compare:
cmp AL,BL
jge reverse
jnz normal
normal:
mov ah,00h
SUB BL,AL
AAS
OR AX,3030h
MOV BX,AX
mov dx,OFFSET Diff1
mov ah,09h
int 21h
mov dl,Bh
mov ah,02h
int 21h
mov dl,Al
int 21h
mov ah,02h
jmp exit
reverse:
mov ah,00h
SUB AL,BL
AAS
OR AX,3030h
MOV BX,AX
mov dx,OFFSET Diff1
mov ah,09h
int 21h
mov dl,"-"
mov ah,02h
int 21h
mov dl,Bh
mov ah,02h
int 21h
mov dl,Bl
mov ah,02h
int 21h
jmp exit
exit:
mov ah,4ch
int 21h
END
答案 0 :(得分:0)
;Subtract
.MODEL Small
.STACK 100h
.DATA
Start DB 13,10,'Subtract 2 numbers!$'
FOne DB 13,10,'Enter first set number1: $'
FTwo DB 13,10,'Enter first set number2: $'
Diff1 DB 13,10,'Difference is: $'
Rtry DB 13,10,'Enter new inputs?[y][n]: $'
.CODE
mov ax,@data
mov ds,ax
mov dx,OFFSET Start
mov ah,09h
int 21h
mov dx, OFFSET FOne
mov ah,09h
int 21h
mov ah,01h
int 21h
MOV BL,AL
AND BL,0Fh
mov dx, OFFSET FTwo
mov ah,09h
int 21h
mov ah,01h
int 21h
MOV BH,AL
AND AL,0Fh
compare:
cmp AL,BL
jg reverse
jnz normal
normal:
mov ah,00h
SUB BL,BH
MOV AL,BL
AAS
OR AX,3030h
MOV BX,AX
mov dx,OFFSET Diff1
mov ah,09h
int 21h
mov dl,Bh
mov ah,02h
int 21h
mov dl,Bl
int 21h
mov ah,02h
jmp exit
reverse:
mov ah,00h
SUB AL,BL
MOV BH,AL
AAS
OR AX,3030h
MOV BX,AX
mov dx,OFFSET Diff1
mov ah,09h
int 21h
mov dl,"-"
mov ah,02h
int 21h
mov dl,Bh
mov ah,02h
int 21h
mov dl,BL
mov ah,02h
int 21h
jmp exit
exit:
mov ah,4ch
int 21h
END