Chapter 4 Addressing modes CEG2400 Microcomputer Systems CEG2400 ch4 addressing modes v3a 1.

Slides:



Advertisements
Similar presentations
Computer Science Education
Advertisements

SE 292 (3:0) High Performance Computing L2: Basic Computer Organization R. Govindarajan
Embedded Software 1. General 8051 features (excluding I/O) CPU 8 bit microcontroller The basic registers include (more discussed later) The 8-bit A (accumulator)
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling ARM assembler instructies  geindexeerde.
Chapter 4 The Von Neumann Model
Chapter 4 The Von Neumann Model
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2.
Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
Instruction execution and sequencing
Compiler Construction Sohail Aslam Lecture Code Generation  The code generation problem is the task of mapping intermediate code to machine code.
ARM versions ARM architecture has been extended over several versions.
CSC 3210 Computer Organization and Programming
Embedded Systems Programming
Appendix D The ARM Processor
Overheads for Computers as Components 2nd ed.
Suranaree University Of Technology มทส  2002 Anant Oonsivilai 2002/2/27 Microcomputers and Microprocessors Chapter Assembly Language Programming.
Chapter 3 โพรเซสเซอร์และการทำงาน The Processing Unit
The NS7520.
Wat gaan we doen? harhaling data types
Class Addressing modes
MIPS Assembly Tutorial
Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
F28PL1 Programming Languages Lecture 3: Assembly Language 2.
THUMB Instructions: Branching and Data Processing
Multiplication – Microprocessor
ITEC 352 Lecture 13 ISA(4).
Tutorial 2 IDE for ARM 7 board (2). Outline Introduce the Debug mode of uVision4 2.
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.
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:
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Lecture 3: Instruction Set Principles Kai Bu
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Load and store instruction.
Introduction to Embedded Systems Intel Xscale® Assembly Language and C Lecture #3.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
Execution of an instruction
Chapter 11-14, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3 Please return breadboards.
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
ARM programmer’s model and assembler Embedded Systems Programming.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
ARM 7 Datapath. Has “BIGEND” input bit, which defines whether the memory is big or little endian Modes: ARM7 supports six modes of operation: (1) User.
Part II: Addressing Modes
MIPS Instruction Set Advantages
Lecture 18 Last Lecture Today’s Topic Instruction formats
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Execution of an instruction
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
AT91 C-startup. 2 For reasons of modularity and portability most application code for an embedded application is written in C The application entry point.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Lecture 6: Branching CS 2011 Fall 2014, Dr. Rozier.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
Revision questions CENG2400 v.14b 1 CENG2400 Revision, Question 1 A system has an ARM processor with a 32-bit General Purpose Input Output (GPIO) module.
Writing Functions in Assembly
Instruction sets : Addressing modes and Formats
MIPS Instruction Set Advantages
Chapter 15: Higher Level Constructs
ECE 3430 – Intro to Microcomputer Systems
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
Writing Functions in Assembly
CENG2400 Revision Q1a A system has an ARM processor with a 32-bit General Purpose Input Output (GPIO) module. Two on/off switches are connected to bit-3.
Overheads for Computers as Components 2nd ed.
Multiply Instructions
Introduction to Assembly Chapter 2
Presentation transcript:

Chapter 4 Addressing modes CEG2400 Microcomputer Systems CEG2400 ch4 addressing modes v3a 1

Overview 1.Memory concept revision 2.Data Transfer Instructions - ADR instruction (Load Address into Register) 3.Register-indirect addressing using load (LDR) / store (STR) 4.Block copying CEG2400 ch4 addressing modes v3a 2

1)Memory concept Program code and data are saved in memory, They occupy different locations labels32-bit Address (HEX) 8-bit data Program/Data Org : TABLE B A B D2 : TABLE C : CEG2400 ch4 addressing modes v3a 3 Four 8-bit data form a 32-bit word Program See appendix For big/little endian formats

2) Data Transfer Instructions - ADR instruction (Load Address into Register) ADR r1, adress_label – It is a pseudo instruction – Details, see appendix for how it is actually implemented E.g. ADR r1, TABLE1 If TABLE1 is at H, then r1 = H after the instruction is run CEG2400 ch4 addressing modes v3a 4 copy ADR r1, TABLE1 ; r1 points to TABLE1 ……. TABLE1 …… ; …… TABLE2 …… ;

3) Register-indirect addressing using load (LDR) / store (STR) CEG2400 ch4 addressing modes v3a 5

Data Transfer Instructions - single register load/store instructions Use a value in one register (called the base register) as a memory address [ ] and either loads the data value from that address into a destination register or stores the register value to memory (mem 32 [r1] means: r1 holds the address, mem 32 [r1] =data content): LDRr0, [r1] ; r0 := mem 32 [r1] ;(content in r1 is an address ) STRr0, [r1] ; mem 32 [r1] := r0 This is called register-indirect addressing LDR r0, [r1] CEG2400 ch4 addressing modes v3a 6

Example : Data Transfer Instructions Use ADR (pseudo instruction) - looks like normal instruction, but it does not really exist. Instead the assembler translates it to one or more real instructions. CEG2400 ch4 addressing modes v3a 7 copyADRr1, TABLE1; r1 points to TABLE1 ADRr2, TABLE2; r2 points to TABLE2 LDRr0, [r1]; load first value …. STRr0, [r2]; and store it in TABLE2 ……. TABLE1……; …… TABLE2 ……;

Exercise 4.1 Fill in the shaded areas. Address (H)CommentsAfter instruction is run (hex) startAll registers are rest to 0 here (TABLE2) R0R1R copyADR r1,TABLE1;r1 points to TABLE1 ADR r2,TABLE2;r2 points to TABLE1 LDR r0, [r1];load first value STR r0, [r2];and store it in TABLE2 :: TABLE ; : TABLE ; CEG2400 ch4 addressing modes v3a 8

Block copy for two data: Data Transfer Instructions The following example copies data from TABLE 1 to TABLE2 (show how to copy two values) CEG2400 ch4 addressing modes v3a 9 copyADRr1, TABLE1; r1 points to TABLE1 ADRr2, TABLE2; r2 points to TABLE2 LDRr0, [r1]; load first value …. STRr0, [r2]; and store it in TABLE2 ADD r1, r1, #4; add 4 to r1 ADD r2, r2, #4 ; add 4 to r2 LDRr0, [r1]; load second value …. STRr0, [r2]; and store it in TABLE2 ….. TABLE1……; …… TABLE2 ……;

Exercise 2 --page1 Block copy for N=5 data : Data Transfer Instructions Copy N=5 data from TABLE 1 to TABLE2 CEG2400 ch4 addressing modes v3a copyADRr1, TABLE1; TABLE1= H 2.ADRr2, TABLE2; TABLE2= H 3.MOV r3,#0;setup counter at R3 4.loop1LDRr0, [r1]; load first value …. 5.STRr0, [r2]; and store it in TABLE2 6.ADD r1, r1, #4; add 4 to r1 7.ADD r2, r2, #4 ; add 4 to r2 8.ADD r3, r3, #1; increment counter 9.CMP r3,#5; repeat N=5 10.BNE loop1; loop back when N<5 ….. TABLE1……; …… TABLE2 ……;

Exercise 2 --page2, Fill in blacks (hex) for the loop after each time line 9 is executed After line 9 is runTime=1Time=2Time=3Time=4Time=5 R3 (Hex)=12345 R0 (Hex) A1 R1 (Hex) R2 (Hex)0004 Z (zero) of CPSR,Z=1 if result 0 else Z=0 0 Table 1, from H A B C D Table 2, from H A CEG2400 ch4 addressing modes v3a 11

4) Block copying: We will study these for block data copy CEG2400 ch4 addressing modes v3a 12 LDRr0, [r1]; register-indirect addressing LDRr0, [r1, # offset]; pre-indexed addressing LDRr0, [r1, # offset]!; pre-indexed, auto-indexing LDRr0, [r1], # offset; post-indexed, auto-indexing

Use of pre-indexed addressing mode LDR r0, [r1, #offset] Base plus offset addressing pre-indexed addressing mode LDRr0, [r1, #4]; r0 := mem 32 [r1 + 4] R1 Unchanged CEG2400 ch4 addressing modes v3a 13 base address offset effective address r1 will not be changed by pre-indexed addressing instructions LDRr0, [r1, #4]; r0 : = mem 32 [r1 + 4]

Pre-indexed addressing, LDRr0, [r1, #offset] Copy and copy2 (shown below) have the same effect CEG2400 ch4 addressing modes v3a 14 Simple method Better method copyADRr1, TABLE1; r1 points to TABLE1 ADRr2, TABLE2; r2 points to TABLE2 LDRr0, [r1]; load first value …. STRr0, [r2]; and store it in TABLE2 ADDr1, r1, #4; step r1 onto next word ADDr2, r2, #4; step r2 onto next word LDRr0, [r1]; load second value … STRr0, [r2]; and store it copy2ADRr1, TABLE1; r1 points to TABLE1 ADRr2, TABLE2; r2 points to TABLE2 LDRr0, [r1]; load first value …. STRr0, [r2]; and store it in TABLE2 LDRr0, [r1, #4]; load second value … STRr0, [r2, #4]; and store it

Pre-indexed with auto addressing mode LDRr0, [r1, #offset]! pre-indexed auto addressing mode, using (!), changes the pointer reg. (e.g. r1 here ) after used. LDRr0, [r1, #4]!; r0 := mem 32 [r1 + 4] R1 = R1+offset=R1+#4 CEG2400 ch4 addressing modes v3a 15 base address offset effective address R1 will be changed by pre-indexed addressing instructions LDRr0, [r1, #4]!; r0 : = mem 32 [r1 + 4] ; r1 := r1 + 4

Exercise 4.3 After Line r0r1r A123 B CEG2400 ch4 addressing modes v3a 16 1.Copy ADRr1, TABLE1; TABLE1= ADRr2, TABLE2; TABLE2= LDRr0, [r1]; load first value …. 4.STRr0, [r2]; and store it inTABLE2 5.LDRr0, [r1, #4]; load second value 6. STR r0, [r2, #4]; and store it LDR r0, [r1, #4]! ; r0 : = mem 32 [r1 + 4] ; r1 := r1 + 4 LDR r0, [r1, #4] ; r0 : = mem 32 [r1 + 4] (all in hex) R1,R2 will NOT be changed by pre-indexed addressing instructions

Exercise 4.4 After line r0r1r A123 B CEG2400 ch4 addressing modes v3a 17 (all in hex) r1,r2 will be changed by pre-indexed addressing instructions 1.Copy ADRr1, TABLE1; TABLE1= ADRr2, TABLE2; TABLE2= LDRr0, [r1]; load first value …. 4.STRr0, [r2]; and store it inTABLE2 5.LDRr0, [r1, #4]!; load second value,R1 will change 6. STR r0, [r2, #4]!; and store it, R2 will change too LDR r0, [r1, #4] ; r0 : = mem 32 [r1 + 4] LDR r0, [r1, #4]! ; r0 : = mem 32 [r1 + 4] ; r1 := r1 + 4

Data Transfer Instructions - post-indexed addressing Another useful form of the instruction is: This is called: post-indexed addressing - the base address is used without an offset as the transfer address, after which it is auto- indexed:(r1=r1+4) Using this, we can improve the copy program: CEG2400 ch4 addressing modes v3a 18 LDRr0, [r1], #4; r0 : = mem 32 [r1] ; then r1 := r1 + 4 copyADRr1, TABLE1; r1 points to TABLE1 ADRr2, TABLE2; r2 points to TABLE2 loopLDRr0, [r1], #4; get TABLE1 1st word …. STRr0, [r2], #4; copy it to TABLE2 ???; if more, go back to loop …… TABLE1……;

Summary :Data Transfer Instructions (LDR-- >LDRB) Size of data can be reduced to 8-bit byte with: Summary of addressing modes: CEG2400 ch4 addressing modes v3a 19 LDRr0, [r1]; register-indirect addressing LDRr0, [r1, # offset]; pre-indexed addressing LDRr0, [r1, # offset]!; pre-indexed, auto-indexing LDRr0, [r1], # offset; post-indexed, auto-indexing ADRr0, address_label; PC relative addressing LDRBr0, [r1]; r0 : = mem 8 [r1]

Self study programming exercise:;ex4_2400 ch4 of CENG2400. It is for your own revision purpose, no need to submit answers to tutors. ; eng2400/ex4_2400_qst.txt; 1) create a project based on this.s code ;2) In keil-ide, use project/rebuild all target files to build the project ;3) use Debug/run_to_cursor_line to run the top line of the program, ;4) use the single step mode to view the memory locations (in DEbug mode/view/memory_wndows)from 0x to 0x , registers and cpsr after the execution of each statement. ;5) Explain the observations and results. ; declare variables New test12D AREA|.data|, DATA, READWRITE Table1 DCD 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,0x1, 0x1 Table2 DCD 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,0x1, 0x1 align ; ; User Initial Stack & Heap AREA |.text|, CODE, READONLY EXPORT __main __main ;clear flags memory_init ; set the memory content in table1 LDR r1, =Table1 LDR r2, =Table2 MOV r3,#0 MOV r0,#0x00 loopADD r0,r0,#0x11 STR r0,[r1] ADD r1,r1,#4 ADD r3,r3,#1 CMP r3,#10 BNE loop NOP ex4_1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BL memory_reset LDR r1,=Table1 LDR r2,=Table2 LDR r0, [r1] STR r0, [r2] NOP CEG2400 ch4 addressing modes v3a 20

Self study exercises (continue) ex4_2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BL memory_reset LDR r1,=Table1 LDR r2,=Table2 MOV r3, #0 loop1 LDR r0,[r1] STR r0,[r2] ADD r1,r1,#4 ADD r2,r2,#4 ADD r3,r3,#1 CMP r3,#5 BNE loop1 NOP ex4_3;;;;;;;; BL memory_reset LDR r1,=Table1 LDR r2,=Table2 LDR r0,[r1] STR r0,[r2] LDR r0,[r1,#4] STR r0,[r2,#4] NOP ex4_4;;;;;;;; BL memory_reset LDR r1,=Table1 LDR r2,=Table2 LDR r0,[r1] STR r0,[r2] LDR r0,[r1,#4]! STR r0,[r2,#4]! NOP memory_reset ; reset the content in ; table2 to be all 0 LDR r5,=Table2 MOV r6,#0 MOV r7,#0 loop2STR r6,[r5] ADD r5,r5,#4 ADD r7,r7,#1 CMP r7,#10 BNE loop2 BX LR END CEG2400 ch4 addressing modes v3a 21

Summary Learned the addressing modes of the Arm processor CEG2400 ch4 addressing modes v3a 22

Appendices CEG2400 ch4 addressing modes v3a 23

Appendix 1: MOV MOV : Move MOV, dest = op_1 MOV loads a value into the destination register, from another register, a shifted register, or an immediate value. You can specify the same register for the effect of a NOP instruction, or you can shift the same register if you choose: MOV R0, R0 ; R0 = R0... NOP instruction MOV R0, R0, LSL#3 ; R0 = R0 * 8 If R15 is the destination, the program counter or flags can be modified. This is used to return to calling code, by moving the contents of the link register into R15: MOV PC, R14 ; Exit to caller MOVS PC, R14 ; Exit to caller preserving flags (not 32-bit compliant) CEG2400 ch4 addressing modes v3a 24

Appendix2: Data Transfer Instructions - ADR instruction How does the ADR instruction work? Address is 32-bit, difficult to put a 32- bit address value + opcode in a register in the first place Solution: Program Counter PC (r15) is often close to the desired data address value ADR r1, TABLE1 is translated into an instruction that adds or subtracts a constant to PC (r15), and puts the results in r1 This constant is known as PC-relative offset, and it is calculated as: addr_of_table1 - (PC_value + 8) Address opcode 00008FE4 E28F0004 ADR R0, table1 ; pseudo instruction ; now pc=r15= 00008FE4 Real instruction 00008FE4 E28F0004 ADD R0, R15, #4 ;real code 00008FF0.table FF0 EQUS Hello world !" CEG2400 ch4 addressing modes v3a 25 By programmer

The use of the pseudo instruction ADR Address opcode 00008FE4 E28F0004 ADR R0, table1 ; pseudo instruction ; now pc=r15= 00008FE4 Real instruction (generated by the assembler) 00008FE4 E28F0004 ADD R0, R15, #4 ;real code 00008FF0.table 00008FF0 EQUS Hello world !" ---Explanation--- The location you want to enter into R0 is.text= 00008FF0, which is the beginning of a string table. But you cannot place a 32-adress and some opcode into 32-bit Because ARM designers want to maintain each instruction is 32-bit long Put location – (PC+8)= 00008FF0-(00008FE4+8)=# 4 instead Note: # n =the actual number n (not an address) CEG2400 ch4 addressing modes v3a 26 You write

End CEG2400 ch4 addressing modes v3a 27

Appendix Big and little endian CEG2400 ch4 addressing modes v3a 28