Hopefully simple math question
Hopefully simple math question
I am having trouble understanding how certain subtractions are represented.
If I have a value like 50 decimal in an accumulator and I subtract 50 from it I have 0 which is obviously 00000000 binary. If instead I subtract 51 from 50 I get -1 which is 11111111 where Bit 7 is the negative sign. I understand that the largest 8 bit negative result is therefore -128 or 10000000.
What I cannot figure out is how larger subtractions are handled like what happens if I do 1-130? Does it just keep going with the value appearing to be a positive value but the carry is set? I think this would be 01111111 with carry set, which without the carry would be +127.
Am I doing this right?
If I have a value like 50 decimal in an accumulator and I subtract 50 from it I have 0 which is obviously 00000000 binary. If instead I subtract 51 from 50 I get -1 which is 11111111 where Bit 7 is the negative sign. I understand that the largest 8 bit negative result is therefore -128 or 10000000.
What I cannot figure out is how larger subtractions are handled like what happens if I do 1-130? Does it just keep going with the value appearing to be a positive value but the carry is set? I think this would be 01111111 with carry set, which without the carry would be +127.
Am I doing this right?
Moderator
iTrader: (1)
Joined: Mar 2002
Posts: 18,432
Likes: 233
From: Chasing Electrons
Car: check
Engine: check
Transmission: check
Re: Hopefully simple math question
Originally posted by BJM
I am having trouble understanding how certain subtractions are represented.
If I have a value like 50 decimal in an accumulator and I subtract 50 from it I have 0 which is obviously 00000000 binary. If instead I subtract 51 from 50 I get -1 which is 11111111 where Bit 7 is the negative sign. I understand that the largest 8 bit negative result is therefore -128 or 10000000.
What I cannot figure out is how larger subtractions are handled like what happens if I do 1-130? Does it just keep going with the value appearing to be a positive value but the carry is set? I think this would be 01111111 with carry set, which without the carry would be +127.
Am I doing this right?
I am having trouble understanding how certain subtractions are represented.
If I have a value like 50 decimal in an accumulator and I subtract 50 from it I have 0 which is obviously 00000000 binary. If instead I subtract 51 from 50 I get -1 which is 11111111 where Bit 7 is the negative sign. I understand that the largest 8 bit negative result is therefore -128 or 10000000.
What I cannot figure out is how larger subtractions are handled like what happens if I do 1-130? Does it just keep going with the value appearing to be a positive value but the carry is set? I think this would be 01111111 with carry set, which without the carry would be +127.
Am I doing this right?
I did find a piece of GM code that did a subtract in a different way. Instead of subtracting 14 from a register, they added 242 to it. Then let the result at that.
Here is another piece of code that may help:
Code:
LDD #1 ; load A = 0, B = 1 SUBB #131 ; sub 131 from B, underflow it SBCA #$00 ; handle the underflow into reg A
At this point the sign bit on A needs to be checked as to whether the double reg D (A&B) is positive or negative.
RBob.
Thanks for the reply.
I just thought of something else and a little different than you example using Acc D.
If, after I did the 1-130 and wound up with -129 and the carry is set, I then add some amount to make it fall within the -128 limit will this give the correct answer? Let's say I add 2, I should now be at -127, $81, 10000001. Does this work directly or do I have to do something special with the carry?
I just thought of something else and a little different than you example using Acc D.
If, after I did the 1-130 and wound up with -129 and the carry is set, I then add some amount to make it fall within the -128 limit will this give the correct answer? Let's say I add 2, I should now be at -127, $81, 10000001. Does this work directly or do I have to do something special with the carry?
Moderator
iTrader: (1)
Joined: Mar 2002
Posts: 18,432
Likes: 233
From: Chasing Electrons
Car: check
Engine: check
Transmission: check
Originally posted by BJM
Thanks for the reply.
I just thought of something else and a little different than you example using Acc D.
If, after I did the 1-130 and wound up with -129 and the carry is set, I then add some amount to make it fall within the -128 limit will this give the correct answer? Let's say I add 2, I should now be at -127, $81, 10000001. Does this work directly or do I have to do something special with the carry?
Thanks for the reply.
I just thought of something else and a little different than you example using Acc D.
If, after I did the 1-130 and wound up with -129 and the carry is set, I then add some amount to make it fall within the -128 limit will this give the correct answer? Let's say I add 2, I should now be at -127, $81, 10000001. Does this work directly or do I have to do something special with the carry?
RBob.
Thread
Thread Starter
Forum
Replies
Last Post




