0% found this document useful (0 votes)
23 views2 pages

Assembly Code for Number Sign Check

The document presents two methods in assembly language to determine if a given number is positive or negative. Method 1 uses rotate instructions to check the most significant bit, while Method 2 employs the test instruction to evaluate the sign flag. Both methods display corresponding messages based on the number's sign.

Uploaded by

shruticpatil07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Assembly Code for Number Sign Check

The document presents two methods in assembly language to determine if a given number is positive or negative. Method 1 uses rotate instructions to check the most significant bit, while Method 2 employs the test instruction to evaluate the sign flag. Both methods display corresponding messages based on the number's sign.

Uploaded by

shruticpatil07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like