Re: LZ: JR/opcode $18
[Prev][Next][Index][Thread]
> okay, latley I've learned how to program in Hex using the Compiler
> program on my ti-85. learning to program in Hex is really convienent for
> small programs. I don't have to goto my comp all the time and assemble them.
> It also has me hung up on one instruction, JR. I know the opcode for JR is
> $18 and the next byte following it is how many bytes to jump foward or back.
> But what has me confused is the two's compliment (what does that mean?!) and
> in what format the next byte should be in (e.g. F8 = jump 8 bytes back in
> the stack and 02 = jump four bytes foward) but how do I decide what to put
> in there?(I know thats where to put the size of the jump!:))And in mnemonic
> terms jump 8 bytes back is JR $F6+2 (which obviously equals and jump back 8
> bytes, right?) I also know that $ equals "the current address". SO I think
> my question is "how do i use the $18 XX opcode" and "what should I put in
> XX?" AND "How do I two's compliment somthing?"
>
two's complement is a method of denoting positive and negative
numbers..
you can think of it kinda like a two digit counter ..
say you start with teh counter at
01
and then decrease it by 1.. it goes to
00
now if yo decrease that by one, it loops back to teh end.
i.e. to
FF
then it goes
FE,
FD,
etc...
so FF is -1, FE, -2, FD, -3, etc..
the z80 decides wheth it's positive ore negative by looking at teh
top bit, hence teh largest positive vale you can use is
$7f (127), and the smallest negative no. you can use is $80 (-128)
a way of calculating a negative value is as such:
write the absolute value of the number in binary
(i.e 65 = %01000001)
then invert all the bits
(i.e. %10111110)
then add 1
(i.e. %10111111)
writing this in hex, gives $bf
65 in hex is$41
and $bf+$41 = $100
and as teh z80 is only dealing with bytes, the 1 get's lost,
giving 00..
so you can see it works... if we add our negative 2's complement no. to
the origional value, we get 0, just how it should...
I hope that made soem sense....
Rob Taylor MAIL - mailto:rtaylor@rtaylor.u-net.com
WEB - http://www.u-net.com/~rtaylor/
References: