Presentation is loading. Please wait.

Presentation is loading. Please wait.

The University of Adelaide, School of Computer Science

Similar presentations


Presentation on theme: "The University of Adelaide, School of Computer Science"— Presentation transcript:

1 The University of Adelaide, School of Computer Science
17 January 2019 Lecture 2 Instructions: Logical Operations Chapter 2 — Instructions: Language of the Computer

2 Objectives Perform left/right shift operations on the contents of registers Perform bitwise operations on contents Perform zero extension on 16-bit immediate values Chapter 2 — Instructions: Language of the Computer — 2

3 Coverage Textbook Chapter 2.6
Chapter 2 — Instructions: Language of the Computer — 3

4 The University of Adelaide, School of Computer Science
17 January 2019 Logical Operations Instructions for bitwise manipulation §2.6 Logical Operations Operation C Java MIPS Shift left << sll Shift right >> >>> srl Bitwise AND & and, andi Bitwise OR | or, ori Bitwise NOT ~ nor Useful for extracting and inserting groups of bits in a word Chapter 2 — Instructions: Language of the Computer — 4 Chapter 2 — Instructions: Language of the Computer

5 The University of Adelaide, School of Computer Science
17 January 2019 Shift Operations - sll op rs rt rd shamt funct 6 bits 5 bits shamt: how many positions to shift Shift left logical Shift left and fill with 0 bits sll by i bits: multiplies by 2i sll $rd, $rt, shamt # R[rd]=R[rt]<<shamt sll $t0, $t0, 4 8 4 6 bits 5 bits Chapter 2 — Instructions: Language of the Computer — 5 Chapter 2 — Instructions: Language of the Computer

6 The University of Adelaide, School of Computer Science
17 January 2019 Shift Operations - srl op rs rt rd shamt funct 6 bits 5 bits shamt: how many positions to shift Shift right logical Shift right and fill with 0 bits srl by i bits: divides by 2i For non-negative number only srl $rd, $rt, shamt # R[rd]=R[rt]>>shamt srl $s0, $t0, 4 8 16 4 2 6 bits 5 bits Chapter 2 — Instructions: Language of the Computer — 6 Chapter 2 — Instructions: Language of the Computer

7 Bitwise Operations Bitwise logical operations in MIPS ISA
and $rd, $rs, $rt # R[rd] = R[rs] & R[rt] or $rd, $rs, $rt # R[rd] = R[rs] | R[rt] nor $rd, $rs, $rt # R[rd] = ~ (R[rs] | R[rt]) Instruction Format (R format) op rs rt rd shamt funct 6 bits 5 bits nor $t0, $t1, $t2 9 10 8 0x24 Chapter 2 — Instructions: Language of the Computer — 7

8 The University of Adelaide, School of Computer Science
17 January 2019 AND Operations Useful to mask bits in a word Select some bits, clear others to 0 and $t0, $t1, $t2 $t2 $t1 $t0 Chapter 2 — Instructions: Language of the Computer — 8 Chapter 2 — Instructions: Language of the Computer

9 The University of Adelaide, School of Computer Science
17 January 2019 OR Operations Useful to set bits in a word Set some bits to 1, leave others unchanged or $t0, $t1, $t2 $t2 $t1 $t0 Chapter 2 — Instructions: Language of the Computer — 9 Chapter 2 — Instructions: Language of the Computer

10 The University of Adelaide, School of Computer Science
17 January 2019 NOT Operations Useful to invert bits in a word Change 0 to 1, and 1 to 0 MIPS does not have NOT instruction MIPS has NOR 3-operand instruction a NOR b == NOT ( a OR b ) nor $t0, $t1, $zero Register 0: always read as zero $t1 $t0 Chapter 2 — Instructions: Language of the Computer — 10 Chapter 2 — Instructions: Language of the Computer

11 Logical Operations with Immediate
Bitwise logical operations with immediate andi $rt, $rs, Imm # R[rt] = R[rs] & ZeroExtImm ori $rt, $rs, Imm # R[rt] = R[rs] | ZeroExtImm Instruction Format (I format) op rs rt Immediate 6 bits 5 bits 16 bits andi $t0, $t1, 0xFF00 0x0C 9 8 0xFF00 6 bits 5 bits 16 bits Chapter 2 — Instructions: Language of the Computer — 11


Download ppt "The University of Adelaide, School of Computer Science"

Similar presentations


Ads by Google