Logical (or “bitwise”) Operations

1 / 20

# Logical (or “bitwise”) Operations - PowerPoint PPT Presentation

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: &lt;&lt; or &gt;&gt; operators Example: 0000 0000 0000 0000 0110 1111 0000 0000 two shifted left by eight, equals:

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Logical (or “bitwise”) Operations' - timberly

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
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

CarryIn

+

a

Sum

b

CarryOut

Ch.4 - Computer Arithmetic - II

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

CarryOut = (b • CarryIn)

+ (a • CarryIn)

+ (a • b)

Ch.4 - Computer Arithmetic - II

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