Logical Instructions - Computer Architecture - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Computer Architecture which includes Machines Address Memory, Notes About Memory, Assembly Language Programmer, Instruction Support for Functions, Jump Register, Nested Procedures, Register Values, Memory Organization etc. Key important points are: Logical Instructions, Shift Instructions, Bitwise Operations, Memory Access, Contents of Register, Unsigned Integer, Classes of Instructions, Logical Operators, Combinations of Inputs

Typology: Slides

2012/2013

Uploaded on 03/22/2013

dhimant
dhimant 🇮🇳

4.3

(8)

128 documents

1 / 34

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Architecture
CPSC 321
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download Logical Instructions - Computer Architecture - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Computer Architecture

CPSC 321

Overview

• Logical Instructions

• Shifts

Logical Operators

  • Two basic logical operators:
    • AND: outputs 1 only if both inputs are 1
    • OR: outputs 1 if at least one input is 1

Logical Operators

  • Truth Table: standard table listing all possible combinations of inputs and resultant output for each
  • Truth Table for AND and OR

A B AND OR 0 0 0 1 1 0 1 1

  • Two basic logical operators:
    • AND: outputs 1 only if both inputs are 1
    • OR: outputs 1 if at least one input is 1

Uses for Logical Operators

  • Note that ANDing a bit with 0 produces a 0 at the output while ANDing a bit with 1 produces the original bit.
  • This can be used to create a mask.
    • Example:

1011 0110 1010 0100 0011 1101 1001 1010

0000 0000 0000 0000 0000 1111 1111 1111

  • The result of ANDing these two is: 0000 0000 0000 0000 0000 1101 1001 1010
  • The second bit string in the example is called a mask. It is used to isolate the rightmost 12 bits of the first bit string by masking out the rest of the string (e.g. setting it to all 0s).

Uses for Logical Operators

  • Thus, the and operator can be used to set certain portions of a bit string to 0s, while leaving the rest alone. - In particular, if the first bitstring in the above example were in $t0, then the following instruction would mask it: andi $t0,$t0,0xFFF
  • Similarly, note that ORing a bit with 1 produces a 1 at the output while ORing a bit with 0 produces the original bit.
  • This can be used to force certain bits of a string to 1s.
    • For example, if $t0 contains 0x12345678, then after this instruction: ori$t0, $t0, 0xFFFF
    • $t0 contains 0x1234FFFF (e.g. the high-order 16 bits are untouched, while the low-order 16 bits are forced to 1s).

Shift Instructions (2/3)

  • Shift Instruction Syntax:

1 2,3,

  • where
  1. operation name
  2. register that will receive value
  3. first operand (register)
  4. shift amount (constant <= 32)

MIPS shift instructions:

  1. sll (shift left logical): shifts left and fills emptied bits with 0s
  2. srl (shift right logical): shifts right and fills emptied bits with 0s
  3. sra (shift right arithmetic): shifts right and fills emptied bits by sign extending

Shift Instructions (3/3)

  • Example: shift right arith (sra) by 8 bits 0001 0010 0011 0100 0101 0110 0111 1000

 Example: shift right arith (sra) by 8 bits

1001 0010 0011 0100 0101 0110 0111 1000

Uses for Shift Instructions (2/4)

  • Could use instead: sll $t0,$t0, srl $t0,$t0,

t 0001 0010 0011 0100 0101 0110 0111 1000 After sll 0101 0110 0111 1000 0000 0000 0000 0000

After srl

Uses for Shift Instructions (3/4)

  • In binary: Multiplying by 2 is same as shifting left by 1: 112 x 10 2 = 110 (^2) 10102 x 10 2 = 10100 (^2) Multiplying by 4 is same as shifting left by 2: 11 2 x 100 2 = 1100 (^2) 10102 x 100 2 = 101000 (^2) Multiplying by 2 n^ is same as shifting left by n

The Story so far…

  • We introduced numerous MIPS assembly language

instructions.

  • We are now familiar with registers and register usage

conventions.

  • We know how to use system calls, basic I/O
  • We have learned how the stack works
  • What is missing?

Practice! Practice! Practice!

What Next?

  • We need a more detailed knowledge about the

instruction formats to fully appreciate certain restrictions.

  • The functional interface is easy to understand, since it is basically familiar procedural programming
  • We need to understand how the computer interprets the instruction, so that we can transition to the discussion of the MIPS hardware architecture

Instruction Word Formats

  • Register format
  • Immediate format
  • Jump format

op-code rs rt rd shamt funct

op-code rs rt immediate value

op-code 26 bit current segment address

6 5 5 16

6 5 5 5 5 6

6 26

Register Format (R-Format)

  • Register format
  • op: basic operation of instruction
  • funct: variant of instruction
  • rs: first register source operand
  • rt: second register source operand
  • rd: register destination operand
  • shamt: shift amount

op-code rs rt rd shamt funct 6 5 5 5 5 6