Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from

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
4.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Instruction Set-Intro
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
SPIM and MIPS programming
Chapter 2 Instructions: Language of the Computer
Chapter 2.
Computer Architecture CSCE 350
MIPS Function Continued
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 6 – Introduction to MIPS Data Transfer & Decisions I Pieter Abbeel’s recent.
CS61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS61C L6 Intro MIPS ; Load & Store (1) Garcia, Fall 2005 © UCB Hate EMACS? Love EMACS? Richard M. Stallman, a famous proponent of open- source software,
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
Normal C Memory Management °A program’s address space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via.
CS 61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
Lecture 4: Loads, Logic, Loops. Review Memory is byte-addressable, but lw and sw access one word at a time. These instructions transfer the contents of.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
CS61C L7 MIPS: Load & Store, Decisions (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
RISC Concepts, MIPS ISA and the Mini–MIPS project
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.
From C to Assembly Language Jen-Chang Liu, Spring 2006 Adapted from
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
CS61C L09 Introduction to MIPS : Data Transfer and Decisions (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
On Textbook CD: SPIM Jen-Chang Liu, Simulation of a virtual machine Virtual machine (simulator) Differences between SPIM and real MIPS? No delayed.
More decisions and logic (1) Fall 2010 Lecture 4: Loads, Logic, Loops.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
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.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
Ch2b- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Thanks for all the Memory! When 32 registers just won’t do. Many times (almost.
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
CWRU EECS 3221 Language of the Machine EECS 322 Computer Architecture Instructor: Francis G. Wolff Case Western Reserve University.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Memory Access Instructions Load and Store Addressing Modes Memory Addressing. Base addressing mode. Load byte and store byte: lb, lbu, sb Address alignment.
MIPS: Load & Store, Decisions. Memory management review Three 3’s Picking blocks off free list  best-, first-, next-fit Attempts to solve external fragmentation.
Computer Architecture & Operations I
Computer Architecture & Operations I
Memory Access Instructions
Instruction Set Architecture
Morgan Kaufmann Publishers
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Lecturer SOE Dan Garcia
These are slides from Comp411
C second, objective-c, Go up!
Lecturer SOE Dan Garcia
MIPS Assembly.
3.
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
COMS 361 Computer Organization
Instruction encoding The ISA defines Format = Encoding
COMS 361 Computer Organization
March 2006 Saeid Nooshabadi
MIPS Assembly.
Instruction encoding The ISA defines Format = Encoding
9/27: Lecture Topics Memory Data transfer instructions
Presentation transcript:

Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from

Example for Lab#1: 印出 sum=5.globl main main:.data str:.asciiz "sum=".text li $v0, 4 # $v0=4 la $a0, str # $a0=str syscall # print the string li $s0, 2 li $s1, 3 add $a0, $s0, $s1 # 2+3=5 li $v0, 1 # print integer syscall

不要亂寫 assembly code °add $s0, 1

Pseudo-instruction °SPIM can recognize a large instruction set than the original MIPS °Example: li (load immediate) MIPS Bare machine SPIM Pseudo-instruction real inst.

Shut down pseudo-instruction option

Outline °C operators, operands °Variables in Assembly: Registers °Comments in Assembly °Addition and Subtraction in Assembly °Memory Access in Assembly 指令

Assembly Operands: Memory °C variables map onto registers; what about large data structures like arrays? °1 of 5 components of a computer: memory contains such data structures °But MIPS arithmetic instructions only operate on registers, never directly on memory. °Data transfer instructions transfer data between registers and memory: Memory to register: load Register to memory: store

MIPS CPU load store

MIPS memory allocation (Textbook Fig2.17) 1 byte bits addressing one byte in an address It is software convention

Data Transfer: Memory to Reg (1/4) °To transfer a word of data, we need to specify two things: Register: specify this by number (0 - 31) Memory address: more difficult -Think of memory as a single one- dimensional array, so we can address it simply by supplying a pointer to a memory address. -Other times, we want to be able to offset from this pointer.

Recall: C pointer °How to access C variables through pointers? #include main() { char str[]=“Hello, World!”; char a; a = *str; a = *(str+1); } Hello,WHello,W … … str str+1

Data Transfer: Memory to Reg (2/4) °To specify a memory address to copy from, specify two things: A register which contains a pointer to memory A numerical offset (Max. offset???) °Example: 8($t0) specifies the memory address pointed to by the value in $t0, plus 8 bytes °The desired memory address is the sum of these two values, 8+$t0.

Memory access: 8($t0) Pointer $t0 (register) Offset 8 (constant) Offset $t0 (register) Start of an array 8 (constant)

Data Transfer: Memory to Reg (3/4) °Load Instruction Syntax: 1 2,3(4) where 1) operation name 2) register that will receive value 3) numerical offset in bytes 4) register containing pointer to memory °Instruction Name: lw (meaning Load Word, so 32 bits (4 bytes) or one word are loaded at a time) Example: lw $t0,12($s0)

Data Transfer: Memory to Reg (4/4) °Example: lw $t0,12($s0) This instruction will take the pointer in $s0, add 12 bytes to it, and then load the value from the memory pointed to by this calculated sum into register $t0 °Notes: $s0 is called the base register 12 is called the offset offset is generally used in accessing elements of array: base reg points to beginning of array

Global pointer $gp (Textbook Fig2.17) $gp=0x

Example: load word # hello.s.globl main main:.data str:.asciiz "Hello, World!".text addi $gp, 0x7fff lw $t0, 0x1($gp) H H Static data $gp= H “Hell” “o, W” “orld”

Example: load word

Data Transfer: Reg to Memory (1/2) °Also want to store value from a register into memory °Store instruction syntax is identical to Load instruction syntax °Instruction Name: sw (meaning Store Word, so 32 bits or one word are loaded at a time)

Data Transfer: Reg to Memory (2/2) °Example: sw $t0,12($s0) This instruction will take the pointer in $s0, add 12 bytes to it, and then store the value from register $t0 into the memory address pointed to by the calculated sum

Pointers v.s. Values °Key Concept: A register can hold any 32-bit value. (typeless) That value can be a (signed) int, an unsigned int, a pointer (memory address), etc. °If you write add$t2,$t1,$t0 then $t0 and $t1 better contain values °If you write lw $t2,0($t0) then $t0 better contain a pointer °Don’t mix these up!

Addressing: Byte vs. Word °Every word in memory has an address, similar to an index in an array °Early computers numbered words like C numbers elements of an array: Memory[0], Memory[1], Memory[2], … Called the “address” of a word °Computers needed to access 8-bit bytes as well as words (4 bytes/word) °Today machines address memory as bytes, hence word addresses differ by 4 Memory[0], Memory[4], Memory[8], … ?

C: word address => assembly: byte address °What offset in lw to select A[8] in C? A is a 4-byte type (ex. long int) °Compile by hand using registers: g = h + A[8]; g : $s1, h : $s2, $s3 :base address of A °4x8=32 bytes offset to select A[8] °add $s1, 32($s3) lw$t0,32($s3) # $t0 gets A[8] add $s1,$s2,$t0# $s1 = h+A[8]

Notes about Memory °Pitfall: Forgetting that sequential word addresses in machines with byte addressing do not differ by 1. # suppose $gp = 0x lw $t0, 0x0($gp) lw $t1, 0x1($gp) # next word?

More Notes about Memory: Alignment Aligned Not Aligned °MIPS requires that all words start at addresses that are multiples of 4 bytes °Called Alignment: objects must fall on address that is multiple of their size.

Role of Registers vs. Memory °What if more variables than registers? Compiler tries to keep most frequently used variable in registers °Why not keep all variables in memory? Smaller is faster: registers are faster than memory Registers more versatile: -MIPS arithmetic instructions can read 2, operate on them, and write 1 per instruction -MIPS data transfer only read or write 1 operand per instruction, and no operation

Brief summary (1/2) °In MIPS Assembly Language: Registers replace C variables One Instruction (simple operation) per line Simpler is Better Smaller is Faster °Memory is byte-addressable, but lw and sw access one word at a time. °A pointer (used by lw and sw ) is just a memory address, so we can add to it or subtract from it (using offset).

Brief summary (2/2) °New Instructions: add, addi, sub lw, sw °New Registers: C Variables: $s0 - $s7 Temporary Variables: $t0 - $t9 Zero: $zero