April 2006 Saeid Nooshabadi

Slides:



Advertisements
Similar presentations
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.
Advertisements

The University of Adelaide, School of Computer Science
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.
Introduction to Embedded Systems Intel Xscale® Assembly Language and C Lecture #3.
COMP3221 lec18-pointers.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 18 : Pointers & Arrays in C/ Assembly
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
Divisor máximo de dois inteiros. unsigned int gcd(unsigned int A, unsigned int B) { if (B > A) return gcd(B,A); else if (B==0) return A; else return gcd(B,A%B);}
MIPS Function Continued
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
COMP3211 lec22-fraction.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 22 : Fractions September,
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
Intro to Computer Architecture
COMP3221 lec18-function-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 17 : Functions in C/ Assembly - III
COMP3221 lec15-function-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 6 : Functions in C/ Assembly - I
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
ELEC2041 lec18-pointers.1 Saeid Nooshabadi COMP3221/9221 Microprocessors and Interfacing Lectures 7 : Pointers & Arrays in C/ Assembly
Recursion!. Can a method call another method? YES.
COMP3221 lec15-function-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 15 : Functions in C/ Assembly - I
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.
L12-Computing Factorial
MIPS function continued. Recursive functions So far, we have seen how to write – A simple function – A simple function that have to use the stack to save.
CS 2130 Lecture 27 Functional Optimizations. Just the factorial... (define fact (lambda (n) (if (= 0 n) 1 (* n (fact (- n 1))) ) (define fact (lambda...))
5. Assembly Language. Basics of AL Program data Pseudo-ops Array Program structures Data, stack, code segments.
Computer Architecture CSE 3322 Lecture 4 crystal.uta.edu/~jpatters/cse3322 Assignments due 9/15: 3.7, 3.9, 3.11.
1 Chapter 4 ARM Assembly Language Smruti Ranjan Sarangi Computer Organisation and Architecture PowerPoint Slides PROPRIETARY MATERIAL. © 2014 The McGraw-Hill.
ARM Assembly Programming II Computer Organization and Assembly Languages Yung-Yu Chuang 2007/11/26 with slides by Peng-Sheng Chen.
Languages.ppt Programming Language Usage Stand-A-Lone Runs on a Mainframe, Server, or PC and does not interface outside of the immediate domain Program.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic4: Procedures José Nelson Amaral.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
F28HS Hardware-Software Interface Lecture 11: ARM Assembly Language 5.
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.
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.
Smruti Ranjan Sarangi, IIT Delhi Chapter 4 ARM Assembly Language
Lecture 5: Procedure Calls
April 2006 Saeid Nooshabadi
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 24: Compiler, Assembler, Linker and Loader – I
Procedures (Functions)
Procedures (Functions)
March 2006 Saeid Nooshabadi
April 2006 Saeid Nooshabadi
CSCI206 - Computer Organization & Programming
What's wrong with this procedure?
ARM Assembly Programming
Passing by-value vs. by-reference in ARM
Microprocessor and Assembly Language
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
Optimizing ARM Assembly
ELEC Microprocessors and Interfacing Lectures 22: Fractions May 2006
March 2006 Saeid Nooshabadi
March 2006 Saeid Nooshabadi
Systems Architecture I
MIPS function continued
CS-401 Computer Architecture & Assembly Language Programming
Branch instructions Branch : B{<cond>} label
April 2006 Saeid Nooshabadi
Main() { int fact; fact = Factorial(4); } main fact.
EECE.3170 Microprocessor Systems Design I
MIPS function continued
An Introduction to the ARM CORTEX M0+ Instructions
Procedures and Macros.
Presentation transcript:

April 2006 Saeid Nooshabadi saeid@unsw.edu.au ELEC2041 Microprocessors and Interfacing Lectures 17: Functions in C/ Assembly - III - Extra http://webct.edtec.unsw.edu.au/ April 2006 Saeid Nooshabadi saeid@unsw.edu.au

Factorial in ARM and C fact: stmfd sp!, {v1,lr} sub fp, ip, #4 body: mov v1, a1 ; copy of n for mul cmp v1, #1 ; n==1 sub a1, a1, #1 ; n -1 for fact(n-1) mov a2, v1 ; return value if n=1 beq fin ; return bl fact ; recursion with n-1 mul a2, a1, v1 ; n*fact(n-1) fin: mov a1, a2 ; return 1 or n*fact(n-1) ldmfd sp!, {v1,pc} unsigned int fact(unsigned int n) {if (n == 1)return 1; else return n*fact(n-1); }

Stack Growth and Shrinkage (#1/2) sp fact(3) sp lr v1 fact(2) sp v1 lr fact(1) sp v1 lr unsigned int fact(unsigned int n) {if (n == 1)return 1; else return n*fact(n-1); }

Stack Growth and Shrinkage (#2/2) sp 6 fact(3) sp lr v1 2 fact(2) sp v1 lr 1 fact(1) sp v1 lr unsigned int fact(unsigned int n) {if (n == 1)return 1; else return n*fact(n-1); }