3 conditional jumps, 4 calling subroutines, 5 loop operations – Maxim Integrated MAXQ610 User Manual
Page 48: Maxq610 user’s guide

3-13
MAXQ610 User’s Guide
3.7.3 Conditional Jumps
Conditional jumps transfer program execution based on the value of one of the status flags (C, E, Z, S) . Except where
noted for JUMP E and JUMP NE, the absolute and relative operands allowed are the same as for the unconditional
JUMP command .
jump c, Label1
; jump to Label1 if Carry is set
jump nc, LongJump ; jump to LongJump if Carry is not set
jump z, LC[0]
; jump to 16-bit register destination if
; Zero is set
jump nz, Label1 ; jump to Label1 if Zero is not set (Acc<>0)
jump s, A[2]
; jump to A[2] if Sign flag is set
jump e, Label1
; jump to Label1 if Equal is set
jump ne, Label1 ; jump to Label1 if Equal is cleared
JUMP E and JUMP NE can only use immediate destinations .
3.7.4 Calling Subroutines
The CALL instruction works the same as the unconditional JUMP, except that the next execution address is pushed on
the stack before the jump is made . The RET instruction is used to return from a normal call, and RETI is used to return
from an interrupt handler routine .
call Label1
; if Label1 is relative,
; assembles to: call #immediate
call LongCall
; assembles to: move PFX[0], #high(LongCall)
; call #low(LongCall)
call LC[0]
; call to address in LC[0]
LongCall:
ret
; return from subroutine
3.7.5 Loop Operations
Looping over a section of code can, of course, be performed by using the conditional jump instructions . However,
there is built-in functionality in the form of the “DJNZ LC[n], src” instruction to support faster, more compact looping
code with separate loop counters . The 16-bit registers LC[0] and LC[1] are used to store these loop counts . The “DJNZ
LC[n], src” instruction automatically decrements the associated loop counter register and jumps to the loop address
specified by src if the loop counter has not reached 0 .
To initialize a loop, set the LC[n] register to the desired count before entering the loop’s main body .
The desired loop address should be supplied in the src operand of the “DJNZ LC[n], src” instruction . When the sup-
plied loop address is relative (+127/-128 words) to the DJNZ LC[n] instruction, as is typically the case, the assembler
automatically calculates the relative offset and inserts this immediate value in the object code .
move LC[1], #10h
; loop 16 times
LoopTop:
; loop addr relative to djnz LC[n],src
call LoopSub
djnz LC[1], LoopTop ; decrement LC[1] and jump if nonzero