Logical Operations Boy who sow wild oats better hope for crop failure.

Slides:



Advertisements
Similar presentations
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Advertisements

Arithmetic for Computers
CMPE 325 Computer Architecture II
Cosc 2150: Computer Organization Chapter 9, Part 2 Integer multiplication and division.
1 Arithmetic and Logical Operations - Part I. Boolean Operations A boolean variable can only have one of the two values, i.e, can either be 1 or 0. Given.
Integer Multiplication and DivisionICS 233 – KFUPM © Muhamed Mudawar slide 1 Multiplicand and HI are sign-extended  Sign is the sign of the result Signed.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Booth’s Algorithm.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
Integer Multiplication and Division
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
EECC341 - Shaaban #1 Lec # 3 Winter Binary Multiplication Multiplication is achieved by adding a list of shifted multiplicands according.
Arithmetic and Logical Operations
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
ECE 4110– Sequential Logic Design
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU.
Integer Conversion Between Decimal and Binary Bases Conversion of decimal to binary more complicated Task accomplished by –Repeated division of decimal.
Multiplication of signed-operands
Digital Kommunikationselektronik TNE027 Lecture 2 1 FA x n –1 c n c n1- y n1– s n1– FA x 1 c 2 y 1 s 1 c 1 x 0 y 0 s 0 c 0 MSB positionLSB position Ripple-Carry.
Lecture 6: Multiply, Shift, and Divide
Integer Multiplication and Division
1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
Integer Multiplication and Division COE 301 Computer Organization Dr. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University.
Integer Operations Computer Organization and Assembly Language: Module 5.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
CHAPTER 3 BINARY NUMBER SYSTEM. Computers are electronic machines which operate using binary logic. These devices use two different values to represent.
1 Lecture 5Multiplication and Division ECE 0142 Computer Organization.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
More Binary Arithmetic - Multiplication
Multiplication and Division basics
Computer Architecture & Operations I
Integer Multiplication and Division
CSCI206 - Computer Organization & Programming
Computer Organization and ASSEMBLY LANGUAGE
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
MISP Assembly.
Computer Organization and Design
Computer Architecture & Operations I
ECEG-3202 Computer Architecture and Organization
Shift & Rotate Instructions)
Logical Operations Boy who sow wild oats better hope for crop failure.
October 15 Chapter 4 – Multiplication/Division Go to the State Fair!
Chapter 8 Computer Arithmetic
Arithmetic and Logic Chapter 5
Binary to Decimal Conversion
MIPS Arithmetic and Logic Instructions
Bit Manipulations CS212.
COE 202: Digital Logic Design Number Systems Part 2
1 Lecture 5Multiplication and Division ECE 0142 Computer Organization.
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

Logical Operations Boy who sow wild oats better hope for crop failure. Chinese Proverb

7 Logical Operations in MIPS not x, y and x, y, z nand x, y, z or x, y, z nor x, y, z xor x, y, z xnor x, y, z x gets y’ x gets result of y,z operation

Mask and Merge Example Macros can be useful to cut down on writing repetitive code blocks like print statements. NewLine macro will print a linefeed to the console, called by newline PHex will print an int in hex format, %value is a substitution string, in this case it should be a register. E.g. PHex($t4)

Mask and Merge Example. Mask using bitwise and will mask out bits, E.g. 0x70707070 Merge using bitwise or, sets bits. E.g 0x7777FFFF Note: the macro calls

Shifts Move bits to new locations in a word 3 Type of Shifts allowed Logical shift Arithmetic Shift Rotate Can shift right or left by a specified number of bits (0 - 31)

MAL’s Shift Operations sll shift left logical srl shift right logical rol rotate left ror rotate right sra shift right arithmetic Format operation destination, source, Amount

Logical Shift (cont.) Logical shifts give us an alternate method of bit extraction (instead of masking). To extract bits p through q sll x, y, (31-q) srl x, x, (31-q+p) Example: Extract bits 16 through 23 sll x, y, (31-23) = sll x, y, 8 srl x, x, (31-23+16) = srl x, x, 24

In fact the result of this sra operation is floor(-5/2)

Count # of 1’s in a word Mask out all bits except the LSB, if it is a 1 count it. Rotate right 1 bit and repeat

Partial Products Partial products are added as they are generated

Standard Multiply Algorithm Multiply can be done using a series of shift and add operations product = 0 while multiplier is non-zero if multiplier LSB = 1 product = product + multiplicand multiplier = multiplier >> 1 multiplicand = multiplicand << 1

Multiply

Alternate Multiply Algorithm how h/w does it. 32 bit x 32 bit = 64 bit result Multiplicand is added into Product_High, Multiplier loaded into Product low. Shift Product_High Product_Low A Multiplicand B Multiplier

Alternate Multiply Algorithm how h/w does it product_high = 0 product_low = multiplier do { If (LSB of multiplier == 1) then add multiplicand to product_High shift multiplier (product_low) right 1 shift product_high right 1 } while (product has not been shifted 32 times) Note: the shift will be done together as 1 cycle in h/w. Broken down for clarity. After 32 shifts, the multiplier will be moved out.

End Notes on Multiply The algorithm loops 32 time Product_low has been shifted 32 times Product_high has been shifted 32 times LSB become MSB of Product_low on shift Rather than shift the multiplicand left and keeping the product stationary, we keep the multiplicand stationary and shift the product right. Easier to build in h/w

Signed Multiplication Same algorithm but with small adjustment Save XOR of sign bits to get product sign bit Convert multiplier & multiplicand to positive Perform normal multiplication algorithm Negate result if product sign bit is 1

Unsigned Division Algorithm remainder = dividend quotient = 0 for i=1 to # of significant digits divisor = divisor >> 1 quotient = quotient <<1 if divisor <= remainder remainder = remainder - divisor quotient = quotient +1

Unsigned Division 01000010 --Dividend = 66 00000110 --Divisor = 6 Determine # of significant digits in quotient, shift divisor left until shifted divisor is > dividend 01000010 --dividend 01100000 --Shifted divisor

Division Example

Determine number of significant bits in quotient Division Determine number of significant bits in quotient

Division

Alternate Division Algorithm how h/w does it Low High Shift Remainder Dividend +/- Quotient Divisor Initialize High to 0 and Low to the Dividend.

Alternate Division Algorithm how h/w does it High = 0 Low = Dividend { shift left High = High – divisor If High < 0 High = High + divisor Else Low = Low or 0x01 } (While not shifted 32 times) Note: Low OR 0x01 will set the LSB of Low, same as adding a 1 since the shift left would shift in a 0.

End!