.model small
.stack 100h
.data
msg1 db '2 - 5 = $'
result db '-$'
.code
main proc
mov ax, @data
mov ds, ax
; subtract 5 from 2
mov al, 2
sub al, 5
aas
; print the result as -3
mov ah, 9
lea dx, msg1
int 21h
; check if the result is negative
cmp ah, 0
jz print_positive
; if the result is negative, print a '-' character
mov ah, 2
mov dl, '-'
int 21h
; convert the absolute value of the result to ASCII characters
print_positive:
mov ah, 0
neg al ; negate the result to get the absolute value
add al, 48
mov result+1, al
mov ah, 2
lea dx, result
int 21h
mov ah, 4ch
int 21h
main endp
end main
This code is for 8086 microprocessor to perform subtraction and show negative number on the screen.
I write the code so that it produces 2-5=-3 on the screen. But it doesn't print 3. It prints 2-5=-. Any reason why?