[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: To the HC11 Number Gurus



Andrew Wakeling wrote:
> 
> ANYHOW, getting right back to my query, I was rather stumped on how the
> HC11 differ positive numbers which are 8 bits, and negative numbers
> which are also 8-bit?

It can't tell the difference and it doesn't care.  When using two's
complement encoding for negative values, the CPU can add and subtract
without knowing if the values are large unsigned numbers of signed
negative numbers.

> I do realise that there is a negative flag, or N
> flag, and the Ref Manual just says that it is basically doing the same
> thing as the MSB. It even goes on to say that the negative flag can be
> used to monitor bit 7. Does this flag however only get used when the
> number is negative?

In most cases, whenever a data value moves through the CPU, the MSB is
copied into the N flag.  The CPU doesn't know if it is a sign bit or
not, it just copies the value.  It is up to the software to know what to
do with the value in the N flag.

> Is there some way to differentiate the difference
> (hehe) between a positive or negative number in the HC11, or does it
> rely on plain coding?

It is up to the programmer to specify the correct branch instructions. 
If the values were unsigned, then the programmer can use BLO, BLS, BEQ,
BNE, BHS, and BHI.  If signed, then BLT, BLE, BEQ, BNE, BGE, and BGT are used.

> In other words, does the HC11 know that a number is negative and when
> you add it to a positive number it does the add it up properly?
> e.g.
>                 8000 + ( - A ) = 7FF6
> 
> or does it turn out to be:
> 
>                 8000 + (+ F6 ) = 80F6

Depends on the software.  The example might turn out to be:

                  8000 + (+ FFF6 ) = 7FF6

-- 
Ludis Langens                               ludis (at) cruzers (dot) com
Mac, Fiero, & engine controller goodies:  http://www.cruzers.com/~ludis/

----------------------------------------------------------------------------
To unsubscribe from gmecm, send "unsubscribe gmecm" (without the quotes)
in the body of a message (not the subject) to majordomo@lists.diy-efi.org