1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002.

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Lecturer PSOE Dan Garcia
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Chapter Three.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Cs 61C L7 Number.1 Patterson Spring 99 ©UCB CS61C Negative Numbers and Logical Operations Lecture 7 February 10, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)
CS61C L10 Introduction to MIPS : Decisions II (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
1  2004 Morgan Kaufmann Publishers Chapter Three.
CS61CL Machine Structures Lec 6 – Number Representation David Culler Electrical Engineering and Computer Sciences University of California, Berkeley.
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
CS 61C L07 MIPS Memory (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #7: MIPS Memory & Decisions.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 07 Introduction to MIPS : Decisions II Researchers at Microsoft and UW.
Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Arithmetic for Computers
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Computing Systems Basic arithmetic for computers.
Computer Engineering AddSub page 1 Basic Building Blocks Multiplexer + Demultiplexer Adder.
1  1998 Morgan Kaufmann Publishers Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
CSE378 Instr. encoding.1 Instruction encoding The ISA defines –The format of an instruction (syntax) –The meaning of the instruction (semantics) Format.
CSCI 136 Lab 1: 135 Review.
IT 251 Computer Organization and Architecture More MIPS Control Instructions Chia-Chi Teng.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Lecture 11: Chapter 2 Today’s topic –Numerical representations Reminders –Homework 3 posted, due 9/29/2014 –Homework 4 posted, due 10/6/2014 –Midterm 1.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 07 Introduction to MIPS : Decisions II Guest Lecturer Alan Christopher.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
Ellen Spertus MCS 111 October 16, 2001 Review. 2 What you will learn this semester Given devices that implement simple boolean functions… Understand how.
Addition, Subtraction, Logic Operations and ALU Design
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
Computer Arthmetic Chapter Four P&H. Data Representation Why do we not encode numbers as strings of ASCII digits inside computers? What is overflow when.
Computer Organization 1 Data Representation Negative Integers.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
Pirouz Bazargan SabetDecember 2003 Effective Implementation of a 32-bit RISC Processor Pirouz Bazargan Sabet University of Paris 6 - LIP6 - ASIM
May 2, 2001System Architecture I1 Systems Architecture I (CS ) Lecture 11: Arithmetic for Computers * Jeremy R. Johnson May 2, 2001 *This lecture.
Add & Subtract. Addition Add bit by bit from right to left Ex 5+6 or (5)0111 (7) (6)OR (3) 1011 (11)1010 (10)
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Computer Arthmetic Chapter Four P&H.
Computer Organization and Design Instruction Sets - 2
MISP Assembly.
Computer Architecture & Operations I
Topic 3a Two’s Complement Representation
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
A 1-Bit Arithmetic Logic Unit
Basic Building Blocks Multiplexer Demultiplexer Adder +
Chapter 3 Arithmetic for Computers
Basic Building Blocks Multiplexer Demultiplexer Adder +
MIPS Assembly.
COMS 361 Computer Organization
MIPS Arithmetic and Logic Instructions
Presentation transcript:

1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002

2 Homework 5: 1 a[0] = a[0] + a[1] - a[2]; lw $a0, __($t0) lw $a1, __($t0) lw $a2, __($t0) add $t1,, sub $t2, $t1, sw $t2, __($t0) Diagram assumes Big-Endian

3 Homework 5: 2 foo(int i, int j) { int temp; temp = a[i]; a[i] = a[j]; a[j] = temp; return; }

4 From representation to value 1000

5 Today Review: unsigned numbers Signed numbers MIPS instructions for signed and unsigned instructions Character encoding Logical operations

6 Unsigned binary arithmetic Biggest number? Smallest number?

7 Signed binary arithmetic (two’s complement) Sign bit Biggest number? Smallest number?

8 Signed binary to decimal

9 Shortcut To negate a number –Invert each bit –Add 1 Practice –1001  0110  0111 (7 10 ), so the original was -7 –1111 –1000

10 Relative sizes Which 4-bit number is bigger: 1000 or 0111? –Signed comparison –Unsigned comparison

11 Sign extension The number The number Extend the sign bit all the way to the left.

12 A closer look at load-byte (lb) load byte signed (lb) –Treat the byte as a signed number –Sign extend it to word length –lb $t0, 400($zero) load byte unsigned (lbu) –Treat the byte as an unsigned number –Zero extend it to word length –lbu $t0, 400($zero)

13 MIPS instructions Signed numbers –set less than (slt) –set less than immediate (slti) –load byte (lb) Unsigned numbers –set less than unsigned (sltu) –set less than immediate unsigned (sltiu) –load byte unsigned (lbu) a0 = two a1 = two slt $t0, $a0, $a1 # signed comparison sltu $t1, $a0, $a1 # unsigned comparison

14 How do we add signed numbers? Just like we always have! signed unsigned

15 What about overflow? signed unsigned

16 Definition of overflow When a carry bit flows into the sign bit This can only happen with signed arithmetic Machine raises an exception

17 MIPS instructions (2) Signed numbers –set less than (slt) –set less than immediate (slti) –load byte (lb) –add –add immediate (addi) –sub –subtract immediate (subi) Unsigned numbers –set less than unsigned (sltu) –set less than immediate unsigned (sltiu) –load byte unsigned (lbu) –add unsigned (addu) –add immediate unsigned (addiu) –subtract unsigned (subu) –subtract immediate unsigned (subiu)

18 Pseudo-instructions Definition: Instructions converted by the assembler into real machine instructions Examples: –Load immediate: li $r1, 5 is replaced by: –Subtract immediate: subi $r1, $r1, 5 is replaced by:

19 Differences between signed and unsigned instructions Sign extension vs. Zero extension –lb/lbu Whether to signal overflow/underflow –add/addu, addi/addiu, sub/subu How to compare numbers –slt/sltu, slti/sltiu

20 Remainder of today Logical operations –Bitwise operations –Shifting

21 Bitwise operations Perform the operation on each bit position Practice –Initial values $t0 = $t1 = –Problems not $t2, $t0 and $t2, $t0, $t1 or $t2, $t0, $t1

22 Shifting Assume $t0 = Shift left logical (sll) –sll $t1, $t0, 2 –result: Shift right logical (srl) –srl $t1, $t0, 2 –result: Note: Zeroes are shifted in