Bob’s Notebook: Jumping Backwards Relatively Speaking

See all articles from Sinc-Link v7 n3
Author(s): Bob Mitchell
Publication: Sinc-Link
Pub Details: Sinc-Link v7 n3 (Volume 7, Issue 3)
Date: May/June 1989
Pages: 21

==>BOB’S NOTEBOOK<==

JUMPING BACKWARDS RELATIVELY SPEAKING

The Z80 machine language instruction JR e means Jump Relative by e addresses. JR cc,e does the same thing but only if condition cc is met; cc may be any one of: NZ, NC, Z or C.

The relative jump may be forward or backward and in the latter case, the convention used is that any value greater than 7F hex (or 127 dec) will be taken to be a negative offset, ie, the normal decimal value of the hex code minus 256.

For example, the offset value -10 is F6 (246-256). An instruction JR F6 would cause the routine to jump backwards by ten addresses. Counting starts with the next address after the JR F6 line, deemed to be the zero datum point, be it forward or backward.

Normally an assembler will do all this for you automatically as you put in your mnemonics and labels but later you might want to study the disassembly and follow the jumps etc in any debugging process.

Here is a short program to generate a table of backward jumps with hex numbers from 80 to FF (-128 to -1 dec). Type in the program lines carefully watching the spacing in line 140 and the length of L$ in particular.

LISTING 1

100 PRINT
110 LET L$="=================================================================================":REM 81 ='s
120 PRINT TAB 9;"NEGATIVE SIGN CONVENTION FOR BACKWARD JUMPS (JR)"
130 PRINT L$
140 PRINT " 0 1 2 3 4 5 6 7 8 9 A B C D E F": REM 4 spaces between characters
150 PRINT L$
160 LET v$="89ABCDEF"
170 LET a=1
180 FOR i=128 TO 1 STEP -16
190 DIM n$(3)
200 PRINT v$(a);
210 FOR j=0 TO 15
220 LET n$=STR$ (i-j)
230 PRINT " -";n$;
240 NEXT j
250 LET a=a+1
260 PRINT
270 NEXT i
280 PRINT L$
290 RANDOMIZE USR 100: CLOSE #2
300 STOP
310 RANDOMIZE USR 100: SAVE "jrnegC.B1" LINE 320: STOP
320 RANDOMIZE USR 100: OPEN #2,"lp": RANDOMIZE USR 100: POKE 16094,8: RANDOMIZE USR 100: POKE 16090,81
330 OUT 127,15
340 GO TO 100

This program is designed to run with a dot-matrix printer in the condensed mode. It will also run in the Elite mode if you make the following changes:

330 GO SUB 350: OUT 127,27: GO SUB 350: OUT 127,77
340 GO TO 100
350 IF IN 127<>237 THEN GO TO 350
360 RETURN

Bob Mitchell 890408

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.