Re: Could you please help me - branch command
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Mon, 12 Mar 2007 09:24:45 +0100
kaja_love160@xxxxxxxxx wrote:
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
Maybe you mixed up the V and the C flag. The Carry flag is set if
an overflow is generated for unsigned numbers.
1111 0110 - 1111 1011 = 1111 1011 C=1 V=0 N=1 Z=0
-10 - -5 = -5 (signed)
246 - 251 = 251 (unsigned)
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.
The other way: GE means N==V
- 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.
Use 2 bit numbers instead of 8 bit numbers then you can write the
complete logic table:
a b b ge a b-a cvnz n==v
00 0 00 0 yes 00 0 0001 true
00 0 01 1 yes 01 1 0000 true
00 0 10 -2 no 10 -2 0010 false
00 0 11 -1 no 11 -1 0010 false
01 1 00 0 no 11 -1 1010 false
01 1 01 1 yes 00 0 0001 true
01 1 10 -2 no 01 1 0100 false
01 1 11 -1 no 10 -2 0010 false
10 -2 00 0 yes 10 -2 1110 true
10 -2 01 1 yes 11 -1 1110 true
10 -2 10 -2 yes 00 0 0001 true
10 -2 11 -1 yes 01 1 0000 true
11 -1 00 0 yes 01 1 1000 true
11 -1 01 1 yes 10 -2 1110 true
11 -1 10 -2 no 11 -1 1010 false
11 -1 11 -1 yes 00 0 0001 true
and for unsigned numbers you get:
a b b hs a b-a cvnz c==0
00 0 00 0 yes 00 0 0001 true
00 0 01 1 yes 01 1 0000 true
00 0 10 2 yes 10 2 0010 true
00 0 11 3 yes 11 3 0010 true
01 1 00 0 no 11 3 1010 false
01 1 01 1 yes 00 0 0001 true
01 1 10 2 yes 01 1 0100 true
01 1 11 3 yes 10 2 0010 true
10 2 00 0 no 10 2 1110 false
10 2 01 1 no 11 3 1110 false
10 2 10 2 yes 00 0 0001 true
10 2 11 3 yes 01 1 0000 true
11 3 00 0 no 01 1 1000 false
11 3 01 1 no 10 2 1110 false
11 3 10 2 no 11 3 1010 false
11 3 11 3 yes 00 0 0001 true
That means, for a "branch greater equal" the condition is n==v and
for a "branch higher same" the condition is c==0.
Can you show me an example(s) of condition we must include into "if
( condition ) then.." statement using BGE 40 command:
* signed number overflows ( V = 1 ) and is also positive ( N = 0 )
* number doesn't overflow ( V = 0 ) and number is positive ( N = 0 )
* number overflows( V = 1 ) and number is also negative ( N = 1 )
See table above.
.
- References:
- Could you please help me - branch command
- From: kaja_love160
- Could you please help me - branch command
- Prev by Date: Re: Ten years later
- 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
|