R

Chapter 3: PicoBlaze Instruction Set

ADD sX,01 ; increment register sX

SUB sX,01 ; decrement register sX

Figure 3-10:Incrementing and Decrementing a Register

If incrementing or decrementing a multi-register value—i.e., a 16-bit value—perform the operation using multiple instructions. Incrementing or decrementing a multi-byte value requires using the add or subtract instructions with carry, as shown in Figure 3-11.

inc_16:

;increment low byte ADD lo_byte,01

;increment high byte only if CARRY bit set when incrementing low byte ADDCY hi_byte,00

Figure 3-11:Incrementing a 16-bit Value

Negate

The PicoBlaze microcontroller does not have a dedicated instruction to negate a register value, taking the two’s complement. However, the instructions in Figure 3-12provide the equivalent operation.

Negate:

;invert all bits in the register performing a one’s complement XOR sX,FF

;add one to sX

ADD sX,01

RETURN

Figure 3-12:Destructive Negate (2’s Complement) Function Overwrites Original

Value

Another possible implementation that does not overwrite the value appears in Figure 3-13.

Negate:

NAMEREG sY, value

NAMEREG sX, complement

;Clear ‘complement’ to zero LOAD complement, 00

;subtract value from 0 to create two’s complement SUB complement, value

RETURN

Figure 3-13:Non-destructive Negate Function Preserves Original Value

Multiplication

The PicoBlaze microcontroller core does not have a dedicated hardware multiplier. However, the PicoBlaze microcontroller performs multiplication using the available arithmetic and shift instructions. Figure 3-14demonstrates an 8-bit by 8-bit multiply routine that produces a 16-bit multiplier product in 50 to 57 instruction cycles, or 100 to 114 clock cycles. By contrast, the 8051 microcontroller performs the same multiplication in eight instruction cycles or 96 clock cycles on a the standard 12-cycle 8051.

28

www.xilinx.com

PicoBlaze 8-bit Embedded Microcontroller

 

 

UG129 (v1.1.2) June 24, 2008

Page 28
Image 28
Xilinx UG129 manual Multiplication, 10Incrementing and Decrementing a Register