Re: Could you please help me - branch command
- From: "Wolfgang Kern" <nowhere@xxxxxxxx>
- Date: Mon, 12 Mar 2007 07:23:44 +0100
<kaja_love160@xxxxxxxxx> send us:
greetings
Salve!
I would really need some help cos I'm stuck.
I've quit highschool few years ago and now I decided to finish it. So
I'm learning stuff by myself at home and then go and take exams.
Even though the purpose of a text book I'm using is not to teach us
how to write anything more advanced than the most basic programs, book
is still useless. It only explains each command very briefly and
that's it. No examples, nada...
The following questions are all related to Motorola 6803.
When I talk about C ( carry ), V ( overflow ), Z (Zero) and N
( negative ) flags, I'm reffering to the flags in CCR register.
1) I think this may be the most important question:
Flag V in CCR register indicates whether the result of an operation
has overflowed according to the two's complement representation.
Meaning if the result is bigger than 127 or smaller than -128, then V
flag will be set to V=1.
So why is V flag set to 1 ( V=1 ) when I do : -10 - (- 5) = - 5 ?
Afterall, result (-5) is not bigger than 127 or smaller than -128!
NOTE - > ( -10 ) is represented as 246 ( 1111 0110 ) and (-5) is
represented as 251
IIRC, Motorola's V-flag works the same way as x86 O-flag,
that means any transition from MSB-1 to MSB will set V.
So if the result is signed () the V-flag indicates that this sign
is wrong. If interpreted as unsigned then the V-flag can be ignored.
If we go by the definition of flag V: " Flag V in CCR register
indicates whether the result of an operation has overflowed according
to the two's complement representation ", then no overflow should
occur and thus V flag should be zero.
Yes.
2) This questions is about command BGE.
BGE 40 -->PC gets increased 42 by if N != V.
But if N==V then PC gets increased by 2.
- So if signed number overflows and if this number is also positive,
then PC will be increased by 40.
- But if number doesn't overflow ( V = 0 ) and if number is positive
( N = 0 ) OR if number overflows ( N = 1 ) and if number is also
negative ( N = 1 ) then PC gets increased by 2?!
I don't follow this logic.
This is due the BGE (and all other short Jcc) are two bytes long,
and the branch offset is relative to the current IP(PC).
So if V the new IP (PC in your book) points right after the branch,
while NV then IP becomes 40+2,... of course!
Can you show me an example(s) of condition we must include into "if
( condition ) then.." statement using BGE 40 command:
a) What kind of IF (CONDITION) THEN .. statement would be TRUE and
would fulfill the following criteria:
* signed number overflows ( V = 1 ) and is also positive ( N = 0 )
b) Can you show me an example of IF (CONDITION) THEN conditional
statement, that would be FALSE and would fulfill the following
criteria:
* number doesn't overflow ( V = 0 ) and number is positive ( N = 0 )
OR
* number overflows( V = 1 ) and number is also negative ( N = 1 )
I just can't figure out "why N flag must not be equal to V flag"
relation.
thank you
V=0 N=0 ignore it
V=1 N=0 ignore it
V=0 N=1 ignore it
V=1 N=1 the N-bit is wrong due result couln't fit
__
wolfgang
.
- References:
- Could you please help me - branch command
- From: kaja_love160
- Could you please help me - branch command
- Prev by Date: Re: Could you please help me - branch command
- Next by Date: Re: Ten years later
- Previous by thread: Re: Could you please help me - branch command
- Next by thread: Re: Could you please help me - branch command
- Index(es):
Relevant Pages
|