beautypg.com

2 unconditional jumps, 3 conditional jumps, 4 calling subroutines – Maxim Integrated MAXQ Family User Manual

Page 37: 5 looping operations, 2 unconditional jumps -12, 3 conditional jumps -12, 4 calling subroutines -12, 5 looping operations -12, Maxq family user’s guide

background image

3-12

MAXQ Family User’s Guide

3.7.2 Unconditional Jumps

An unconditional jump can be relative (IP +127/-128 words) or absolute (to anywhere in program space). Relative jumps must use an

8-bit immediate operand, such as

Label1:

; must be within +127/-128 words of the JUMP

...

jump Label1

Absolute jumps can use a 16-bit immediate operand, a 16-bit register, or an 8-bit register.

jump LongJump

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

;

jump #low(LongJump)

jump DP[0]

; absolute jump to the address in DP[0]

If an 8-bit register is used as the jump destination, the prefix value is used as the high byte of the address and the register is used as

the low byte.

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.

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

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

Maxim Integrated