Altera Nios II User Manual page 187

Hide thumbs Also See for Nios II:
Table of Contents

Advertisement

Chapter 8: Instruction Set Reference
Instruction Set Reference
add
Operation:
Assembler Syntax:
Example:
Description:
Usage:
Exceptions:
Instruction Type:
Instruction Fields:
31
30
29
28
27
26
25
A
February 2014 Altera Corporation
rC ← rA + rB
add rC, rA, rB
add r6, r7, r8
Calculates the sum of rA and rB. Stores the result in rC. Used for both signed and unsigned
addition.
Carry Detection (unsigned operands):
Following an add operation, a carry out of the MSB can be detected by checking whether the
unsigned sum is less than one of the unsigned operands. The carry bit can be written to a
register, or a conditional branch can be taken based on the carry condition. The following code
shows both cases:
add rC, rA, rB
cmpltu rD, rC, rA
add rC, rA, rB
bltu rC, rA, label
Overflow Detection (signed operands):
An overflow is detected when two positives are added and the sum is negative, or when two
negatives are added and the sum is positive. The overflow condition can control a conditional
branch, as shown in the following code:
add rC, rA, rB
xor rD, rC, rA
xor rE, rC, rB
and rD, rD, rE
blt rD, r0,label
None
R
A = Register index of operand rA
B = Register index of operand rB
C = Register index of operand rC
24
23
22
21
20
19
18
17
B
C
# The original add operation
# rD is written with the carry bit
# The original add operation
# Branch if carry generated
# The original add operation
# Compare signs of sum and rA
# Compare signs of sum and rB
# Combine comparisons
# Branch if overflow occurred
16
15
14
13
12
11
10
9
0x31
8
7
6
5
4
3
2
1
0
0x3a
Nios II Processor Reference Handbook
8–7
add
0

Advertisement

Table of Contents
loading

Table of Contents