Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

subbtraction operation

Status
Not open for further replies.

bleach

New Member
can some one please explain me the subbtraction operation in µC 8051
for example;
mov a,#40h
subb a,#31h
the result which will be set in the accumelator is 0Eh(how:mad:)

thanks
 
You can't take 1 from 0, zero is less than one so you borrow a 1 from the sixteens place. So 0x10 - 0x01 = 0x0F. Now you take 0x3 from 0x3 in the sixteens place to get 0x0, and the answer is 0x0F, but remembering the 'b' on the end of subb, which stands for borrow and is the complement of the carry the 0x0F - (borrow==1) = 0x0E

Clear? I guess that might be a bit hard to follow if you've never done hexadecimal arithmetic. Think about it for a really long time and it will come to you. While you're at it try these references so we don't end up rewriting the whole damn reference manual.

https://www.electro-tech-online.com/custompdfs/2009/01/doc0509.pdf
https://www.electro-tech-online.com/custompdfs/2009/01/doc4316.pdf
 
The borrow

In fact the concept of "borrowing" is valid not only for hexadecimal but for any base system you use. Sorry, but you did it at school.

If you cannot grasp the idea think of what you will do when substracting 51 from 60, being both decimal quantities.

Have you ever considered that the same happens when you have 30$ en three 10$ notes and you change 10$ in small notes to pay 18$?

Try, in your mind now: 30 - 18.

For some people, this analogy (changing a big note in smaller ones) works fine.

Once you get used you will not need to ask again. Buena suerte.
 
You can't take 1 from 0, zero is less than one so you borrow a 1 from the sixteens place. So 0x10 - 0x01 = 0x0F. Now you take 0x3 from 0x3 in the sixteens place to get 0x0, and the answer is 0x0F, but remembering the 'b' on the end of subb, which stands for borrow and is the complement of the carry the 0x0F - (borrow==1) = 0x0E

Clear? I guess that might be a bit hard to follow if you've never done hexadecimal arithmetic. Think about it for a really long time and it will come to you. While you're at it try these references so we don't end up rewriting the whole damn reference manual.

https://www.electro-tech-online.com/custompdfs/2009/01/doc0509-1.pdf
https://www.electro-tech-online.com/custompdfs/2009/01/doc4316-1.pdf

normally what i do is take one from 4 so it will be 10 and 4 will be replaced to 3, then the result will be 09, but here its done with a different way, am still not getting the idea ;
a 1 from the sixteens place. So 0x10 - 0x01 = 0x0F
am not getting this one
take 0x3 from 0x3 in the sixteens place to get 0x0, and the answer is 0x0F
from where 03
but remembering the 'b' on the end of subb, which stands for borrow and is the complement of the carry the 0x0F - (borrow==1) = 0x0E
common

by the way i have done hexadecimal with barrow for example;
f6H - A8H= 4E by borrow 1 from f it become E and 6 become 16 (this 16 in hexadecimal if i convert it to decimal it will be 22 - 8 = 14(by retaining it back to hexa it will be E). and i will have now E - A = 14 - 10 = 4.......
 
In fact the concept of "borrowing" is valid not only for hexadecimal but for any base system you use. Sorry, but you did it at school.
thanks man but i don't remember

If you cannot grasp the idea think of what you will do when substracting 51 from 60, being both decimal quantities.
it will be -9 by logic
Have you ever considered that the same happens when you have 30$ en three 10$ notes and you change 10$ in small notes to pay 18$?
i am not getting this one
Try, in your mind now: 30 - 18.
12 by mind
For some people, this analogy (changing a big note in smaller ones) works fine.

Once you get used you will not need to ask again. Buena suerte.
thanks
 
Anyone who intends to work with digital electronics needs to work in hex and binary as fast as others work in decimal.

You need to convert hex to bin and bin to hex without thinkng. 1101 1011 is 0xDB and 0xDB is 1101 1011.
If you have to think about it you do not know it well enough. This will save time, every time, you work on a project and prevent costly errors.

You need to do bitwise 1's and 2's complment in you sleep.

3v0
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top