Processing Data

R

Complement/Invert Register

The PicoBlaze microcontroller does not have a specific instruction to invert individual bits within register sX. However, the XOR sX,FF instruction performs the equivalent operation, as shown in Figure 3-2.

T

If reading this document in Adobe Acrobat,

 

use the Select Text tool to select code snippets,

 

then copy and paste the text into your text editor.

complement:

;XOR sX, FF invert all bits in register sX, same as one’s complement

LOAD s0,

AA

;

load register

s0

=

10101010

XOR s0,

FF

;

invert contents

s0

=

01010101

Figure 3-2:Complementing a Register Value

Invert or Toggle Bit

The PicoBlaze microcontroller does not have a specific instruction to invert or toggle an individual bit or bits within a specific register. However, the XOR instruction performs the equivalent operation. XORing register sX with a bit mask inverts or toggles specific bits, as shown in Figure 3-3. A ‘1’ in the bit mask inverts or toggles the corresponding bit in register sX. A ‘0’ in the bit mask leaves the corresponding bit unchanged.

toggle_bit:

;XOR sX, <bit_mask>

XOR s0, 01 ; toggle the least-significant bit in register sX

Figure 3-3:Inverting an Individual Bit Location

Clear Register

The PicoBlaze microcontroller does not have a specific instruction to clear a specific register. However, the XOR sX,sX instruction performs the equivalent operation. XORing register sX with itself clears registers sX and sets the ZERO flag, as shown in Figure 3-4.

XOR sX, sX ; clear register sX, set ZERO flag

Figure 3-4:Clearing a Register and Setting the ZERO Flag

The LOAD sX,00 instruction also clears register sX, but it does not affect the ZERO flag, as shown in Figure 3-5.

LOAD sX,00 ; clear register sX, ZERO flag unaffected

Figure 3-5:Clearing a Register without Modifying the ZERO Flag

Set Bit

The PicoBlaze microcontroller does not have a specific instruction to set an individual bit or bits within a specific register. However, the OR instruction performs the equivalent

PicoBlaze 8-bit Embedded Microcontroller

www.xilinx.com

25

UG129 (v1.1.2) June 24, 2008

Page 25
Image 25
Xilinx UG129 manual 2Complementing a Register Value, 3Inverting an Individual Bit Location