Thursday, December 24, 2009

Assembly Language Part 6

Logic Instructions

The ability to manipulate the individual bits of a Data is one of the key advantages of assembly language. In order to do so we use Logic instructions. Let us first remind the basic ligic instructions for now,


AND 
 0 0 -> 0
 1 0 -> 0
 0 1 -> 0
 1 1 -> 1

OR 
 0 0 -> 0
 1 0 -> 1
 0 1 -> 1
           1 1 -> 1            



XOR 
 0 0 -> 0
 1 0 -> 1
 0 1 -> 1
 1 1 -> 0


NOT

 0 -> 1
 1 -> 0
 

Now lets see where we use these functions in Assembly -

AND   ->  To clear
OR     ->  To set
XOR   ->  To compliment desired bit positions
NOT   ->  To compliment all bits

AND (Used to Clear )

The form is
AND DESTINATION, SOURCE

Suppose we want to clear the sign bit of AL then the code will be

AND AL,7Fh                            ;

we know that the sign bit is the MSB so if we AND it with the value which has all 1s except of the MSB as 0 then

AL   =   10101100
Msk =   01111111

-----------------------------
rslt  =   00101100


OR (used to set)

The form is
OR DESTINATION, SOURCE

Suppose we want to set the sign bit of AL then the code will be

OR AL,80h                            ;

we know that the sign bit is the MSB so if we OR it with the value which has all 0s except of the MSB as 1 then

AL   =   00101100
Msk =   10000000
-----------------------------
rslt  =   10101100

XOR (Used to compliment selected bits )

The form is
XOR DESTINATION, SOURCE

Suppose we want to change the sign bit of AL then the code will be

XOR AL,80h                            ;

we know that the sign bit is the MSB so if we XOR it with the value which has all 0s except of the MSB which is 1 then


AL   =   10101100
Msk =   10000000
-----------------------------
rslt  =   00101100

Here you may have noticed that destination bit is complimented if that bit position of the Mask is 1 and unchanged if it is 0. (XOR x , 0 - x) (XOR  x,1)= x'



NOT (Used to compliment all bits )

The form is
NOT DESTINATION

Suppose we want to invert all the bits of AL then the code will be

NOT AL                            ;

You can see that NOT takes only one argument.

Suppose AL = 10110010 , after executing the NOT instruction it will be 01001101


Problem (Convert ASCII value to number)
When we enter a character in Assembly the equivalent ASCII value is stored in the memory. Say we pressed 3 then the ASCII value 33h will be saved in AL. we have to convert it to 3...

If we AND a value with 0000  1111 then the relust will be 30 less than the original value

AL   =   0011 0011   =33
Msk =   0000 1111
------------------------------
             0000 1111   =3

so the code will be

AND AL, 0Fh

No comments:

Post a Comment

- - Important Notice - -





Programming google group is up. If you want to join request personally to any of the managers!




Education Blogs - BlogCatalog Blog Directory

Message from DIUCSP




This blog is open for all students of CS, CSE, CIS of Daffodil International University.


Join This blog to stay on touch with other students. If you have a gmail account then just sign in as the g-mail user and become a follower of the blog. You can then submit comments on our posts.

You will find information on different subjects of our course, discuss problems and have solution. Try to maintain the subjectwise discussion for early response. And remember this blog is not only for the genius or more than average CS, CSE, CIS students with great computer skills so dont feel shy in submitting your simple daily life problems (even the silliest ones) because I believe if you feel shy in learning now then you will feel shy all your life for not learning it at all.


Please be conscious about sharing your personal Data, DaffodilCSE blog moderator is not responsible for any risk you take, If you feel safe post comment as your own will, If you do not want to share your mail, comment anonymously. Thanks




They are with us

BlogCatalog

Earn from a cool looking gadget..! It works with Google adsense and any other advertising programs!
Grab now !