9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.

Slides:



Advertisements
Similar presentations
MIPS Assembly Tutorial
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.
Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
Branches Two branch instructions:
The University of Adelaide, School of Computer Science
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
Comp Sci Control structures 1 Ch. 5 Control Structures.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Computer Architecture CSCE 350
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Lecture 8: MIPS Instruction Set
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 6 – Introduction to MIPS Data Transfer & Decisions I Pieter Abbeel’s recent.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
CS61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS 61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
CS61C L09 Introduction to MIPS : Data Transfer and Decisions (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Intel has developed a new technique to generate random numbers that is suitable for integration directly into the CPU! This circuit can turn out 2.4 billion.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
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,
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
Lecture 4: MIPS Instruction Set
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
9/29: Lecture Topics Conditional branch instructions
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
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 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CDA 3101 Spring 2016 Introduction to Computer Organization
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
Computer Organization Instructions Language of The Computer (MIPS) 2.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
Lecture 6: Assembly Programs
CS2100 Computer Organisation
MIPS Coding Continued.
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
MPIS Instructions Functionalities of instructions Instruction format
The University of Adelaide, School of Computer Science
C second, objective-c, Go up!
Instruction encoding The ISA defines Format = Encoding
Lecturer SOE Dan Garcia
Computer Instructions
3.
COMS 361 Computer Organization
COMS 361 Computer Organization
Generalities for Assembly Language
MIPS Assembly Language Programming Computer Architecture
9/27: Lecture Topics Memory Data transfer instructions
Presentation transcript:

9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices Conditional branch instructions

Administrative notes Don’t forget: homework due Monday Readings: before or after lecture? Lecture slides on the web/printing Are you on the mailing list yet?

Memory and Addressing Only so many registers, but memory holds millions of data elements Think of memory as a big array AddressData Each address is a 32-bit number describing a location......and each data element is 8 bits of information.

MIPS Information Units Data types and size: –byte (eight bits) –half-word (two bytes) –word (four bytes) –float (four bytes, single precision) –double (eight bytes, double precision) Memory is byte addressable Data types start at an address divisible by the data type size (alignment)

Word Alignment Why do you think so many architectures use alignment? AddressData

How Big Can Memory Be? How big is an address? –32 bits How many addresses are there? –2 32 = about 4 billion How much data lives at each address? –1 byte How much memory can this computer have? –4 billion x 1 byte = 4 GB

Some Perspective Today’s attitude: –32 bits is definitely not enough for long –We hope 64 bits will be enough for a while The attitude a while back: –16 bits is enough for all time! –Who could possibly use up 64K of memory?

Loads and Stores Data transfer instructions let us –load data from memory to registers –store data from registers into memory In MIPS, all data must be loaded before use and stored after use –Load-store architecture lw instruction fetches a word sw instruction stores a word

Alternatives to Load-Store (p. 191) register-register is another name for load-store (MIPS) accumulator architectures had only one register (EDSAC) register-memory architectures allow one operand to be in memory (IBM 360, Intel 80386) memory-memory architectures allow both operands to be in memory (DEC VAX)

Load Syntax first argument: where to put the data second argument: offset third argument: address Desired result:MIPS assembly: lw $t0, 0($s0) Load the word at the address in $s0 into register $t0 Load the word at the address in $s0 plus 4 into $t0 lw $t0, 4($s0)

A Related Concept: move lw and sw are for moving data between memory and registers move is for copying data from one register to another common usage: zero a register move $t0, $0

“Complex” Example Revisited Desired result: MIPS assembly: add $s0, $s1, $s2 sub $s0, $s0, $s3 sub $s0, $s0, $s4 f = (g + h) - (i + j) f, g, h, i, j are in registers $s0, $s1, $s2, $s3, $s4, respectively

“Complex” Example with L/S Desired result: MIPS assembly: f = (g + h) - (i + j) load g, h, i, j, compute, then store f add $s0, $s1, $s2 sub $s0, $s0, $s3 sub $s0, $s0, $s4 AddressData f g h i j

Arrays in Assembly Programs One reason for lw syntax is arrays –keep the base address in a register –lw and sw on offsets into the array Example: int A[10]; A[0] = 0; A[1] = 0; # addr of A in $t0 sw $0, 0($t0) sw $0, 4($t0)

Variable Array Indexing Very common use of arrays: walk through the array by incrementing a variable lw and sw instructions allow offset to be specified: –as a constant –as the contents of a register lw $t0, 4($t2)lw $t0, $t1($t2) vs.

Array Example g = h + A[i] Idea: translate into assembly, assuming Base address of A is in $s3 g, h, i in $s1, $s2, $s4

Operation Types Remember these? Arithmetic –add, sub, mult, div Data Transfer –lw, sw, lb, sb Conditional Branch –beq, bne Unconditional Jump –j, jr, jal

Conditional Branch yes no ?... A change of the flow of control of the program that depends on a condition

Control flow in C Conditional branch constructs: –while, do while loops –for loops Unconditional jump constructs: –goto –switch statements

Branching Instructions beq bne other real instructions: b, bgez, bgtz, more... other pseudoinstructions: beqz, bge, bgt, ble, blt, more...

Pseudoinstructions One-to-one mapping between assembly and machine language not strictly true Assembler can do some of the work for you Example: bgt is a real instruction; blt is a pseudoinstruction move is a pseudoinstruction

Labels in MIPS MIPS allows text tags –a name for a place to branch to Under the covers, the assembler converts the text tag into an address loop: add $t0, $t0, $t0 # bne $t0, $t1, loop # sw $t2, 0($t3) #

Building a while loop in MIPS i=0; while(i<100) { i++; } Idea: translate into assembly.

How about a for loop? One answer: translate from for to while, then use while loop conventions This is typically how compilers handle loops for(i=0; i<N; i++) { do_stuff(i); } i=0; while(i<N) { do_stuff(i); i++; }

Example C Program int array[100]; void main() { int i; for(i=0; i<100; i++) array[i] = i; }

An Assembly Version main: move $t0, $0 # la $t1, array # start: bge $t0, 100, exit # sw $t0, 0($t1) # addi $t0, $t0, 1 # addi $t1, $t1, 4 # j start # exit: j $ra #