Reputation: 195
Can someone define me the exact purpose of the and
keyword in assembly? I have provided a code here can someone explain me what the and
does in this code? By the way the and
is located somewhere under begin
just for you to locate it easily.
code segment
assume cs:code;ds:code
org 100h
begin:
mov ah, 09
mov dx, offset msg1
int 21h
mov ah,01h ;ask user
int 21h
and al,01h
jz EVENn
mov ah, 09 ;display string
mov dx, offset oddmsg
int 21h
jmp ENDd
EVENn:
mov ah, 09 ;display string
mov dx, offset evenmsg
int 21h
ENDd:
int 20h
msg1:db 'enter a number: $'
evenmsg:db 0ah,0dh, 'EVEN $'
oddmsg:db 0ah,0dh, 'ODD$'
code ends
end begin
Upvotes: 0
Views: 4032
Reputation: 700152
The and
opreator does a logical and operation.
In this case it's used to mask out a single bit in a value. If you for example get the value 6Dh
in al
(the character m
read from STDIN), the operation leaves only the least significant bit:
6Dh 01101101
01h 00000001
--------------- and
00000001
An even character code gives the result 00h
, and an odd character code gives the result 01h
.
Upvotes: 1