Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Hollywood MAL AMIStore App Store A600 Memory

AuthorTopic: Assembler question2  (Read 1190 times)

0 Members and 1 Guest are viewing this topic.

Offline Jose

Assembler question2
« on: April 04, 2003, 09:11:13 PM »
About the V and C bits of the status register:

V —Set if an overflow occurs; cleared otherwise.
C — Set if a borrow occurs; cleared otherwise.

Now, from what I've read, and I'm not dedicating much time to it, that's why I prefer to ask you guys here  :-D  the V bit is set when a change of signal occurs, but I don't know much about the Carry bit. Can someone explain what is a borrow? And an overflow by the way, just to confirm.

I guess one can use instructions without knowing this but I'd like to know it8-)

Thanks
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline N7VQM

Re: Assembler question2
« Reply #1 on: April 05, 2003, 12:42:06 AM »
Are you asking about m68k?
\\"...an error of 1 is much less significant in counting the population of the Earth than in counting the occupants of a phone booth.\\" - Michael T. Heath, Scientific Computing...
 

Offline Jose

Re: Assembler question2
« Reply #2 on: April 05, 2003, 12:51:54 AM »
Hi. Yes, it's 68k. I guess I must stop being a lazy ass and try to find it, but the problem is, I hardly  give off the time I have to rest and be with friends to do that, so I just read some stuff once in a while. Like this it would be faster.
I'm sure there's someone who knows :-o
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Hardboy

Re: Assembler question2
« Reply #3 on: April 05, 2003, 04:15:21 AM »
Overflow bit is set when a signed operationen results in wrong sign. Also happens when result can be contained in destination register on mult,div.

Carry is set when adding through 0.
 

Offline Jose

Re: Assembler question2
« Reply #4 on: April 05, 2003, 06:51:58 PM »
Hey.
I know what's a signed byte word etc. (to have negative numbers), but what's a signed operation?

"Carry is when addign through 0"
Maybe my english is rusted. What does that mean?

What about some examples with numbers for both cases?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline N7VQM

Re: Assembler question2
« Reply #5 on: April 05, 2003, 07:26:42 PM »
Quote

Jose wrote:
"Carry is when addign through 0"


I'll stick to 8-bit numbers for this example of the the carry flag.

Let's say you have the number 255 (1111 1111) stored in R0 and you want to add 1 to it.  Where that 255 came from isn't important.

255+1=256
or, in binary
1111 1111 + 0000 0001 = 1 0000 0000

The result is a 9 bit answer.  That first binary 1 after the equal sign is a carry from the addition.  Our hypothetical 8-bit micro knows that you just added two numbers together that results in a number that needs more than 8 bits to represent.  So, to indicated that fact, the carry flag is set.

On some micros, the carry flag can be set by rotate/shift operations.  For example,  lets say 1001 1001 is stored in R0 and you're about to execute a left shift on it.

1.  R0 = 1001 1001  C=0
2.  R0 = 0011 0010  C=1  (The left shift just happened)

The leading 1 that was in R0 got shifted into the carry flag.  Bear in mind this example may not be true on all micros.  You'll have to check the micro documentation to be sure.

As far as the V flag, I don't know.  I'm a wimp.  If I need signed math, I use C.  My guess is that the V flag get set if you perform an addition that causes your number to exeed 0111 1111.
\\"...an error of 1 is much less significant in counting the population of the Earth than in counting the occupants of a phone booth.\\" - Michael T. Heath, Scientific Computing...
 

Offline Jose

Re: Assembler question2
« Reply #6 on: April 05, 2003, 08:20:35 PM »
Hmm, ok it helped. I have this tutorial and I  just stumbled across a whole set of instructions that use the V flag, so I  guess I'll have to check it out.

Cheers
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Karlos

Re: Assembler question2
« Reply #7 on: April 05, 2003, 08:46:11 PM »
Argh - I just posted and got kicked out before the page refreshed.

I hate it when that happens!!!

Anyway

Quote

N7VQM wrote:
I'm a wimp.  If I need signed math, I use C.  My guess is that the V flag get set if you perform an addition that causes your number to exeed 0111 1111.


Due to the nature of signed 2's complement arithmetic, it doesn't matter. The operation performed is the same for signed and unsigned numbers. Hence the m68k doesn't need to differentiate between the two for addition/subtraction.

Allow me to demonstrate, again using bytes.

unsigned byte : 200 + 20 = 220
signed byte : -56 + 20 = -36

The point is, the bitwise representation of signed byte -56 and unsigned byte 200 are the same, as are signed -36 and 220. The binary representation of 20 is the same in both cases.

This is why there aren't any adds /addu / subs / subu on 68k. Obviously, multiplication and division are different because sign matters (negative x negative = pos etc), so we do have seperate signed and unsigned operations for this.

Hope this helps a bit.

-edit-

Asm not my strong point so don't ask me to explain any further :-D
int p; // A
 

Offline PiR

Re: Assembler question2
« Reply #8 on: April 07, 2003, 03:49:51 PM »
Hi Jose

Are you still interested in these flags?
Karlos gave you pretty good explanation, but ended just before the last, final word.
So, as said above, all numbers are really HEX values. The meaning of values actually depends only on the interpretation.
$FF can mean:
255 - unsigned char
-1 - signed char

After borring analysis you can find that:
adding and substracting is done exactly the same for signed and unsigned versions.
multiply and division are diffenet for signed and unsinged, so they have different commands.

So you have the same instruction for add (and substract). But when the counter overflows?

If you meant signed interpretation - check V flag
If you meant unsigned interpretation - check C flag

It is really that easy! Isn't it wonderfull on 68k? Adding and substracting is so easy that during signle operation 68k interprets value both as signed and unsigned and adjucts both flags for signed and unsigned interpretation, just in case it is needed.

If you're interested in 68k programming, want to know when these flags are updated, when not touched check this out:
Motorola 68k Programmers Guide
(Warning: 2338 kB)

Good luck

PS: Hi Karlos. I've finally signed up. Yes, thats me.  :-)
 

Offline Karlos

Re: Assembler question2
« Reply #9 on: April 07, 2003, 04:04:25 PM »
Hi PiR,

Nice to see you joined the fun :-D
int p; // A
 

Offline Jose

Re: Assembler question2
« Reply #10 on: April 07, 2003, 06:40:35 PM »
Ok, thanks all for the time. I'm slowly learning assembler. Maybe one could join efforts in the future, but I still have stuff to learn... :-)
\\"We made Amiga, they {bleep}ed it up\\"