Search code examples
tasm

How do you code subtraction in TASM


Okay so I based my codes from the turbo assembler manual that we have...i tried to swap registers and it worked only for the inverse subtraction example 1-2= -1...now my problem in this code is that when the first number is greater than the second number, i cannot get the correct answer

;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

Solution

  • ok so i guess i got it :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