Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.

Slides:



Advertisements
Similar presentations
ARM versions ARM architecture has been extended over several versions.
Advertisements

Appendix D The ARM Processor
Overheads for Computers as Components 2nd ed.
Multiplication – Microprocessor
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.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Load and store instruction.
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Computer Architecture CSCE 350
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 6 – Introduction to MIPS Data Transfer & Decisions I Pieter Abbeel’s recent.
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.
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Memory Access March,
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
CS61C L7 MIPS: Load & Store, Decisions (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
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.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
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.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
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.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Topic 10: Instruction Representation CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and.
Lecture 4. ARM Instructions Prof. Taeweon Suh Computer Science & Engineering Korea University COMP427 Embedded Systems.
Topic 9: Procedures CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Topic 7: Control Flow Instructions CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering.
ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh.
Unit-2 Instruction Sets, CPUs
Lecture 4: Load/Store Architectures CS 2011 Fall 2014, Dr. Rozier.
Lecture 8: Loading and Storing to Memory CS 2011 Fall 2014, Dr. Rozier.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
Arrays In high-level languages, we have several technigues available for constucting data stuctures: −One-dimensional arrays −Multi-dimensional arrays.
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.
ARM Instruction Set Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Peng-Sheng Chen.
MIPS: Load & Store, Decisions. Memory management review Three 3’s Picking blocks off free list  best-, first-, next-fit Attempts to solve external fragmentation.
Chapter 4 Copying Data.
CS2100 Computer Organisation
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
ECE 3430 – Intro to Microcomputer Systems
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
Chapter 4 Addressing modes
Lecturer SOE Dan Garcia
The University of Adelaide, School of Computer Science
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
C second, objective-c, Go up!
Topic 6: Bitwise Instructions
ARM Load/Store Instructions
Lecturer SOE Dan Garcia
Multiplication by small constants (pp. 139 – 140)
3.
COMS 361 Computer Organization
COMS 361 Computer Organization
COMS 361 Computer Organization
Branching instructions
March 2006 Saeid Nooshabadi
Overheads for Computers as Components 2nd ed.
Computer Architecture
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Immediate data Immediate operands : ADD r3, r3, #1 valid ADD r3, #1,#2 invalid ADD #3, r1,r2 invalid ADD r3, r2, #&FF ( to represent hexadecimal immediate.
Introduction to Assembly Chapter 2
ARM Load/Store Instructions
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and Engineering University of California, San Diego

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 ARM arithmetic instructions only operate on registers, never directly on memory.  Data transfer instructions transfer data between registers and memory:  Memory to register  Register to memory

Load/Store Instructions  The ARM is a Load/Store Architecture:  Does not support memory to memory data processing operations.  Must move data values into registers before using them.  This might sound inefficient, but in practice isn ’ t:  Load data values from memory into registers.  Process data in registers using a number of data processing instructions which are not slowed down by memory access.  Store results from registers out to memory.

Load/Store Instructions  The ARM has three sets of instructions which interact with main memory. These are:  Single register data transfer (LDR/STR)  Block data transfer (LDM/STM)  Single Data Swap (SWP)  The basic load and store instructions are:  Load and Store Word or Byte or Halfword  LDR / STR / LDRB / STRB / LDRH / STRH  Syntax:  { }{ } Rd,

Single register data transfer LDRSTR Word LDRBSTRB Byte LDRHSTRH Halfword LDRSB Signed byte load LDRSH Signed halfword load  Memory system must support all access sizes  Syntax:  LDR{ }{ } Rd,  STR{ }{ } Rd, e.g. LDREQB

Anatomy: 5 components of any Computer Processor Computer Control “brain” Datapath Registers Memory Devices Input Output Load (from) Store (to) These are “data transfer” instructions… Registers are in the datapath of the processor; if operands are in memory, we must transfer them to the processor to operate on them, and then transfer back to memory when done.

Data Transfer: Memory to Register  To transfer a word of data, we need to specify two things:  Register: r0-r15  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. Remember: Load FROM memory

Base Register Addressing Modes  There are many ways in ARM to specify the address; these are called addressing modes.  A register which contains a pointer to memory  Example: [r0]  specifies the memory address pointed to by the value in r0

Data Transfer: Memory to Register  Load Instruction Syntax: 1 2, [3]  where 1) operation name 2) register that will receive value 3) register containing pointer to memory  ARM Instruction Name:  LDR (meaning Load Register, so 32 bits or one word are loaded at a time)

Data Transfer: Memory to Register  Example: LDR r0,[r1] This instruction will take the pointer in r1, and then load the value from the memory pointed to by this calculated sum into register r0  Notes:  r1 is called the base register Data Flow

Data Transfer: Register to Memory  Also want to store value from a register into memory  Store instruction syntax is identical to Load instruction syntax  MIPS Instruction Name: STR (meaning Store Register, so 32 bits or one word are loaded at a time)  Example: STR r0,[r1] This instruction will take the pointer in r1 and store the value from register r0 into the memory address pointed to by the calculated sum Remember: Store INTO Memory Data Flow

Base Register Addressing Mode  The memory location to be accessed is held in a base register  STR r0, [r1]; Store contents of r0 to location pointed to ; by contents of r1.  LDR r2, [r1]; Load r2 with contents of memory location ; pointed to by contents of r1. r1 0x200 Base Register Memory 0x5 0x200 r0 0x5 Source Register for STR r2 0x5 Destination Register for LDR

Immediate Offset Addressing Mode  To specify a memory address to copy from, specify two things:  A register which contains a pointer to memory  A numerical offset (in bytes)  The desired memory address is the sum of these two values.  Example: [r0,#8]  specifies the memory address pointed to by the value in r0, plus 8 bytes

Immediate Offset Addressing Mode  Load Instruction Syntax: 1 2,[3,#4]  where 1) operation name 2) register that will receive value 3) register containing pointer to memory 4) numerical offset in bytes

Immediate Offset Addressing Mode  Example: LDR r0,[r1,#12] This instruction will take the pointer in r1, add 12 bytes to it, and then load the value from the memory pointed to by this calculated sum into register r0  Example: STR r0,[r1,#-8] This instruction will take the pointer in r 0, subtract 8 bytes from it, and then store the value from register r0 into the memory address pointed to by the calculated sum  Notes:  r1 is called the base register  #constant is called the offset  offset is generally used in accessing elements of array or structure: base reg points to beginning of array or structure

Immediate Offset Addressing Mode *Example: STR r0, [r1,#12] *To store to location 0x1f4 instead use: STR r0, [r1,#-12] *To auto-increment base pointer to 0x20c use: STR r0, [r1, #12]! (called immediate pre-indexed addressing mode) *If r2 contains 3, access 0x20c by multiplying this by 4: STR r0, [r1, r2, LSL #2] (called scaled register offset addressing mode) r1 0x200 Base Register Memory 0x5 0x200 r0 0x5 Source Register for STR Offset 12 0x20c

Post-indexed Addressing Mode *Example: STR r0, [r1], #12 *To auto-increment the base register to location 0x1f4 instead use: STR r0, [r1], #-12 *If r2 contains 3, auto-increment base register to 0x20c by multiplying this by 4: STR r0, [r1], r2, LSL #2 r1 0x200 Original Base Register Memory 0x5 0x200 r0 0x5 Source Register for STR Offset 12 0x20c r1 0x20c Updated Base Register

Using Addressing Modes Efficiently *Imagine an array, the first element of which is pointed to by the contents of r0. *If we want to access a particular element, then we can use pre-indexed addressing: r1 is element we want. LDR r2, [r0, r1, LSL #2] *If we want to step through every element of the array, for instance to produce sum of elements in the array, then we can use post-indexed addressing within a loop: r1 is address of current element (initially equal to r0). LDR r2, [r1], #4 Use a further register to store the address of final element, so that the loop can be correctly terminated element Memory Offset r0 Pointer to start of array

Swap and Swap Byte Instructions *Atomic operation of a memory read followed by a memory write which moves byte or word quantities between registers and memory. *Syntax: SWP{ }{B} Rd, Rm, [Rn] *Thus to implement an actual swap of contents make Rd = Rm. *The compiler cannot produce this instruction. Rm Rd Rn temp Memory

Pointers vs. Values  Key Concept: A register can hold any 32-bit value. That value can be a (signed) int, an unsigned int, a pointer (memory address), and so on  If you write ADDr2,r1,r0 then r0 and r1 better contain values  If you write LDR r2,[r0] then [r0] 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 (byte) as well as words (4 bytes/word)  Today machines address memory as bytes, hence 32-bit (4 byte) word addresses differ by 4  Memory[0], Memory[4], Memory[8], …

Compilation with Memory  What offset in LDR to select A[8] in C?  4x8=32 to select A[8] : byte vs word  Compile by hand using registers: g = h + A[8];  g : r1, h : r2, r3 :base address of A  1st transfer from memory to register: LDRr0,[r3, #32] ; r0 gets A[8]  Add 32 to r3 to select A[8], put into r0  Next add it to h and place in g ADD r1,r2,r0; r1 = h+A[8]

Notes about Memory  Pitfall: Forgetting that sequential word addresses in machines with byte addressing do not differ by 1.  Many an assembly language programmer has toiled over errors made by assuming that the address of the next word can be found by incrementing the address in a register by 1 instead of by the word size in bytes.  So remember that for both LDR and STR, the sum of the base address and the offset must be a multiple of 4 (to be word aligned)

More Notes about Memory: Alignment Aligned Not Aligned  ARM typically requires that all words start at byte addresses that are multiples of 4 bytes  Called Alignment: objects must fall on address that is multiple of their size. 0, 4, 8, or C hex Last hex digit of address is: 1, 5, 9, or D hex 2, 6, A, or E hex 3, 7, B, or F hex

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

Conclusion  Memory is byte-addressable, but LDR and STR access one word at a time.  A pointer (used by LDR and STR ) is just a memory address, so we can add to it or subtract from it (using offset).

Conclusion  Instructions so far:  Previously: ADD, SUB, MUL, MULA, [U|S]MULL, [U|S]MLAL, RSB AND, ORR, EOR, BIC MOV, MVN LSL, LSR, ASR, ROR CMP, B{EQ,NE,LT,LE,GT,GE}  New: LDR, LDR, STR, LDRB, STRB, LDRH, STRH