Re: Could you please help me - branch command




<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



.



Relevant Pages

  • Re: Problem using Ada.Text_IO.Modular_IO
    ... build-in CPU Carry flag to detect a Overflow/Underflow condition for those types that are define in the Standard/System packages. ... Assuming you get an advantage from using hardware overflow ... What routines does the compiler generate for mod 2**5? ...
    (comp.lang.ada)
  • Re: Kann Java nicht mit Byte-Zahlen rechnen?
    ... Ingo Menger wrote: ... ich auch nicht wie das bei modernen Prozessoren ist, aber mein 68000er Handbook von Gerry Kane, sagt mir dass der Prozessor schon vor 26 Jahren die Ergebnisse von Lade- und Rechen-Operationen mit *vier* Statusflags bewertet hat: ... Bit#0 CF Carry Flag ... Bit#11 OF Overflow Flag ...
    (de.comp.lang.java)
  • Re: Math in asm... and limits...
    ... If Nasm had a fan club, ... If you want the result in C, "mov C, ax". ... the carry flag is set. ... really an overflow, but if you want a 16-bit result it is. ...
    (alt.lang.asm)
  • Re: C desktop programmer needs advice on how to code embedded C on a micro controller.
    ... So what do you do if there is an overflow? ... that" flag might not be of any use. ... missed the next 10 or so interrupts. ... int handlers short and using a properly structured control loop, ...
    (comp.arch.embedded)
  • Re: Using the carry flag in standard C
    ... The overflow flag is set if and only if the mathematical result of the operation cannot be represented in the target type. ... I wonder if we'd want a similar interface for floating-point. ... A question to the group in general: is this whole idea sufficiently useful to consider adding it to the standard? ...
    (comp.std.c)