Assembly Language - Negative Numbers
So in the previous post we saw different numbering systems. Now in this blog post I am going to explain the Negative Numbers.
Ever wonder how computer represent negative numbers and how they store the data into the memory then don't worry your friendly neighborhood binaryhakka is going to explain it to you in a simple way...
Negative Numbers :-
But first we have to go from some basics like binary addition and subtraction the below diagram shows how it is done.
Secondly we need to understand two concepts known as 1's Complement and 2's Complement.
1's Complement :-
1's Complement is pretty easy to understand all you need to do is change the 1 with 0 and 0 with 1 huh neat na...
2's Complement :-
2's Complement is obtained using adding one to result of 1's Complement.
I hope you have understand the logic of 1's and 2's Complement. Now I am going to explain how negative numbers are represent and stored in the computer...
The logic is also pretty straight forward the negative numbers are represented using the 2's Complement method how?? lets understand with the below example
Also the bash (Bourne-Again Shell) also uses the 2's Complement method...
Now at last see one practical example and end this post....
1. I have created one C program to give you better understand of negative numbers. Also INT is Signed by default.
2. I know you guys aren't familiar with assembly yet but still I tried my best to only highlighting needed output for you... As you can see in the disassembly of main 0xfffffffd is moved into some memory location and that is our negative 3.
3. If you guys are thinking how I knew that this was -3.
4. This is it...
I hope you guys have understood the concept behind the negative numbers if not then feel free to message me i have given my twitter id in the right corner you can check.
Now that's it for this post see you guys in then next one till then keep smiling .... :)
Assembly Language - Negative Numbers
Reviewed by h4kk4
on
March 19, 2020
Rating:
No comments:
Enter your comments here if you need any help: