EECE.3170 Microprocessor Systems Design I

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
Advertisements

Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
COMP 2003: Assembly Language and Digital Logic
Computer Architecture CSCE 350
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
Assembly Language for Intel-Based Computers Chapter 8: Advanced Procedures Kip R. Irvine.
University of Washington Last Time For loops  for loop → while loop → do-while loop → goto version  for loop → while loop → goto “jump to middle” version.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Accessing parameters from the stack and calling functions.
– 1 – , F’02 ICS05 Instructor: Peter A. Dinda TA: Bin Lin Recitation 4.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
Microprocessor Systems Design I
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2014 Lecture 4: x86 memory.
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Fabián E. Bustamante, Spring 2007 Machine-Level Programming III - Procedures Today IA32 stack discipline Register saving conventions Creating pointers.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Recitation 2: Outline Assembly programming Using gdb L2 practice stuff Minglong Shao Office hours: Thursdays 5-6PM Wean Hall.
Today’s topics Procedures Procedures Passing values to/from procedures Passing values to/from procedures Saving registers Saving registers Documenting.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
Compiler Construction Code Generation Activation Records
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Assembly Language Addressing Modes. Introduction CISC processors usually supports more addressing modes than RISC processors. –RISC processors use the.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Lecture 15 Advanced Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Recitation 3: Procedures and the Stack
Stack Operations Dr. Hadi AL Saadi.
Reading Condition Codes (Cont.)
Microprocessor Systems Design I
C function call conventions and the stack
Microprocessor Systems Design I
Microprocessor Systems Design I
Chapter 12 Variables and Operators
Microprocessor Systems Design I
143A: Principles of Operating Systems Lecture 4: Calling conventions
Exploiting & Defense Day 2 Recap
16.317: Microprocessor System Design I
Microprocessor Systems Design I
Microprocessor and Assembly Language
Introduction to Compilers Tim Teitelbaum
Assembly IA-32.
CS 301 Fall 2002 Control Structures
Computer Architecture and Assembly Language
Machine-Level Programming 4 Procedures
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Stack Frames and Advanced Procedures
Machine-Level Programming III: Procedures Sept 18, 2001
The University of Adelaide, School of Computer Science
EECE.3170 Microprocessor Systems Design I
Practical Session 4.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.2160 ECE Application Programming
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
CSC 497/583 Advanced Topics in Computer Security
Computer Organization and Assembly Language
EECE.3170 Microprocessor Systems Design I
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

EECE.3170 Microprocessor Systems Design I Instructor: Dr. Michael Geiger Summer 2016 Lecture 8 HLL  assembly (continued)

Microprocessors I: Lecture 8 Lecture outline Announcements/reminders HW 3 due 1:00 PM today HW 4 to be posted; due 1:00 PM Thursday, 6/9 Exam 2: Monday, 6/13 Will again be allowed one 8.5” x 11” note sheet, calculator Instruction list provided Review: Subroutines HLL  assembly Static data Stack usage with function calls Today’s lecture Conditional statements Loops HLL  assembly examples 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Review: subroutines Subroutines: low-level functions When called, address of next instruction saved Return instruction ends routine; goes to that point May need to save state on stack x86 specifics CALL <proc>: call procedure <proc> typically label Saves address of next instruction to stack RET: return from procedure Saving state to stack: push instructions Store data “above” current TOS; decrement SP Basic PUSH stores word or double word Directly storing flags: PUSHF Storing all 16-/32-bit general purpose registers: PUSHA/PUSHAD Restoring state: POP/POPF/POPA/POPAD 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Review: HLL  assembly Global variables  static; allocated in data segment Other variables  dynamic; allocated on stack Stack frame for each function contains (from top) Saved variables within function Local variables for function (starting at EBP – 4) Saved EBP Saved EIP Function arguments (starting at EBP + 8) 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Stack accesses On function call SP or ESP: points to current top of stack Lowest address in current stack frame BP or EBP: used to reference data within frame Arguments Local variables 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Stack accesses (cont.) Arguments start at offset 8 from EBP Local variables start at offset -4 from EBP Starting offset of each variable can be defined as symbol Ex. (testfile1.asm) _j$ = -120; size = 4 _i$ = -108; size = 4 _Y$ = -96; size = 40 _X$ = -48; size = 40 mov DWORD PTR _i$[ebp], 0  sets i = 0 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Array accesses To access array element, need Base address of array Offset into array Offset = index * (size of each element) For example, X[2] is 2*4 = 8 bytes into array X In some ISAs, need to explicitly calculate this address Multiply index by element size Add to base address x86 uses scaled addressing  multiplication done in memory access Example: code for X[i] = i * 2 from testfile1: mov eax, DWORD PTR _i$[ebp] shl eax, 1 mov ecx, DWORD PTR _i$[ebp] mov DWORD PTR _X$[ebp+ecx*4], eax 1/2/2019 Microprocessors I: Lecture 8

Conditional statements If-then-else statements typically take form similar to: <code to evaluate condition> <conditional jump to else if false> <code if condition true> jmp end else: <code if condition false> end: … Always requires a conditional branch Must add label to branch to “else” statement Once statement for “if” condition is complete, jump past “else” statement Requires insertion of another label for jump target 1/2/2019 Microprocessors I: Lecture 8

Conditional statements (cont.) Body of inner loop: if (j < 5) Y[j] = X[i] + j; else Y[j] = X[i] – j; cmp DWORD PTR _j$[ebp], 5 jge SHORT $LN2@main mov eax, DWORD PTR _i$[ebp] mov ecx, DWORD PTR _X$[ebp+eax*4] add ecx, DWORD PTR _j$[ebp] mov edx, DWORD PTR _j$[ebp] mov DWORD PTR _Y$[ebp+edx*4], ecx jmp SHORT $LN1@main $LN2@main: sub ecx, DWORD PTR _j$[ebp] $LN1@main: 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Loops For loops are essentially three parts Initializing loop index Checking boundary condition Similar idea to if-then-else statements, but simpler If condition is false, end of loop Branch to label at first instruction after loop Usually done at start of loop, since no iterations should occur unless condition is true End of loop then contains jump back to beginning Incrementing loop index While loops only require the boundary condition check 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Loops (cont.) for (j = 0; j < 10; j++) {// inner loop mov DWORD PTR _j$[ebp], 0 jmp SHORT $LN5@main $LN4@main: mov eax, DWORD PTR _j$[ebp] add eax, 1 mov DWORD PTR _j$[ebp], eax $LN5@main: cmp DWORD PTR _j$[ebp], 10 jge SHORT $LN3@main ; jmp to end . . ; Loop body here jmp SHORT $LN4@main $LN3@main: 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Practice problems See today’s handout for Description of how stack frame should be created Description of where to access function arguments, local variables Functions to be written int fact(int n): Calculate and return n! int max(int v1, int v2): Return largest value between v1 and v2 void swap(int *a, int *b): Given addresses a & b, swap contents Solutions to be posted as PDF online C versions in slides that follow; assembly in PDF file Will be covered in class today as well 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Factorial in C int fact(int n) { int i; int fact = 1; for (i = n; i > 1; i--) fact *= i; return fact; } 1/2/2019 Microprocessors I: Lecture 8

Maximum value function in C int max(int v1, int v2) { if (v1 > v2) return v1; else return v2; } 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Swap in C void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } 1/2/2019 Microprocessors I: Lecture 8

Microprocessors I: Lecture 8 Final notes Next time: PIC introduction Begin PIC instruction set Reminders: HW 3 due 1:00 PM today HW 4 to be posted; due 1:00 PM Thursday, 6/9 Exam 2: Monday, 6/13 Will again be allowed one 8.5” x 11” note sheet, calculator Instruction list provided 1/2/2019 Microprocessors I: Lecture 8