Lecture 16: 10/29/2002CS170 Fall 20021 CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 5: MIPS Instruction Set
CS/COE0447 Computer Organization & Assembly Language
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
CS3350B Computer Architecture Winter 2015 Lecture 4
Chapter 2 Instructions: Language of the Computer
Chapter 2.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
Assembly Language II CPSC 321 Andreas Klappenecker.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
CPSC CPSC 3615 Computer Architecture Chapter 3 Instructions and Addressing (Text Book: Chapter 5)
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
CS35101 Computer Architecture Spring 2006 Week 5 Paul Durand ( Course url:
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
9/29: Lecture Topics Conditional branch instructions
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
EE472 – Spring 2007P. Chiang, with Slide Help from C. Kozyrakis (Stanford) ECE472 Computer Architecture Lecture #3—Oct. 2, 2007 Patrick Chiang TA: Kang-Min.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CDA 3101 Spring 2016 Introduction to Computer Organization
Computer Organization Instructions Language of The Computer (MIPS) 2.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
Lecture 17: 10/31/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Computer Architecture & Operations I
MIPS Instruction Set Advantages
Morgan Kaufmann Publishers
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
The University of Adelaide, School of Computer Science
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
CS170 Computer Organization and Architecture I
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
The University of Adelaide, School of Computer Science
Part II Instruction-Set Architecture
Instruction encoding The ISA defines Format = Encoding
Instruction encoding The ISA defines Format = Encoding
Instruction encoding The ISA defines Format = Encoding
9/27: Lecture Topics Memory Data transfer instructions
Conditional Control Structure
Presentation transcript:

Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture 16: 10/29/2002

CS170 Fall Outline Constant or Immediate Operands Pseudoinstrcutions Memory usage and a related pseudoinstruction

Lecture 16: 10/29/2002CS170 Fall Constant Operands 1/6 In the C compiler gcc, 52% of arithmetic operations involve constants. In circuit simulation program spice it is 69% x = x +4; where x is associated with register $s0, the constant 4 is stored in memory at memory address ADDR_4 What is the MIPS assembly code? lw $t0, ADDR_4($zero)# $t0  the constant 4 add $s0,$s0,$t0# $s0  $s0 + 4 This solution requires memory access to load a constant from memory (not efficient) Offer versions of arithmetic instructions in which operand can be a constant Use I-format (Immediate-format) for such instructions (2 registers and a constant) The MIPS field containing the constant is 16 bits long

Lecture 16: 10/29/2002CS170 Fall Constant Operands 2/6 Add Immediate instruction addi $s0,$s0,4# $s0  $s op rs rt immediate Immediate version of slt slti $t0,$s2,10# $t0 = 1 if $s2 < 10 Design principle: Make the common case fast Constant operands occur frequently, make constants part of arithmetic instructions. Much faster than a memory load

Lecture 16: 10/29/2002CS170 Fall Constant Operands 3/6 How about constants bigger than 16 bits? Set upper 16 bits of a constant in a register using lui instruction A subsequent instruction can specify the lower 16 bits of the constant lui $t0, 255#255 is Transfer 16 bit immediate constant into leftmost 16 bits of register and fill lower 16 bits with 0s Contents of register $t0 after lui instruction is executed

Lecture 16: 10/29/2002CS170 Fall Constant Operands 4/6 What is the MIPS assembly code to load the following 32-bit constant into register $s0? Load upper 16 bits using lui into $s0 lui $s0, 61# = Add lower 16 bits whose lower value is 2304 addi $s0, $s0, 2304# = Compiler or assembler break large constants into pieces and then reassemble into a register If assembler performs such job, it needs a temporary register available in which to create the long values Register $at is reserved for assembler

Lecture 16: 10/29/2002CS170 Fall Constant Operands 5/6 A word of caution addi sign extends 16-bit immediate field before performing addition Copy leftmost bit (sign bit) of 16-bit immediate field of instruction into upper 16 bits of a word before performing addition An alternative to addi is to use ori instruction (logical OR immediate) to create 32-bit constants in conjunction with lui (especially useful for base memory addresses) ori $s0, $s0,2304 ori loads 0s into the upper 16 bits (zero-extend immediate field) Why it is OK to use ori after lui?

Lecture 16: 10/29/2002CS170 Fall Constant Operands 6/6 Any constant value can be expressed in decimal, binary, or hexadecimal By default the value is in decimal in instructions To represent in hex use 0x before constant value lui $s0, 61# = To represent constant in hex lui $s0,0x003D # Why is 003D 16 ?

Lecture 16: 10/29/2002CS170 Fall Pseudoinstructions Some instructions are provided to simplify assembly language programming and translation, and give a richer set of instructions than those implemented by the hardware The assembler reads such instructions and replaces by a sequence of real machine instructions that have the same effect Example move $t0,$t1# pseudoinstruction $t0  $t1 Assembler converts this instruction into machine language equivalent add $t0, $zero,$t1# $t0  0 + $t1 Other pseudoinstructions blt, bgt, bge, and ble You can use pseudoinstructions to simplify programming, but attempt to write your programs in terms of REAL MIPS instructions

Lecture 16: 10/29/2002CS170 Fall Memory Usage in MIPS See Figure A.9 (section A.5 in appendix A) Reserved for Operating System Program code (“Text”) starts at (PC is program counter) Static data (data size known at compile time, and lifetime is the program’s entire execution) starts at Dynamic data (allocation occurs during execution) is next and grows up towards the stack Stack is dynamic (will see function when we look at procedure calls) The register $gp is the global pointer and is set to an address ( ) to make it easy to access data

Lecture 16: 10/29/2002CS170 Fall A related pseudoinstruction How does an array address get loaded into a register? Array is allocated in the static data portion of the data segment We can use load address pseudoinstruction la rdest, symbolic address la $s3, Address At compile time Address is known. Assume Address is A4 16 We need to put this value in $s3 using real instructions Immediate field is only 16 bits (4 hex digits)? In this case, la gets implemented using two instructions lui $s3, 0x1000 addi $s3,$s3,0x00A4