你如何在 TASM 中编写减法代码

How do you code subtraction in TASM

好的,所以我的代码基于我们拥有的 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

好的,我想我明白了:D

;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