9/27: Lecture Topics Memory Data transfer instructions

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

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.
Branches Two branch instructions:
The University of Adelaide, School of Computer Science
Deeper Assembly: Addressing, Conditions, Branching, and Loops
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.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
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.
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.
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.
CS61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
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.”
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.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
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.
 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 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.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
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 5: Procedure Calls
Computer Architecture & Operations I
Lecture 6: Assembly Programs
CS2100 Computer Organisation
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Lecturer SOE Dan Garcia
Pick up the handout on your way in!!
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
MPIS Instructions Functionalities of instructions Instruction format
Henk Corporaal TUEindhoven 2010
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
Review.
Part II Instruction-Set Architecture
Computer Instructions
3.
COMS 361 Computer Organization
COMS 361 Computer Organization
COMS 361 Computer Organization
MIPS Coding Continued.
Computer Architecture
Generalities for Assembly Language
MIPS Assembly Language Programming Computer Architecture
Conditional Branching (beq)
Presentation transcript:

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

If nobody every writes assembly, why learn it? Why did people used to learn assembly? only language available, faster A few people still write assembly compiler/OS writers, embedded systems, games It gives you an understanding of a program’s performance procedure calls It’s a building block for more important topics pipelining, caching, operating systems Better understanding of computer science

Memory and Addressing Only so many registers, but memory holds millions of data elements Think of memory as a big array Address Data 01011010 Each address is a 32-bit number describing a location... ...and each data element is 8 bits of information. 10011001 1 2 10001111 3 11110010 4 00011001

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? Address Data 4 8 12 16 Why do you think so many architectures use alignment?

How Big Can Memory Be? How big is an address? 32 bits How many addresses are there? 232 = 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: The attitude a while back: 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: 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, 0($s0) 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: f = (g + h) - (i + j) f, g, h, i, j are in registers $s0, $s1, $s2, $s3, $s4, respectively MIPS assembly: add $s0, $s1, $s2 sub $s0, $s0, $s3 sub $s0, $s0, $s4

“Complex” Example with L/S Desired result: f = (g + h) - (i + j) load g, h, i, j, compute, then store f Address Data MIPS assembly: f 200 g 204 208 h add $s0, $s1, $s2 sub $s0, $s0, $s3 sub $s0, $s0, $s4 212 i 216 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 vs. lw $t0, 4($t2) lw $t0, $t1($t2)

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

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

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

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 Idea: translate i=0; while(i<100) { i++; } 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 i=0; while(i<N) { do_stuff(i); i++; } for(i=0; i<N; i++) { do_stuff(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 #