Chapter Two MIPS Arithmetic

Similar documents
Fast Arithmetic. Philipp Koehn. 19 October 2016

Arithmetic for Computers

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

ECE260: Fundamentals of Computer Engineering

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

ECE260: Fundamentals of Computer Engineering

We are quite familiar with adding two numbers in decimal

MIPS Assembly Programming

Number Systems and Their Representations

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

3. Instruction Set Architecture The MIPS architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Part 1 (70% of grade for homework 2): MIPS Programming: Simulating a simple computer

Integer Arithmetic. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 8: Addition, Multiplication & Division

Integer Multiplication and Division

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Instructions: Language of the Computer

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

MIPS History. ISA MIPS Registers

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

Arithmetic. Chapter 3 Computer Organization and Design

ECE260: Fundamentals of Computer Engineering

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

MIPS Instruction Format

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

Homework 3. Assigned on 02/15 Due time: midnight on 02/21 (1 WEEK only!) B.2 B.11 B.14 (hint: use multiplexors) CSCI 402: Computer Architectures

LAB B Translating Code to Assembly

ECE331: Hardware Organization and Design

CS3350B Computer Architecture MIPS Introduction

ICS 233 Computer Architecture & Assembly Language. ICS 233 Computer Architecture & Assembly Language

Number Representations

Signed Multiplication Multiply the positives Negate result if signs of operand are different

SPIM Instruction Set

Thomas Polzer Institut für Technische Informatik

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

COMP MIPS instructions 2 Feb. 8, f = g + h i;

The MIPS Instruction Set Architecture

Unsigned Binary Integers

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

Unsigned Binary Integers

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

CS3350B Computer Architecture MIPS Instruction Representation

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: The MIPS ISA (P&H ) Consulting hours. Milestone #1 (due 1/26)

CS3350B Computer Architecture

CSCI 402: Computer Architectures

Computer Organization MIPS ISA

TSK3000A - Generic Instructions

CS 61c: Great Ideas in Computer Architecture

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

SIGNED AND UNSIGNED SYSTEMS

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Lecture 12 Integers. Computer and Network Security 19th of December Computer Science and Engineering Department

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Operations, Operands, and Instructions

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner. Topic 3: Arithmetic

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

MIPS Integer ALU Requirements

COMP2611: Computer Organization. Data Representation

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

ECE331: Hardware Organization and Design

We will study the MIPS assembly language as an exemplar of the concept.

Assembly Language Programming

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides

Chapter Three. Arithmetic

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Chapter 2A Instructions: Language of the Computer

MIPS Hello World. MIPS Assembly 1. # PROGRAM: Hello, World! # Data declaration section. out_string:.asciiz "\nhello, World!\n"

Review: MIPS Organization

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

CS 110 Computer Architecture MIPS Instruction Formats

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1

INSTRUCTION SET COMPARISONS

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

Review. Steps to writing (stateless) circuits: Create a logic function (one per output)

Number System. Introduction. Decimal Numbers

M2 Instruction Set Architecture

COMPUTER ORGANIZATION AND DESIGN

Lecture Topics. Announcements. Today: The MIPS ISA (P&H ) Next: continued. Milestone #1 (due 1/26) Milestone #2 (due 2/2)

Mips Code Examples Peter Rounce

Instructors: Randy H. Katz David A. PaHerson hhp://inst.eecs.berkeley.edu/~cs61c/fa10. Fall Lecture #6. Agenda

COMPUTER ORGANIZATION AND DESIGN

Run time environment of a MIPS program

Transcription:

Chapter Two MIPS Arithmetic Computer Organization

Review Binary Representation Used for all data and instructions Fixed size values: 8, 16, 32, 64 Hexadecimal Sign extension Base and virtual machines. pseudo instructions MIPS Arithmetic 2

Registers Registers special storage locations built into the CPU for faster access. characteristics: 32 user accessible registers. each store 32-bits. each has a symbolic name. some registers have a special purpose. MIPS Arithmetic 3

Registers Some of the more commonly used registers include. Name Usage $zero constant 0. $s0 - $s7 general purpose temporary (saved). $t0 - $t9 general purpose temporary. $a0 - $a3 passing arguments to functions. $v0 - $v1 return values from functions. MIPS Arithmetic 4

Integer Arithmetic All computers must be able to perform arithmetic. In C/C++ + - * / % (/) Integer division if both operands are integers. MIPS Arithmetic 5

MIPS Arithmetic Have three operands. All must be registers. Example: C/C++, Java (assume vars a c are in $s0 - $2) int a, b, c; a = b + c; MIPS add $s0, $s1, $s2 MIPS Arithmetic 6

MIPS Arithmetic Derived from two of the principles: simplicity favors regularity smaller is faster This simplicity comes at a price. a = b + c - d; Requires multiple MIPS instructions. add $t0, $s1, $s2 # t = b + c sub $s0, $t0, $s3 # a = t - d MIPS Arithmetic 7

Arithmetic Example 1 Convert the following C segment to MIPS a = b + c; d = e + f - a; Answer: (a f stored in $s0...$s5) add $s0, $s1, $s2 # a = b + c add $t0, $s4, $s5 # t = e + f sub $s3, $t0, $s0 # d = t - a MIPS Arithmetic 8

Arithmetic Example 2 Convert the following C segment to MIPS x = u + (y z) + (v - w); Answer: (u z stored in $s0...$s5) sub $t0, $s4, $s5 # t0 = y z sub $t1, $s1, $s2 # t1 = v w add $t2, $s0, $t0 # t2 = u + t0 add $s3, $t2, $t1 # x = t2 + t1 MIPS Arithmetic 9

Arithmetic Example 3 Convert the following C segment to MIPS a = b + (d e); b = b - (c + f) a; Answer: MIPS Arithmetic 10

Immediate Operands Constants are very common in programs. a = b - 1; b++; c = x[i+1]; Principle 3: make the common case fast. MIPS provides some immediate instructions. addi $s0, $s1, -1 addi $s1, $s1, 1 MIPS Arithmetic 11

Immediate Operations Machine instructions (non-pseudo) 16-bit constant With sign-extension Consider value -7 16-bits: 1111111111111001 32-bits: 11111111111111111111111111111001 MIPS Arithmetic 12

Arithmetic Integer Operations Instruction Description add rd, rs, rt add: rd rs + rt addi rd, rs, imm add immediate: rd rs + imm sub rd, rs, rt subtract: rd rs + rt mul rd, rs, rt multiply: rd rs * rt div rd, rs, rt divide: rd rs / rt rem rd, rs, rt modulo: rd rs % rt abs rd, rs absolute value: rd rs neg rd, rs negation: rd - rs MIPS Arithmetic 13

neg Implementation How is the neg pseudo instruction implemented? neg $t0, $t1 # $t0 = -$t1 By subtraction sub $t0, $zero, $t1 # $t0 = 0 - $t1 MIPS Arithmetic 14

Load Immediate What about constants in non-immediate instructions. c = b * 5 We can use load immediate (pseudo). li $t2, 5 mul $t0, $t1, $t2 MIPS Arithmetic 15

Load Immediate How can we implement the li instruction? li $t2, 58 Break it into two conditions: up to 15-bits larger than 15-bits For small constants: addi $t2, $zero, 58 MIPS Arithmetic 16

Large Constants What about constants larger than 15-bits? li $t0, 0x4F287 $t0: 0004F287 MIPS Arithmetic 17

Move Operation We also have a move instruction (pseudo). move $t3, $t2 # $t3 $t2 How is it implemented? MIPS Arithmetic 18

Mixed Sizes Consider the following code segment int a, b; short c; char d; a = b + c * d; MIPS Arithmetic 19

Unsigned Values Consider the following code segment int w; unsigned int x; unsigned short y; unsigned char z; w = x + y * z; MIPS Arithmetic 20

Unsigned Arithmetic Operations In MIPS, the only difference between the signed and unsigned operations Whether to signal when an overflow occurs. These do not signal an overflow Instruction addu rd, rs, rt addiu rd, rs, imm subu rd, rs, rt Description add: rd rs + rt add immediate: rd rs + imm subtract: rd rs + rt MIPS Arithmetic 21

Overflow When the proper result of an arithmetic operation can not be represented with the alloted number of bits. What happens? Programming language Operating system Programmer MIPS Arithmetic 22

Overflow Consider the following operation of 4-bits: 0110 + 1101 ------ 10011 Does overflow occur? MIPS Arithmetic 23

Overflow When does overflow occur with addition and subtraction? Operation Operand A Operand B Overflow Occurs for Results A + B >= 0 >= 0 < 0 A+B < 0 < 0 >= 0 A - B >= 0 < 0 < 0 A - B < 0 >= 0 >= 0 MIPS Arithmetic 24