Method 1:Use rotate instructions to check the given number is positive or negative.
.model small
.stack 100h
.data
msg_pos db 'The number is Positive.$'
msg_neg db 'The number is Negative.$'
.code
main:
mov ax, @data
mov ds, ax
mov al, -8 ; Load a number to check (you can change this)
; Rotate MSB into Carry Flag
rol al, 1 ; MSB -> CF, AL is rotated left by 1 bit
; Now CF = original MSB
jc is_negative ; If CF = 1 (i.e., original MSB = 1), it's negative
is_positive:
lea dx, msg_pos
mov ah, 09h
int 21h
jmp exit
is_negative:
lea dx, msg_neg
mov ah, 09h
int 21h
exit:
mov ah, 4ch
int 21h
end main
Methode 2: Using Test instruction
.model small
.stack 100h
.data
msg_pos db 'The number is Positive.$'
msg_neg db 'The number is Negative.$'
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, -5 ; Load a number to test (you can change this value)
; Check sign of AL
test al, al ; Sets flags based on AL (including Sign flag)
jns is_positive ; Jump if Sign Flag = 0 (i.e., number is positive)
is_negative:
lea dx, msg_neg
mov ah, 09h
int 21h
jmp exit
is_positive:
lea dx, msg_pos
mov ah, 09h
int 21h
exit:
mov ah, 4ch
int 21h
end main