Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  Herhaling ARM assembler instructies.

Slides:



Advertisements
Similar presentations
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  LCD aansturen  een scrollende text laten zien.
Advertisements

Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling ARM assembler instructies  geindexeerde.
Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag functie definitions;.h files;
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2.
Onderwerpen voor vandaag
ARM versions ARM architecture has been extended over several versions.
Wat gaan we doen? harhaling data types
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.
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Optimizing ARM Assembly Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Peng-Sheng Chen.
Lab III Real-Time Embedded Operating System for a SoC System.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
Introduction to Embedded Systems Intel Xscale® Assembly Language and C Lecture #3.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  pak het project tint.zip.
VPEMSY1, D3ECPT2 : ARM Assembler Hogeschool Utrecht / Electrical Engineering & Design 1  Herhaling B/BL, conditions,
Subroutines reasons for subroutines −repeat same code, or similar code with slightly different parameters −hide design decisions or design complexity −partition.
Multiple data transfer instructions ARM also supports multiple loads and stores: ldm/ldmia/ldmfd: load multiple registers starting from [base register],
S. Barua – CPSC 240 CHAPTER 10 THE STACK Stack - A LIFO (last-in first-out) storage structure. The.
EECC250 - Shaaban #1 Lec # 5 Winter Stacks A stack is a First In Last Out (FILO) buffer containing a number of data items usually implemented.
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
COMP3221 lec18-function-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 17 : Functions in C/ Assembly - III
Chapters 9 & 10 Midterm next Wednesday (11/19) Trap Routines & RET Subroutines (or Functions) & JSR & JSRR & RET The Stack SSP & USP Interrupts RTI.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
Subroutines and Stacks 1. Subroutines Separate, independent module of program, performs a specific task shortens code, provide reusable “tools” High-level.
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Lecture 4. ARM Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University ECM586 Special Topics in Embedded Systems.
Topic 9: Procedures CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Computer Architecture Lecture 13 – part 1 by Engineer A. Lecturer Aymen Hasan AlAwady 31/3/2014 University of Kufa - Information Technology Research and.
1 Chapter 4 ARM Assembly Language Smruti Ranjan Sarangi Computer Organisation and Architecture PowerPoint Slides PROPRIETARY MATERIAL. © 2014 The McGraw-Hill.
Arrays and Strings in Assembly
Lecture 6: Branching CS 2011 Fall 2014, Dr. Rozier.
MIPS Subroutines Subroutine Call – jal subname Saves RA in $31 and jumps to subroutine entry label subname Subroutine Return – jr $31 Loads PC with return.
Lecture 8: Loading and Storing to Memory CS 2011 Fall 2014, Dr. Rozier.
CPS 4150 Computer Organization Chapter 2-2 Fall 2006 Ching-Song Don Wei.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
The Stack. ARMSim memory space: 0x Unused 0x x11400 Stack 0x x09400 Heap 0x?????-0x01400 Data 0x x????? Text 0x x01000.
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.
Subroutines reasons for subroutines −repeat same code, or similar code with slightly different parameters −hide design decisions or design complexity −partition.
Multiple data transfer instructions ARM also supports multiple loads and stores: When the data to be copied to the stack is known to be a multiple of 4.
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.
Writing Functions in Assembly
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
PROGRAMMING OF 8085 PROCESSOR
ECE 3430 – Intro to Microcomputer Systems
The Stack.
Introduction to the ARM Instruction Set
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
The Stack.
Lab 3 - Branching & Subroutines
Subroutines and the Stack
Writing Functions in Assembly
The Stack.
ARM Assembly Programming
Programming 8086 – Part IV Stacks, Macros
Chapter 5: ARM Assembly Directives and the use of stack
Passing by-value vs. by-reference in ARM
Subroutines and the Stack
The University of Adelaide, School of Computer Science
ARM Load/Store Instructions
EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR
Debugging with printf you can call printf from an ARM assembly language program some of the details will be explained later, but for now use this skeleton.
ECE 3430 – Intro to Microcomputer Systems
Optimizing ARM Assembly
Branch instructions Branch : B{<cond>} label
Subroutines and the Stack
Some Assembly (Part 2) set.html.
ECE511: Digital System & Microprocessor
An Introduction to the ARM CORTEX M0+ Instructions
Implementing Functions: Overview
Presentation transcript:

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  Herhaling ARM assembler instructies  Branch instructie  Subroutines, gebruik van de stack  Conditionele instructies en de flags  Oefening

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 2 LDR R0, =value R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers ……. FFFF FFFB FFFF FFFC FFFF FFFD FFFF FFFE FFFF geheugen

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 3 MOV R0, R1 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers ……. FFFF FFFB FFFF FFFC FFFF FFFD FFFF FFFE FFFF geheugen

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 4 LDR R0, [ R1 ] R0 R R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers ……. FFFF FFFB FFFF FFFC FFFF FFFD FFFF FFFE FFFF geheugen

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 5 STR R0, [ R1 ] R0 R1FFFF FFFC R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers ……. FFFF FFFB FFFF FFFC FFFF FFFD FFFF FFFE FFFF geheugen

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 6 ADD R3, R1, R2 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers ……. FFFF FFFB FFFF FFFC FFFF FFFD FFFF FFFE FFFF geheugen +

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 7 Drie getallen optellen.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word main: ldr r0, =0 ldr r1, =getal_1 ldr r2, [ r1 ] addr0, r0, r2 ldr r1, =getal_2 ldr r2, [ r1 ] addr0, r0, r2 ldr r1, =getal_3 ldr r2, [ r1 ] add r0, r0, r2 ldr r1, =som str r0, [ r1] done: b done

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 8 B = branch R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers ……. FFFF FFFB FFFF FFFC FFFF FFFD FFFF FFFE FFFF geheugen

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 9 BL = branch and link R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers ……. FFFF FFFB FFFF FFFC FFFF FFFD FFFF FFFE FFFF geheugen

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 10 Hoofdprogramma. Call sub. Call sub. Een subroutine aanroepen Sub:. return

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 11 Hoofdprogramma. call sub. call sub. Een subroutine aanroepen Sub:. return

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 12 Hoofdprogramma. BL SUB. BL SUB. ARM subroutine mechanisme SUB:. MOV PC, LR R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers BL label

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 13 Een subroutine gebruiken (1).global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word add: ldr r2, [ r1 ] addr0, r0, r2 movPC, LR main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =getal_2 bladd ldr r1, =getal_3 bladd ldr r1, =som str r0, [ r1] done: b done

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 14 Een subroutine gebruiken (2).global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word add: ldr r2, [ r1 ] add r1, r1, #4 addr0, r0, r2 movPC, LR main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =som str r0, [ r1] done: b done add: ldr r2, [ r1 ] addr0, r0, r2 movPC, LR main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =getal_2 bladd ldr r1, =getal_3 bladd ldr r1, =som

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 15 Een subroutine roept een andere subroutine aan. Wat gaat hier mis?.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word add_r0_r2: add r0, r0, r2 movPC, LR add: ldr r2, [ r1 ] BLadd_r0_r2 add r1, r1, #4 movpc, lr main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =som str r0, [ r1] …..

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 16 Stack A stack is an area of memory which grows as new data is “pushed” onto the “top” of it, and shrinks as data is “popped” off the top. stack pointer used to point the current “top” of the stack. empty ascending / empty decending / full ascending / full decenuing SP PUSH {1,2,3} POP 1 2 Result of pop = 3 SP

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 17 assembler instructie formaat : multiple words van en naar geheugen (block transfer instructies) STMFD SP!, { R1-R9, R12 } LDMFD SP!, { R1-R9, R12 }

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 18 Gebruik de stack subroutine: stmfdsp!, { r2, r3, r4, lr } … ldmfdsp!, { pc, r2-r4 }

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 19 Gebruik de stack.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word add_r0_r2: stmfdsp!, { lr } add r0, r0, r2 ldmfdsp!, { pc } add1: stmfdsp!, { r2, lr } ldr r2, [ r1 ] bladd_r0_r2 add r1, r1, #4 ldmfdsp!, { r2, pc } main: ldr r0, =0 ldr r1, =getal_1 bladdl ldr r1, =som str r0, [ r1] ….. add_r0_r2: add r0, r0, r2 movPC, LR add1: ldr r2, [ r1 ] BLadd_r0_r2 add r1, r1, #4 movpc, lr

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 20 ARM instructie set iedere instructie is conditioneel Bijna alle instructies kunnen de conditie flags zetten ”de conditie” is de uitkomst van de laatste rekeninstructie die de flags heeft gezet (S achtervoegsel)

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 21 The ARM condition code field All instructions are conditionally executed!

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 22 Conditions

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 23 Zet de flags of laat ze ongewijzigd Gewoon een S (= Set Condition Codes) achter de instructie ADDSr0, r1, zet de flags ADCr3, r4, laat de flags ongewijzig (carry!)

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 24 2 getallen R0 == a, R1 == b, R2 == n subs r3, r0, r1 bne niet_verhogen add r2, r2, #1 niet_verhogen: if ( a == b ){ n++; R0 == a, R1 == b, R2 == n subs r3, r0, r1 addeq r2, r2, #1 niet_verhogen:

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 25 Drie getallen optellen in een loop.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 0 main: ldr r0, initialisatie loop body subs r2, r2, #1 bneloop ldr r1, =som str r0, [ r1] done: b done Hier zelf code toevoegen

Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 26 Opdrachten: 1. Maak zelf het ‘loop’ optel programma af en test het. 2. maak een programma dat 2 getallen vermenigvuldigt (door herhaald optellen). Het is misschien handig eerst in C te schrijven hoe je dit zou doen.