Passing by-value vs. by-reference in ARM

Slides:



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

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.
COMP3221 lec16-function-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 16 : Functions in C/ Assembly - II
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.
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.
Assembler Parameter Passing Exercises. Assembler Exercise 1: Convert the following C++ code to H1 assembler. int foo(int a, char ch = ‘a’) { if ch ==
Subroutines reasons for subroutines −repeat same code, or similar code with slightly different parameters −hide design decisions or design complexity −partition.
F28PL1 Programming Languages Lecture 5: Assembly Language 4.
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.
ELEC2041 lec18-pointers.1 Saeid Nooshabadi COMP3221/9221 Microprocessors and Interfacing Lectures 7 : Pointers & Arrays in C/ Assembly
ARM C Language & Assembler. Using C instead of Java (or Python, or your other favorite language)? C is the de facto standard for embedded systems because.
Program.-(4)* Write a program for input two integer number with message and display their sum. Algorithm steps Algorithm steps 1.Display message for input.
Cortex-M3 Programming. Chapter 10 in the reference book.
Separate Assembly allows a program to be built from modules rather than a single source file.
FUNCTION – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
1 Program Layout in memory –Code –Data Global variables –Stack Local variables & function Invocation Frames –Heap Dynamically allocated memory Today’s.
Topic 9: Procedures CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Memory/Storage Architecture Lab 컴퓨터의 개념과 실습 Assembly Example.
F28PL1 Programming Languages Lecture 4: Assembly Language 3.
ARM Assembly Programming II Computer Organization and Assembly Languages Yung-Yu Chuang 2007/11/26 with slides by Peng-Sheng Chen.
Arrays and Strings in Assembly
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 3: Toolchain, ABI, Memory Mapped I/O January 14 th, 2016 Slides.
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.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Review, Simulation, ABI, and Memory-Mapped I/O September.
Improvements to the Compiler Lecture 27 Mon, Apr 26, 2004.
The Stack. ARMSim memory space: 0x Unused 0x x11400 Stack 0x x09400 Heap 0x?????-0x01400 Data 0x x????? Text 0x x01000.
Practical Session 8. Position Independent Code- self sufficiency of combining program Position Independent Code (PIC) program has everything it needs.
F28HS Hardware-Software Interface Lecture 11: ARM Assembly Language 5.
Arrays In high-level languages, we have several technigues available for constucting data stuctures: −One-dimensional arrays −Multi-dimensional arrays.
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.
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.
Chapter 14 Functions.
Writing Functions in Assembly
ECE 3430 – Intro to Microcomputer Systems
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
The Stack.
Exploiting & Defense Day 2 Recap
Lab 3 - Branching & Subroutines
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
April 2006 Saeid Nooshabadi
Writing Functions in Assembly
Slides developed in part by Prof. Dutta
Computer Architecture and Assembly Language
ARM Assembly Programming
Int add3 (int a, int b, int c) { return a + b + c; } int sum = 0; main () sum += add3 (1, 2, 3); sum += 10; sum += add3 (10, 20, 30);
Stack Frame Linkage.
Multiple Entry Points Multiple entry points allow different function names, different parameter lists, default parameters, etc. Example int fn( int a =
Scope (visibility) scope in C is simple:
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
April 2006 Saeid Nooshabadi
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Introduction to Assembly Chapter 2
Computer Architecture and System Programming Laboratory
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Implementing Functions: Overview
Presentation transcript:

Passing by-value vs. by-reference in ARM C code equivalent assembly code int a; .section ".bss" @ .bss since a is not assigned an a: .skip 4 @ initial value; alloc 4 bytes .section ".text" int subr(int); .global main int main(void) main: { push {r4, lr} a = 0; ldr r4, =a @ a = 0 a = subr( a ); mov r2, #0 return 0; str r2, [r4] @ } ldr r0, [r4] @ call subr( a ); pass “a” by value bl subr str r0, [r4] @ a = return value from subr in r0 mov r0, #0 @ return value 0 put in r0 pop {r4, lr} bx lr @ put lr in pc

Passing by-value vs. by-reference in ARM C code equivalent assembly code int sub( int x ) subr: add r0, r0, #1 @ return value = x + 1 { bx lr return( x + 1 ); }

Passing by-value vs. by-reference in ARM C code equivalent assembly code int a; .section ".bss" @ .bss since a is not assigned an a: .skip 4 @ initial value; alloc 4 bytes .section ".text" int subr(int *); .global main int main(void) main: { push {r4, lr} a = 0; ldr r4, =a @ a = 0 a = subr( &a ); mov r2, #0 return 0; str r2, [r4] @ ldr r0, r4 @ call subr( a ); pass “a” by ref bl subr str r0, [r4] @ a = return value from subr in r0 mov r0, #0 @ return value 0 put in r0 pop {r4, lr} bx lr @ put lr in pc

Passing by-value vs. by-reference in ARM C code equivalent assembly code int sub( int *x ) subr: { ldr r1, [r0] @deref parameter return(*x + 1); add r0, r1, #1 @return val in r0 } bx lr