![Intel NIOS II Owner Reference Manual Download Page 228](http://html1.mh-extra.com/html/intel/nios-ii/nios-ii_owner-reference-manual_2071826228.webp)
Table 112.
stw
Bit Fields
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
A
B
IMM16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
IMM16
0x15
Table 113.
stwio
Bit Fields
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
A
B
IMM16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
IMM16
0x35
8.5.90. sub
Instruction
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 in the following code:
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 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 in the following code:
sub rC, rA, rB
xor rD, rA, rB
xor rE, rA, rC
and rD, rD, rE
blt rD, r0, label
# The original sub operation
continued...
8. Instruction Set Reference
NII-PRG | 2018.04.18
Nios II Processor Reference Guide
228