Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2009, 04:04 PM
tombaugh tombaugh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 tombaugh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old October 16th, 2009, 04:14 PM
E-Oreo's Avatar
E-Oreo E-Oreo is online now
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,939 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
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.

Reply With Quote
  #3  
Old October 16th, 2009, 04:30 PM
tombaugh tombaugh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 tombaugh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old October 16th, 2009, 04:52 PM
tombaugh tombaugh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 tombaugh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 55 sec
Reputation Power: 0
Ok, it's clear to me now. Thank you!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > [Assembly] signed math

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap