Assembly Language/decimal to binary

Advertisement


Question
hi daru, i know this is slightly out of your category field but if you could possibly remember back to when you did binary i would be very grateful for a little help.

just a little confused about representing a positive decimal and the same negative decimal in signed magnitude, one's compliment and twos complement.

the integers are 123 and -123

my representation in 8-bit form

signed magnitude

123 - 01111011
-123 - 11111011

ones compliment

123 - 10000100
-123 - 00000100 (or should i stll keep the leftmost bit here negative? )

twos compliment

123 - 10000101
-123 - 00000101 ( and same here should this still represent a negative)

i would be very gratefull if you could help, i have exam on monday and just am not too sure about this.

hope you can help, Pete  

Answer
I hope I am not too late with the answer...

Here's the simpliest rule.

Take a positive number, 123 = 01111011b. To get the corresponding negative value (-123), you have to:
1) NOT the byte. You'll get 10000100b.
2) Add 1. You'll get the correct value: 10000101b.

So,

NEG al
is the same as
NOT al
INC al
(but the flags may be different as a result - here I'm not sure).

Assembly Language

All Answers


Ask Experts

Volunteer


daru

Expertise

Pascal inline assembler; pure assembler programs for DOS; interrupt handling; TSR building; debugging and reverse engineering.

Experience

About 5 years of programming and reverse engineering.

©2012 About.com, a part of The New York Times Company. All rights reserved.