beautypg.com

3 conditional jumps -38, 4 calling subroutines -38, 5 looping operations -38 – Maxim Integrated MAXQ7666 User Manual

Page 40

background image

1.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 may only use immediate destinations.

1.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
transferring program execution to the branch address. 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

1.3.7.5 Looping Operations

Looping over a section of code can 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 reg-
isters LC[0], and LC[1] are used to store these loop counts. The ‘DJNZ LC[n], src’ instruction automatically decrements the associat-
ed 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 count you wish to use 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 supplied 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 instruction

call LoopSub

djnz LC[1], LoopTop

; decrement LC[1] and jump if nonzero

When the supplied loop address is outside the relative jump range, the prefix register (PFX[0]) is used to supply the high byte of the
loop address as required.

move LC[1], #10h

; loop 16 times

LoopTop:

; loop addr not relative to djnz LC[n],src

call LoopSub

...

djnz LC[1], LoopTop

; decrement LC[1] and jump if nonzero

; assembles to: move PFX[0], #high(LoopTop)

; djnz LC[1], #low(LoopTop)

MAXQ7665/MAXQ7666 User’s Guide

1-38

Maxim Integrated

This manual is related to the following products: