220 likes | 505 Views
Logical (or “bitwise”) Operations. Manipulating bits within words SHIFT AND OR. Logical (or “bitwise”) Operations SHIFT. Moving bits within word to left or right In C: << or >> operators Example: 0000 0000 0000 0000 0110 1111 0000 0000 two shifted left by eight, equals:
E N D
Logical (or “bitwise”) Operations • Manipulating bits within words • SHIFT • AND • OR Ch.4 - Computer Arithmetic - II
Logical (or “bitwise”) OperationsSHIFT • Moving bits within word to left or right • In C: << or >> operators • Example:0000 0000 0000 0000 0110 1111 0000 0000twoshifted left by eight, equals: 0000 0000 0110 1111 0000 0000 0000 0000two Ch.4 - Computer Arithmetic - II
Machine Instruction Format (R) op – basic operation (opcode) rs – first register source operand [0-31] rt – second register source operand [0-31] rd – register destination operand [0-31] shamt – shift amount funct – function Ch.4 - Computer Arithmetic - II
MIPS Instructions (Logical)(so far…) Ch.4 - Computer Arithmetic - II
Logical (or “bitwise”) OperationsAND and OR • Bitwise logical “AND” and “OR” • In C: & and | operators • Examples:0110 1100two • 1100 0000two = 0100 0000two 0110 1100two + 1100 0000two = 1110 1100two Ch.4 - Computer Arithmetic - II
Logical AND and OR AND OR a c b a c b Ch.4 - Computer Arithmetic - II
MIPS Instructions (Logical)(so far…) Ch.4 - Computer Arithmetic - II
Logical NOT and Multiplexor NOT Multiplexor (if d==0, c=a;else c=b) a c d a c b Ch.4 - Computer Arithmetic - II
Arithmetic Logic Unit (ALU) • Part of CPU • Device implementing arithmetic (ADD, SUB) and logical (AND, OR) operations • Built out of logic (AND, OR, NOT) gates and multiplexors* * - multiplexors are themselves built out of logic gates Ch.4 - Computer Arithmetic - II
The 32-bit ALU • Built out of 32 1-bit ALUs • 1-bit ALU • supports 1-bit AND, OR, NOT, ADD Ch.4 - Computer Arithmetic - II
1-bit AND/OR operation a result b Ch.4 - Computer Arithmetic - II
1-bit ADD CarryIn + a Sum b CarryOut Ch.4 - Computer Arithmetic - II
1-bit ADD Ch.4 - Computer Arithmetic - II
1-bit ADDCalculating CarryOut Logically CarryOut = (b • CarryIn) + (a • CarryIn) + (a • b) + (a • b • CarryIn) Ch.4 - Computer Arithmetic - II
1-bit ADDCalculating CarryOut CarryOut = (b • CarryIn) + (a • CarryIn) + (a • b) Ch.4 - Computer Arithmetic - II
1-bit ADDCalculating Sum Ch.4 - Computer Arithmetic - II
1-bit ALU CarryIn operation a 0 result 1 b + 2 CarryOut Ch.4 - Computer Arithmetic - II
The 32-bit ALUPutting it all together… (ripple carry) a0 b0 a1 b1 a2 b2 … How long would this take to run? a31 b31 Ch.4 - Computer Arithmetic - II
1-bit SUBCalculating SUB from ADD Binvert CarryIn operation a 0 result 1 b + 2 CarryOut Ch.4 - Computer Arithmetic - II
32-bit SUB • Connect like before • CarryOuti = CarryIni+1 • Binvert also tied to CarryIn on 0th unit Ch.4 - Computer Arithmetic - II