Specifications
Table Of Contents
- Nios II Processor Reference Handbook
- Contents
- Chapter Revision Dates
- About This Handbook
- Section I. Nios II Processor
- 1. Introduction
- 2. Processor Architecture
- 3. Programming Model
- Introduction
- General- Purpose Registers
- Control Registers
- Operating Modes
- Exception Processing
- Memory and Peripheral Access
- Instruction Set Categories
- Referenced Documents
- Document Revision History
- 4. Instantiating the Nios II Processor in SOPC Builder
- Section II. Appendices
- 5. Nios II Core Implementation Details
- Introduction
- Device Family Support
- Nios II/f Core
- Nios II/s Core
- Nios II/e Core
- Referenced Documents
- Document Revision History
- 6. Nios II Processor Revision History
- 7. Application Binary Interface
- 8. Instruction Set Reference
- Introduction
- Word Formats
- Instruction Opcodes
- Assembler Pseudo- instructions
- Assembler Macros
- Instruction Set Reference
- add
- addi
- and
- andhi
- andi
- beq
- bge
- bgeu
- bgt
- bgtu
- ble
- bleu
- blt
- bltu
- bne
- br
- break
- bret
- call
- callr
- cmpeq
- cmpeqi
- cmpge
- cmpgei
- cmpgeu
- cmpgeui
- cmpgt
- cmpgti
- cmpgtu
- cmpgtui
- cmple
- cmplei
- cmpleu
- cmpleui
- cmplt
- cmplti
- cmpltu
- cmpltui
- cmpne
- cmpnei
- custom
- div
- divu
- eret
- flushd
- flushda
- flushi
- flushp
- initd
- initi
- jmp
- jmpi
- ldb / ldbio
- ldbu / ldbuio
- ldh / ldhio
- ldhu / ldhuio
- ldw / ldwio
- mov
- movhi
- movi
- movia
- movui
- mul
- muli
- mulxss
- mulxsu
- mulxuu
- nextpc
- nop
- nor
- or
- orhi
- ori
- rdctl
- ret
- rol
- roli
- ror
- sll
- slli
- sra
- srai
- srl
- srli
- stb / stbio
- sth / sthio
- stw / stwio
- sub
- subi
- sync
- trap
- wrctl
- xor
- xorhi
- xori
- Referenced Documents
- Document Revision History

8–96 Altera Corporation
Nios II Processor Reference Handbook October 2007
sub
sub
subtract
Operation:
rC
←
rA – rB
Assembler Syntax:
sub rC, rA, rB
Example:
sub r6, r7, r8
Description: Subtract rB from rA and store the result in rC.
Usage: Carry Detection (unsigned operands):
The carry bit indicates an unsigned overflow. Before or after a
sub operation, a carry
out of the MSB can be detected by checking whether the first operand is less than
the second operand. The carry bit can be written to a register, or a conditional branch
can be taken based on the carry condition. Both cases are shown below.
sub rC, rA, rB
cmpltu rD, rA, rB
sub rC, rA, rB
bltu rA, rB, label
; The original sub operation (optional)
; rD is written with the carry bit
; The original sub operation (optional)
; Branch if carry was generated
Overflow Detection (signed operands):
Detect overflow of signed subtraction by comparing the sign of the difference that is
written to rC with the signs of the operands. If rA and rB have different signs, and the
sign of rC is different than the sign of rA, an overflow occurred. The overflow condition
can control a conditional branch, as shown below.
sub rC, rA, rB
xor rD, rA, rB
xor rE, rA, rC
and rD, rD, rE
blt rD, r0, label
; The original sub operation
; Compare signs of rA and rB
; Compare signs of rA and rC
; Combine comparisons
; Branch if overflow occurred
Instruction Type: R
Instruction Fields: A = Register index of operand rA
B = Register index of operand rB
C = Register index of operand rC
313029282726252423222120191817161514131211109876543210
ABC0x3900x3a