Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
October 16th, 2009, 04:04 PM
 tombaugh
Registered User

Join Date: Oct 2009
Posts: 3
Time spent in forums: 20 m 55 sec
Reputation Power: 0
[Assembly] signed math

Hi,

I'm taking my first steps in assembly and I'm a bit confused over signed versus unsigned math. I'm debugging a simple executable which at one point does a subtraction.

Before the operation, this is what AX and BX look like:

AX CF8F
BX 2300

After "sub ax, bx" the sign flag is set and AX becomes

AX AC8F

When thinking in unsigned numbers I understand what is happening.

53135 - 8960 = 44175

However, when I'm trying to understand what happens in terms of signed numbers, I'm a bit confused.

AX CF8F = 1100 1111 1000 1111 = -100 1111 1000 1111 = -20367
BX 2300 = 0010 0011 0000 0000 = +010 0011 0000 0000 = 8960

-20367 - 8960 = -29327 = -111 0010 1000 1111 = 1111 0010 1000 1111 = F28F

So obviously there is something wrong with my reasoning. Who can help me out?

Thanks

#2
October 16th, 2009, 04:14 PM
 E-Oreo
Lost in code

Join Date: Dec 2004
Posts: 7,939
Time spent in forums: 2 Months 9 h 13 m 20 sec
Reputation Power: 7053
Are AX and BX 16 or 32 bit registers?

Edit:
Also, are you sure the architecture uses sign magnitude instead of 2's complement? If it's 2's complement then
1100 1111 1000 1111 = - 011 0000 0111 0001 = -12,401

Last edited by E-Oreo : October 16th, 2009 at 04:20 PM.

#3
October 16th, 2009, 04:30 PM
 tombaugh
Registered User

Join Date: Oct 2009
Posts: 3
Time spent in forums: 20 m 55 sec
Reputation Power: 0
The registers are 16 bit. The architecture is x86, I'm using Windows XP on a virtual machine.

I'll look into 2's complement, I wasn't aware of this.

#4
October 16th, 2009, 04:52 PM
 tombaugh
Registered User

Join Date: Oct 2009
Posts: 3
Time spent in forums: 20 m 55 sec
Reputation Power: 0
Ok, it's clear to me now. Thank you!

 Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > [Assembly] signed math