Processing Data

R

ADD16:

NAMEREG s0, a_lsb ; rename register s0 as “a_lsb”

NAMEREG s1, a_msb ; rename register s1 as “a_msb”

NAMEREG s2, b_lsb ; rename register s2 as “b_lsb”

NAMEREG s3, b_msb ; rename register s3 as “b_lsb”

ADD a_lsb, b_lsb ; add LSBs, keep result in a_lsb

ADDCY a_msb, b_msb ; add MSBs, keep result in a_msb

RETURN

Figure 3-8:16-Bit Addition Using ADD and ADDCY Instructions

See also:

“ADD sX, Operand —Add Operand to Register sX,” page 91

“ADDCY sX, Operand —Add Operand to Register sX with Carry,” page 92

SUB and SUBCY Subtract Instructions

The PicoBlaze microcontroller provides two subtract instructions, SUB and SUBCY, that compute the difference of two 8-bit operands, either without or with CARRY (borrow), respectively. The CARRY flag indicates if the subtract operation generates a borrow condition. The first operand is a register location. The second operand is either a register location or a literal constant. The resulting operation affects both the CARRY and ZERO flags. If the resulting difference is less than 0, then the CARRY flag is set. If the resulting difference is 0 or -256, then the ZERO flag is set.

The SUBCY instruction is a subtract operation with borrow. If the CARRY flag is set, then SUBCY subtracts an additional one from the resulting difference.

The SUBCY instruction is commonly used in multi-byte subtraction. Figure 3-9demonstrates a subroutine that subtracts two 16-bit integers and produces a 16-bit difference. The upper byte of each 16-bit value is labeled as MSB for most-significant byte; the lower byte of each 16-bit value is labeled LSB for least-significant byte.

SUB16:

NAMEREG s0, a_lsb ; rename register s0 as “a_lsb”

NAMEREG s1, a_msb ; rename register s1 as “a_msb”

NAMEREG s2, b_lsb ; rename register s2 as “b_lsb”

NAMEREG s3, b_msb ; rename register s3 as “b_lsb”

SUB a_lsb, b_lsb

;

subtract

LSBs,

keep

result

in

a_lsb

SUBCY a_msb, b_msb

;

subtract

MSBs,

keep

result

in

a_msb

RETURN

 

 

 

 

 

 

 

Figure 3-9:16-Bit Subtraction Using SUB and SUBCY Instructions

See also:

“SUB sX, Operand —Subtract Operand from Register sX,” page 113

“SUBCY sX, Operand —Subtract Operand from Register sX with Borrow,” page 114

Increment/Decrement

The PicoBlaze microcontroller does not have a dedicated increment or decrement instruction. However, adding or subtracting one using the ADD or SUB instructions provides the equivalent operation, as shown in Figure 3-10.

PicoBlaze 8-bit Embedded Microcontroller

www.xilinx.com

27

UG129 (v1.1.2) June 24, 2008

Page 27
Image 27
Xilinx UG129 manual SUB and Subcy Subtract Instructions