Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shift Instructions and Logical Instructions

Similar presentations


Presentation on theme: "Shift Instructions and Logical Instructions"— Presentation transcript:

1 Shift Instructions and Logical Instructions
Shift Instructions (sll, srl) No Operation Logical Instructions (or, and, xor, nor) Not, Move - pseudo instructions Textbook: Appendix A – A.10. MIPS R2000 assembly language. Central Connecticut State University, MIPS Tutorial. Chapter 12.

2 Shift Instructions (sll, srl)
It often happens that a bit pattern must be moved left or right within a register. The instructions that do this are the shift instructions.

3 Shift Left Logical sll d,s,shft
$d <-- the bits in $s shifted left logical by shft positions where 0 <= shft < 32 The ALU (arithmetic/logic unit) which does the operation pays no attention to what the bits mean. If the bits represent an unsigned integer, then a left shift is equivalent to multiplying the integer by two.

4 SLL example ## Program to logical shift left a pattern .text .globl main main: ori $8, $0, 0x6F sll $9, $8, 2 How 0x6F appears in the register $8 ? How it becomes to 0x1BC ?

5 Shifting in Place When an ALU operation is performed:
Data is copied from the register(s) into the ALU. Then, the ALU does the operation. Next the result is written to the designated result register. There is no problem when an operand register is also the result register because the operand data was transferred to the ALU in the first step, leaving the register open to receive the result. Sending the result back to the source register is called shifting in place.

6 Machine instruction for shift in place
opcode source dest shft 2ndary ALUop $8 $ sll   sll $8, $8, 2

7 No-Op sll $0, $0, 0 ALUop $0 $0 0 sll
A machine instruction that does nothing is called (in official computer science jargon) a no-op (no operation). Register $0 always contains a 32-bit zero so shifting it left by zero positions and attempting to put the result back in $0 does nothing. Any instruction that attempts to alter $0 does nothing, but this instruction is the preferred way of doing nothing. opcode source dest shft 2ndary ALUop $0 $ sll sll $0, $0, 0

8 Moves bits to the right by a number of positions less than 32.
The high-order bit gets zeros The low-order bits are discarded If the bit pattern is regarded as an unsigned integer, or a positive two's comp. integer, then a right shift of one bit position performs an integer divide by two. A right shift by N positions performs an integer divide by 2N. srl d,s,shft $d <-- logical right shift of $s by shft positions. shft is a 5-bit integer, 0 <= shft < 32

9 Bitwise logic instructions
or d,s,t # $d <-- bitwise OR between $s with $t. and d,s,t # $d <-- bitwise AND between $s with $t. xor d,s,t # $d <-- bitwise XOR between $s with $t. operand 1 AND OR XOR XOR does inversion wherever one of the operands contains ones.

10 Not Or nor d,s,t # $d <-- bitwise NOR between
$s with $t. NOT pseudoinstruction as NOR with $0 nor d,s,$0 # $d <-- bitwise NOT of $s operand 1 AND OR XOR NOR NOR does inversion wherever one of the operands contains zeroes.

11 MOVE pseudoinstruction as OR with Zero
Copying the pattern in a source register to a destination register is called a move operation, even though the source register does not change. or d,s,$0 # $d <-- contents of $s operand 1 AND OR XOR NOR OR does setup wherever one of the operands contains zeroes.

12 Summary New learned instructions AND OR XOR NOR
and d,s,t or d,s,t xor d,s,t nor d,s,t $d <— $s and $t $d <— $s or $t $d <— $s xor $t $d <— $s nor $t All learned instructions and andi nor or ori sll srl xor xori


Download ppt "Shift Instructions and Logical Instructions"

Similar presentations


Ads by Google