SOB SUETRACT ONE AND BRANCH
Purpose |
decrement integer loop count and loop |
Format |
opcode index.ml, displ.bb |
Operation |
index ß index -1: SOBGEQ If index GEQ 0 then PC ß PC + SEXT (displ); index ß index-1: SOBGTR If index GTR 0 then PC ß PC + SEXT (displ); |
Condition codes |
N ß index LSS 0; Z ß index EQL 0; V ß {integer overflow}; C ß C; |
Exceptions |
integer overflow |
Opcodes |
F4 SOBGEO Subtract One and Branch Greater Than or Equal F5 SOBGTR Subtract One and Branch Greater Than |
Description |
One is subtracted from the index operand and the index operand is replaced by the result. On SOBGEQ, If the index operand is greater than or equal to 0, the branch is taken. On SOBGTR, if the index operand is greater than 0, the branch is taken, if the branch is taken, the sign-extended branch displacement is added to the PC and the PC is replaced by the result. |
Notes |
1. Integer overflow occurs if the index operand before subtraction is the largest negative integer. On overflow, the index operand is replaced by the largest positive integer, and thus the branch is taken. 2. The C-bit is unaffected. |
Example 1
The program makes a loop that prints the numbers 10 down to 1 on the screen.
.text
main: .word 0
movl $10, r1
prnLoop:
pushl r1
pushal format
calls $2, .printf
sobgtr r1, prnLoop
pushl $0
calls $1, .exit
.data
format: .asciz "%d\n"
Example 2
The example shows the case when overflow occurs on SOBGEQ:
.text
main: .word 0
movl $0x80000000, r2
prnLoop:
pushl r2
pushal format
calls $2, .printf
sobgeq r2, prnLoop # overflow on the first time we reach this # line
pushl $0
calls $1, .exit
.data
format: .asciz "%ld\n"