ASH ARITHMETIC SHIFT
Purpose |
shift of integer |
Format |
opcode cnt.rb, src.rx, dst.wx |
Operation |
dst ß src shifted cnt bits; |
Condition codes |
N ß dst LSS 0; Z ß dst EQL 0; V ß {integer overflow}; C ß 0; |
Exceptions |
Integer overflow |
Opcodes |
78 ASHL Arithmetic Shift Long 79 ASHQ Arithmetic Shift Quad |
Description |
The source operand is arithmetically shifted by the number of bits specified by the count operand and the destination operand is replaced by the result. The source operand is unaffected. A positive count operand shifts to the left bringing Os into the least significant bit. A negative count operand shifts to the right bringing in copies of the most significant (sign) bit into the most significant bit position. A zero count operand replaces the destination operand with the unshifted source operand. |
Notes |
1. Integer overflow occurs on a left shift if any bit shifted into the sign bit position differs from the sign bit of the source operand. On overflow, the destination operand is replaced by the low order bits of the true result. 2. If cnt GEQ 32 (ASHL) or cnt GEQ 64 (ASHQ); the destination operand is replaced by 0 3. If cnt LEQ -32 (ASHL) or cnt LEQ -63 (ASHQ); all the bits of the destination operand are copies of the sign bit of the source operand. 4. A left shift is equivalent to a multiply by the corresponding power of two. A right shift is not, however, equivalent to a divide because negative numbers are rounded away from zero. |
Example 1
The program demonstrates several usages of ASHL opcode.
.text
main: .word 0
movb $1, r1
ashl $4, r1, r2
pushl r2
pushal format
calls $2, .printf # Prints 16
movb $0x10, r1
ashl $-4, r1, r2
pushl r2
pushal format
calls $2, .printf # Prints 1
movl $0xFFFFFFFF, r1
ashl $4, r1, r2
pushl r2
pushal format2
calls $2, .printf # Prints FFFFFFF0
movl $0xFFF00FFF, r1
ashl $-4, r1, r2
pushl r2
pushal format2
calls $2, .printf # Prints FFFF00FF
movl $0xF0FFFFFF, r1
ashl $4, r1, r2
pushl r2
pushal format2
calls $2, .printf # Prints FFFFFF0
pushl $0
calls $1, .exit
.data
format: .asciz "R2 is %d\n"
format2: .asciz "R2 is %8lX\n"