Re: LZ: JR/opcode $18


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

Re: LZ: JR/opcode $18



On Mon, 5 Aug 1996, Joshua Lynch wrote:


> 
>         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?"


You can think of two's compliment as a binary version of your car's
odometer.  If your odometer is at 0 and you go backwards 1 mile, it's
now at 99999.  That's -1 in 10's compliment.  If you have 0 in a byte
then it's $00 in hex and if you subtract 1 it becomes $FF.  That's -1
in 2's compliment.   $FE is -2.  That's really all there is to it.


But in a JR  you have to start your calculation from the next instruction,
not the current one.  That's because the JR is really an add or subtract to
the PC and the PC is pointing at the next instruction.  That means you have
to know the length of the current instruction so you can calculate the
address of the next instruction.  In this case, the length of the current
instruction is 2 so that's easy.


Barry


References: