Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bitwise Logic and Immediate Operands

Similar presentations


Presentation on theme: "Bitwise Logic and Immediate Operands"— Presentation transcript:

1 Bitwise Logic and Immediate Operands
Bitwise operation Zero Extension Immediate operand instructions (ori, andi, xori) Textbook: Appendix A – A.10. MIPS R2000 assembly language. Central Connecticut State University, MIPS Tutorial. Chapter 11.

2 Bitwise Operation 0110 1100 operand 0101 0110 operand ------------
A bitwise operation is where a logical operation is performed on the bits of each column of the operands. With a bitwise logic operation two bit patterns are "lined up" Then a logic operation (such as OR, AND, …) is performed between pairs of bits. Here is the bitwise OR between two 8-bit patterns. operand operand result

3 Zero Extension of decimal numbers
When doing operations with decimal numbers everyday we do zero extension of that numbers intuitively if they have different amount of digits.

4 Zero Extension or padding with zeros with binary numbers
Suppose we have this 16 bit number as a first operand And this 32 bit number as a second operand We want to perform OR operation between 2 operands. First we should do zero extension of the first operand Then perform the operation with the full length of both operands. zero extended part zero extended 1st operand nd operand result

5 What is immediate operand ?
A machine instruction can use some of its bits as one of the operands for a machine operation. This is called an immediate operand. Using this kind of operations the program can set up the registers with the desirable known values. Immediate operand example address machine code assembly code —————————— —————————— ————————————— 0x x ori $8,$0,0x2    The last 16 bits (4 nibbles) of the machine instruction contain the immediate operand 0x0002.

6 Zero Extension of immediate operand
ori $8,$0,0x2 16 bits of immediate operand 32 bits of register zero zero extension An OR operation is done in each column. The 32-bit result is placed in register $8.

7 OR Immediate used with Non-zero Operands
ori d,s,const register d <-- bitwise OR of const with the contents of register $s(source) const represents a positive integer 0 <= const <= (0xFFFF -16 bits) The three operands of the assembly instruction d, $s, and const must appear in that order.

8 OR programming tricks What is the value of Xs ?
X 00X0 - R R – R3 Set the value of a bit to 1 Get the value of a bit

9 OR Immediate used with Zero Register – setup the register
ori d,$0,const register d <-- const. (d – destination)  const represents a positive integer 0 <= const <= (0xFFFF -16 bits) . The three operands of the assembly instruction d, $0, and const must appear in that order.

10 ORI Example ## Program to bitwise OR two patterns .text .globl main main: ori $8,$0,0x0FA5 ori $10,$8,0x368F ## End of file

11 AND Immediate Instruction
andi d,s,const register d <-- bitwise AND of immediate operand const and the contents of register $s. const is a 16-bit pattern 0x const ... 0xFFFF Simple AND Rules  AND-ing the Register with 0s sets the Register value to 0s. AND-ing the Register with the pattern (mask) 0s and 1s selects the original Register’s bits by mask of 1s. The original values are not changed only where the mask bits are 1s. The other bits are set to 0s.

12 AND programming tricks
What is the value of Xs ? XXXX XXXX - R R XXXX XXXX XXXX XXXX XXXX XXXX – R3 What is the value of R1 ? XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX - R1 R2 – R3

13 Exclusive Or Immediate (XOR)
Simple XOR Rules XOR the Register with itself sets the Register value to 0s. XOR the Register with 1s inverts the original Register’s content. XOR compares 2 operand and sets 1s in result bits where the operands are different. xori d,s,const register d <-- bitwise XOR of immediate operand const and the contents of register $s. const is a 16-bit pattern 0x const ... 0xFFFF

14 XOR programming tricks
Invertion - What is the value of X ? X R R – R3 Comparison - Is R1==R2 ? XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX - R1 XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX - R2 – R3 if (R3==0) then ...

15 Example Program .text .globl main main: ori $15, $0,0x0FA5
## Program to bitwise OR, AND, and XOR two patterns .text .globl main main: ori $15, $0,0x0FA5 ori $8,$15,0x368F andi $9,$15,0x368F xori $10,$15,0x368F ## End of file


Download ppt "Bitwise Logic and Immediate Operands"

Similar presentations


Ads by Google