Re: A86: Adding numbers


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

Re: A86: Adding numbers




This is a 16-bit number.  Wierd stuff happens to these.

The Z80 loads 16-bit numbers 'backwards', lowest byte first.  Thus, if
you load the value you have into hl, it would be $1027, not $2710.  You
can fix this two ways:

Probably the better way is to use .dw (define word) rather than .db
(define byte).  A word is a 16-bit number (2 bytes).  Example:

.dw $2710  -or-  .dw 10000

The other way is to intentionally store it backwards, bytewise, using
.db's.

.db $10,$27

When compiled, both methods produce the same output, which is $10 $27.

Cassady Roop

Brent Schneider wrote:
> 
> I have a question:
> I am making a program, and I have 10000 stored in money:
> money:
> .db $27,$10
> then, in my program, I want to add 10 to it. This is what I did:
> ld hl,(money)
> ld de,$A
> add hl,de
> ld (money),hl
> 
> But, it doesn't work. I've tried many things. Am I doing something wrong?
> Thanks!


References: