Machine- Level Representa2on: Procedure
|
|
- Lorraine Harvey
- 5 years ago
- Views:
Transcription
1 Machine- Level Representa2on: Procedure CSCI 2021: Machine Architecture and Organiza2on Pen- Chung Yew Department Computer Science and Engineering University of Minnesota With Slides from Bryant, O Hallaron and Antonia Zhai
2 Review: Assembly/Machine Code View CPU (Central Processing Unit) PC Registers Condi2on Codes Addresses Data Instruc2ons Memory Code Data Stack Programmer- Visible State PC: Program counter %rip Address of next instruc2on Called %rip in x86-64 Register file Heavily used program data Condi2on codes Store status informa2on about most recent arithme?c or logical opera?on Used for condi?onal branching Memory Byte addressable array Code and user data Stack to support procedures CF ZF SF OF Condi2on Flags 2
3 Review: Jump and Condi2onal Move jx Condi2on Descrip2on jmp 1 Uncondi2onal je ZF Equal / Zero jne ~ZF Not Equal / Not Zero js SF Nega2ve jns ~SF Nonnega2ve jg ~(SF^OF)&~ZF Greater (Signed) jge ~(SF^OF) Greater or Equal (Signed) jl (SF^OF) Less (Signed) jle (SF^OF) ZF Less or Equal (Signed) ja ~CF&~ZF Above (unsigned) jb CF Below (unsigned) Condi2onal Move val = Test? Then_Expr : Else_Expr; val = x>y? x-y : y-x; 3
4 Review: Loops Do- While Loop do Body While Loop while (Test) Body while(test); For Loop for (Init; Test; Update ) Body
5 Review: Jump Table Structure Switch Form switch(x) { case val_0: Block 0 case val_1: Block 1 case val_n-1: Block n 1 Transla2on (Extended C) goto *JTab[x]; jtab: Jump Table Targ0 Targ1 Targ2 Targn-1 Targ0: Targ1: Targ2: Targn-1: Jump Targets Code Block 0 Code Block 1 Code Block 2 Code Block n 1
6 Outline Procedures Stack Structure Calling Conven2ons Passing control Passing data Managing local data Illustra2on of Recursion 6
7 Mechanisms in Procedures Passing control To beginning of procedure code Back to return point Passing data Procedure arguments Return value Memory management Allocate during procedure execu?on Deallocate upon return Mechanisms all implemented with machine instruc?ons x86-64 implementa?on of a procedure uses only those mechanisms required P( ) { y = Q(x); print(y) int Q(int i) { int t = 3*i; int v[10]; return v[t]; 7
8 Review: Assembly/Machine Code View CPU (Central Processing Unit) PC Registers Condi2on Codes Addresses Data Instruc2ons Memory Code Data Stack Programmer- Visible State PC: Program counter %rip Address of next instruc2on Called %rip in x86-64 Register file Heavily used program data Condi2on codes Store status informa2on about most recent arithme?c or logical opera?on Used for condi?onal branching Memory Byte addressable array Code and user data Stack to support procedures 8
9 x86-64 Stack Region of memory managed with stack discipline, i.e. last- in- first- out, or LIFO. Stack Bohom Registers Grows toward lower addresses Register %rsp contains lowest stack address address of top element Increasing Addresses %rax %rbx %r8 %r9 Stack Grows %rcx %rdx %r10 %r11 Stack Pointer: %rsp Down %rsi %rdi %r12 %r13 Stack Top %rsp %rbp %r14 %r15 9
10 x86-64 Stack: Push Stack Bohom pushq Src Fetch operand at Src Decrement %rsp by 8 Write operand at address given by %rsp Increasing Addresses Registers %rax %r8 %rbx %rcx %r9 %r10 Stack Grows %rdx %rsi %r11 %r12 Stack Pointer: %rsp - 8 Down %rdi %r13 %rsp %rbp %r14 %r15 Stack Top 10
11 x86-64 Stack: Pop popq Dest Read value at address given by %rsp Increment %rsp by 8 Store value at Dest (must be register) Registers Stack Bohom Increasing Addresses %rax %r8 %rbx %rcx %r9 %r10 Stack Grows %rdx %rsi %r11 %r12 Stack Pointer: %rsp +8 Down %rdi %rsp %r13 %r14 Stack Top %rbp %r15 11
12 Outline Procedures Stack Structure Calling Conven2ons Passing control Passing data Managing local data Illustra2on of Recursion 12
13 Code Examples void multstore (long x, long y, long *dest) { long t = mult2(x, y); *dest = t; long mult2 (long a, long b) { long s = a * b; return s; <multstore>: : push %rbx # Save %rbx : mov %rdx,%rbx # Save dest : callq <mult2> # mult2(x,y) : mov %rax,(%rbx) # Save at dest 40054c: pop %rbx # Restore %rbx 40054d: retq # Return <mult2>: : mov %rdi,%rax # a : imul %rsi,%rax # a * b : retq # Return
14 Procedure Control Flow Use stack to support procedure call and return Procedure call: call label Push return address on stack Jump to label Return address: Address of the next instruc?on right aser call Example from disassembly Procedure return: ret Pop address from stack Jump to address 14
15 Control Flow Example # <multstore>: : callq <mult2> : mov %rax,(%rbx) 0x130 0x128 0x <mult2>: : mov %rdi,%rax : retq %rsp %rip 0x120 0x
16 Control Flow Example # <multstore>: : callq <mult2> : mov %rax,(%rbx) <mult2>: : mov %rdi,%rax : retq 0x130 0x128 0x120 0x118 %rsp %rip 0x x118 0x
17 Control Flow Example # <multstore>: : callq <mult2> : mov %rax,(%rbx) <mult2>: : mov %rdi,%rax : retq 0x130 0x128 0x120 0x118 %rsp %rip 0x x118 0x
18 Control Flow Example # <multstore>: : callq <mult2> : mov %rax,(%rbx) <mult2>: : mov %rdi,%rax : retq 0x130 0x128 0x120 %rsp %rip 0x120 0x
19 Outline Procedures Stack Structure Calling Conven2ons Passing control Passing data Managing local data Illustra2ons of Recursion & Pointers 19
20 Procedure Data Flow Registers Stack Registers First 6 arguments %rdi 1 %rsi 2 Arg n %rax %rbx %r8 %r9 %rdx %rcx 3 4 %rcx %r10 %r8 5 Arg 8 %rdx %rsi %r11 %r12 %r9 6 Arg 7 %rdi %rsp %rbp %r13 %r14 %r15 Return value %rax Only allocate stack space when needed 20
21 Code Examples void multstore (long x, long y, long *dest) { long t = mult2(x, y); *dest = t; long mult2 (long a, long b) { long s = a * b; return s; <multstore>: : push %rbx # Save %rbx : mov %rdx,%rbx # Save dest : callq <mult2> # mult2(x,y) : mov %rax,(%rbx) # Save at dest 40054c: pop %rbx # Restore %rbx 40054d: retq # Return <mult2>: : mov %rdi,%rax # a : imul %rsi,%rax # a * b : retq # Return
22 Procedure Data Flow Registers Stack Registers First 6 arguments %rdi x %rsi y a b Arg n %rax %rbx %r8 %r9 %rdx %rcx dest %rcx %r10 %r8 Arg 8 %rdx %rsi %r11 %r12 %r9 Arg 7 %rdi %rsp %rbp %r13 %r14 %r15 Return value %rax Only allocate stack space when needed 22
23 Data Flow Examples void multstore (long x, long y, long *dest) { long t = mult2(x, y); *dest = t; long mult2 (long a, long b) { long s = a * b; return s; <multstore>: # x in %rdi, y in %rsi, dest in %rdx : mov %rdx,%rbx # Save dest : callq <mult2> # mult2(x,y) # t in %rax : mov %rax,(%rbx) # Save at dest %rdi %rsi %rdx %rcx %r8 x y *dest a b %r9 %rax <mult2>: # a in %rdi, b in %rsi : mov %rdi,%rax # a : imul %rsi,%rax # a * b # s in %rax : retq # Return
24 Outline Procedures Stack Structure Calling Conven2ons Passing control Passing data Managing local data Illustra2on of Recursion 24
25 Stack- Based Languages Languages that support recursion e.g., C, Pascal, Java Code must be Reentrant Mul?ple simultaneous instan?a?ons of single procedure Need some place to store state of each instan?a?on Arguments Local variables Return pointer Stack discipline State for given procedure needed for limited?me From when called to when return Callee returns before caller does Stack allocated in Frames State for single procedure instan?a?on 25
26 Call Chain Example yoo( ) { who(); who( ) { (); (); ( ) { (); Example Call Chain yoo who Procedure () is recursive 26
27 Stack Frames Carnegie Mellon Contents Return informa2on Local storage (if needed) Temporary space (if needed) Management Space allocated when enter procedure Set- up code Includes push by call instruc?on Deallocated when return Finish code Includes pop by ret instruc?on Frame Pointer: %rbp (Op2onal) x Stack Pointer: %rsp Previous Frame Frame for proc Stack Top 27
28 Example Stack yoo( ) { yoo who %rbp %rsp yoo yoo who(); 28
29 Example Stack yoo( ) { who( ) { who(); (); (); yoo who %rbp %rsp yoo yoo who 29
30 Example Stack yoo( ) { who( ) { ( ) { who(); (); (); (); yoo who %rbp %rsp yoo yoo who 30
31 Example Stack yoo( ) { who( ) { ( ) { who(); (); ( ) { (); (); (); yoo who %rbp %rsp yoo yoo who 31
32 Example Stack yoo( ) { who( ) { ( ) { who(); (); ( ) { ( ) (); (); { (); (); yoo who %rbp %rsp yoo yoo who 32
33 Example Stack yoo( ) { who( ) { ( ) { who(); (); ( ) { (); (); (); yoo who %rbp %rsp yoo yoo who 33
34 Example Stack yoo( ) { who( ) { ( ) { who(); (); (); (); yoo who %rbp %rsp yoo yoo who 34
35 Example Stack yoo( ) { who( ) { who(); (); (); yoo who %rbp %rsp yoo yoo who 35
36 Example Stack yoo( ) { who( ) { ( ) { who(); (); (); (); yoo who %rbp %rsp yoo yoo who 36
37 Example Stack yoo( ) { who( ) { who(); (); (); yoo who %rbp %rsp yoo yoo who 37
38 Example Stack yoo( ) { yoo who %rbp %rsp yoo yoo who(); 38
39 Outline Procedures Stack Structure (Last- in- First- out, LIFO) Calling Conven2ons Passing control Passing data Managing local data Illustra2on of Recursion 40
40 Review: Mechanisms in Procedures Passing control To beginning of procedure code Back to return point Passing data Procedure arguments Return value Memory management Allocate during procedure execu?on Deallocate upon return P( ) { y = Q(x); print(y) int Q(int i) { int t = 3*i; int v[10]; return v[t]; 41
41 Review: Procedure Passing Control Use stack to support procedure call and return (part of Applica2on Binary Interface, ABI) Procedure call: call label Push return address on stack Jump to label Return address: Address of the next instruc2on right aner call Procedure return: ret Pop return address from stack Jump to the return address 42
42 Review: Procedure Data Flow Registers Stack Registers First 6 arguments %rdi 1 %rsi 2 Arg n %rax %rbx %r8 %r9 %rdx %rcx 3 4 %rcx %r10 %r8 5 Arg 8 %rdx %rsi %r11 %r12 %r9 6 Arg 7 %rdi %rsp %rbp %r13 %r14 %r15 Return value %rax Only allocate stack space when needed 43
43 Review: Structure of Stack Need some place to store state of each instan?a?on Arguments Local variables Return pointer Stack discipline State for given procedure needed for limited?me From when called to when return Callee returns before caller does (LIFO) Stack allocated in Frames State for single procedure instan?a?on 45
44 x86-64/linux Stack Frame Current Stack Frame ( Top to Bohom) Argument build: Parameters for func?on about to call Local variables If can t keep in registers Saved register context Old frame pointer (op2onal) Caller Stack Frame (ABI Applica2on Binary Interface) Return address (Bottom) Frame pointer %rbp (Op2onal) Pushed by call instruc?on Arguments for this call Stack pointer (top) %rsp Caller Frame Arguments 7+ Return Addr Old %rbp Saved Registers + Local Variables Argument Build (Op2onal) Arg n Arg 8 Arg 7
45 Example: incr long incr(long *p, long val) { long x = *p; long y = x + val; *p = y; return x; %rdi %rsi %rdx %rcx %r8 %r incr: movq addq movq ret (%rdi), %rax %rax, %rsi %rsi, (%rdi) Register %rdi %rsi %rax Use(s) Argument p Argument val, y x, Return value 47
46 Example: Calling incr #1 long call_incr() { long v1 = 15213; long v2 = incr(&v1, 3000); return v1+v2; Ini2al Stack Structure... Rtn address %rsp call_incr: subq $16, %rsp movq movl leaq call addq addq ret $15213, 8(%rsp) $3000, %rsi 8(%rsp), %rdi incr 8(%rsp), %rax $16, %rsp Resul2ng Stack Structure... Rtn address %rsp+8 Unused %rsp 48
47 Example: Calling incr #2 long call_incr() { long v1 = 15213; call_incr: subq $16, %rsp movq movl leaq call addq addq ret long v2 = incr(&v1, 3000); return v1+v2; $15213, 8(%rsp) $3000, %rsi 8(%rsp), %rdi incr 8(%rsp), %rax $16, %rsp Stack Structure... Rtn address %rsp+8 Unused %rsp Register Use(s) %rdi &v1 %rsi
48 Example: Calling incr #3 long call_incr() { long v1 = 15213; call_incr: subq $16, %rsp movq movl leaq call addq addq ret long v2 = incr(&v1, 3000); return v1+v2; $15213, 8(%rsp) $3000, %rsi 8(%rsp), %rdi incr 8(%rsp), %rax $16, %rsp... Rtn address Unused Register %rdi Stack Structure Use(s) &v1 %rsi 3000 incr: movq addq movq ret %rsp+8 %rsp (%rdi), %rax %rax, %rsi %rsi, (%rdi)
49 Example: Calling incr #4 long call_incr() { long v1 = 15213; long v2 = incr(&v1, 3000); Rtn address return v1+v2; Unused Stack Structure %rsp+8 %rsp call_incr: subq $16, %rsp movq movl leaq call addq addq ret $15213, 8(%rsp) $3000, %rsi 8(%rsp), %rdi incr 8(%rsp), %rax $16, %rsp Register Use(s) %rax Return value Updated Stack Structure... Rtn address %rsp 51
50 Example: Calling incr #5 long call_incr() { long v1 = 15213; long v2 = incr(&v1, 3000); return v1+v2; Updated Stack Structure... Rtn address %rsp call_incr: subq $16, %rsp movq movl leaq call addq addq ret $15213, 8(%rsp) $3000, %rsi 8(%rsp), %rdi incr 8(%rsp), %rax $16, %rsp Register Use(s) %rax Return value Final Stack Structure... %rsp 52
51 Register Saving Conven2ons When procedure yoo calls who: yoo is the caller who is the callee Can register be used for temporary storage? yoo: movq $15213, %rdx call who addq %rdx, %rax ret who: subq $18213, %rdx ret Contents of register %rdx overwrizen by who This could be trouble something should be done! Need some coordina?on 53
52 Register Saving Conven2ons When procedure yoo calls who: yoo is the caller who is the callee Can register be used for temporary storage? Conven?ons (ABI Applica2on Binary Interface) Caller Saved Caller saves temporary values in its frame before the call Callee Saved Callee saves temporary values in its frame before using Callee restores them before returning to caller 54
53 x86-64 Linux Register Usage (Caller Saved) %rax Return value Also caller- saved Can be modified by procedure %rdi,..., %r9 Arguments Also caller- saved Can be modified by procedure %r10, %r11 Caller- saved Can be modified by procedure Return value Arguments Caller- saved temporaries %rax %rdi %rsi %rdx %rcx %r8 %r9 %r10 %r11 55
54 x86-64 Linux Register Usage (Callee Saved) Carnegie Mellon %rbx, %r12, %r13, %r14 Callee- saved Callee must save & restore %rbp Callee- saved Callee must save & restore May be used as frame pointer Can mix & match %rsp Special form of callee save Restored to original value upon exit from procedure Callee- saved Temporaries Special %rbx %r12 %r13 %r14 %rbp %rsp 56
55 x86-64 Integer Registers: Usage Conven2ons %rax Return value %r8 Argument #5 %rbx Callee saved %r9 Argument #6 %rcx Argument #4 %r10 Caller saved %rdx Argument #3 %r11 Caller Saved %rsi Argument #2 %r12 Callee saved %rdi Argument #1 %r13 Callee saved %rsp Stack pointer %r14 Callee saved %rbp Callee saved %r15 Callee saved 58
56 Callee- Saved Example #1 long call_incr2(long x) { long v1 = 15213; long v2 = incr(&v1, 3000); return x+v2; Rtn address %rsp... Ini2al Stack Structure call_incr2: pushq %rbx subq movq movq movl leaq call addq addq popq ret $16, %rsp %rdi, %rbx $15213, 8(%rsp) $3000, %esi 8(%rsp), %rdi incr %rbx, %rax $16, %rsp %rbx Resul2ng Stack Structure... Rtn address Saved %rbx %rsp+8 Unused %rsp 59
57 Callee- Saved Example #2 long call_incr2(long x) { long v1 = 15213; long v2 = incr(&v1, 3000); return x+v2;... Rtn address Resul2ng Stack Structure Saved %rbx call_incr2: pushq %rbx subq movq movq movl leaq call addq addq popq ret $16, %rsp %rdi, %rbx $15213, 8(%rsp) $3000, %esi 8(%rsp), %rdi incr %rbx, %rax $16, %rsp %rbx %rsp+8 Unused %rsp Pre- return Stack Structure... Rtn address %rsp 60
58 Outline Procedures Stack Structure Calling Conven2ons Passing control Passing data Managing local data Illustra2on of Recursion 61
59 Recursive Func2on /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) else return 0; return (x & 1) + pcount_r(x >> 1); pcount_r: movl testq je.l6 pushq movq andl shrq call addq.l6: popq rep; ret $0, %eax %rdi, %rdi %rbx %rdi, %rbx $1, %ebx %rdi pcount_r %rbx, %rax %rbx 62
60 Recursive Func2on Terminal Case /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) else return 0; return (x & 1) + pcount_r(x >> 1); Register Use(s) Type %rdi x Argument %rax Return value Return value pcount_r: movl testq je.l6 pushq movq andl shrq call addq.l6: popq rep; ret $0, %eax %rdi, %rdi %rbx %rdi, %rbx $1, %ebx %rdi pcount_r %rbx, %rax %rbx 63
61 Review: Jump jx Condi2on Descrip2on jmp 1 Uncondi2onal je ZF Equal / Zero jne ~ZF Not Equal / Not Zero js SF Nega2ve jns ~SF Nonnega2ve jg ~(SF^OF)&~ZF Greater (Signed) jge ~(SF^OF) Greater or Equal (Signed) jl (SF^OF) Less (Signed) jle (SF^OF) ZF Less or Equal (Signed) ja ~CF&~ZF Above (unsigned) jb CF Below (unsigned) 64
62 Recursive Func2on Register Save /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) else return 0; return (x & 1) + pcount_r(x >> 1); Register Use(s) Type %rdi x Argument pcount_r: movl testq je.l6 pushq movq andl shrq call addq.l6: popq rep; ret... $0, %eax %rdi, %rdi %rbx %rdi, %rbx $1, %ebx %rdi pcount_r %rbx, %rax %rbx Rtn address Saved %rbx %rsp
63 Recursive Func2on Call Setup /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) else return 0; return (x & 1) + pcount_r(x >> 1); Register Use(s) Type %rdi x >> 1 Rec. argument %rbx x & 1 Callee- saved pcount_r: movl testq je.l6 pushq movq andl shrq call addq.l6: popq rep; ret $0, %eax %rdi, %rdi %rbx %rdi, %rbx $1, %ebx %rdi pcount_r %rbx, %rax %rbx 66
64 Recursive Func2on Call /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) else return 0; return (x & 1) + pcount_r(x >> 1); Register Use(s) Type %rbx x & 1 Callee- saved %rax Recursive call return value pcount_r: movl testq je.l6 pushq movq andl shrq call addq.l6: popq rep; ret $0, %eax %rdi, %rdi %rbx %rdi, %rbx $1, %ebx %rdi pcount_r %rbx, %rax %rbx 67
65 Recursive Func2on Result /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) else return 0; return (x & 1) + pcount_r(x >> 1); Register Use(s) Type %rbx x & 1 Callee- saved %rax Return value pcount_r: movl testq je.l6 pushq movq andl shrq call addq.l6: popq rep; ret $0, %eax %rdi, %rdi %rbx %rdi, %rbx $1, %ebx %rdi pcount_r %rbx, %rax %rbx 68
66 Recursive Func2on Comple2on /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) else return 0; return (x & 1) + pcount_r(x >> 1); Register Use(s) Type %rax Return value Return value pcount_r: movl testq je.l6 pushq movq andl shrq call addq.l6: popq rep; ret $0, %eax %rdi, %rdi %rbx %rdi, %rbx $1, %ebx %rdi pcount_r %rbx, %rax %rbx... %rsp
67 Observa2ons About Recursion Handled Without Special Considera2on Stack frames mean that each func2on call has private storage Saved registers & local variables Saved return pointer Register saving conven2ons prevent one func2on call from corrup2ng another s data Unless the C code explicitly does so (e.g., buffer overflow) Stack discipline follows call / return pahern If P calls Q, then Q returns before P Last- In, First- Out Also works for mutual recursion P calls Q; Q calls P 70
68 x86-64 Procedure Summary Stack is the right data structure for procedure call / return If P calls Q, then Q returns before P Recursion (& mutual recursion) handled by normal calling conven2ons Can safely store values in local stack frame and in callee- saved registers Put func?on arguments at top of stack Result return in %rax Pointers are addresses of values On stack or global Caller Frame %rbp (Op2onal) %rsp Arguments 7+ Return Addr Old %rbp Saved Registers + Local Variables Argument Build
Machine-Level Programming III: Procedures
Machine-Level Programming III: Procedures CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides Mechanisms in Procedures Passing control
More informationMachine-level Programs Procedure
Computer Systems Machine-level Programs Procedure Han, Hwansoo Mechanisms in Procedures Passing control To beginning of procedure code Back to return point Passing data Procedure arguments Return value
More informationBryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon
Carnegie Mellon Machine-Level Programming III: Procedures 15-213/18-213/14-513/15-513: Introduction to Computer Systems 7 th Lecture, September 18, 2018 Today Procedures Mechanisms Stack Structure Calling
More informationMachine-Level Programming (2)
Machine-Level Programming (2) Yanqiao ZHU Introduction to Computer Systems Project Future (Fall 2017) Google Camp, Tongji University Outline Control Condition Codes Conditional Branches and Conditional
More informationCS429: Computer Organization and Architecture
CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 CS429 Slideset 9: 1 Mechanisms in Procedures
More informationProcedures and the Call Stack
Procedures and the Call Stack Topics Procedures Call stack Procedure/stack instructions Calling conventions Register-saving conventions Why Procedures? Why functions? Why methods? int contains_char(char*
More informationMechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing
CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 Mechanisms in Procedures Passing Control
More informationOutline. Review: Assembly/Machine Code View. Processor State (x86-64, Par2al) Condi2on Codes (Explicit Se^ng: Compare) Condi2on Codes (Implicit Se^ng)
Outline Machine- Level Representa2on: Control CSCI 2021: Machine Architecture and Organiza2on Pen- Chung Yew Department Computer Science and Engineering University of Minnesota Control: Condi2on codes
More informationAssembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Mechanisms in Procedures Passing control To beginning of procedure code
More informationThe Stack & Procedures
The Stack & Procedures CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/648/
More informationMachine-Level Programming II: Control
Mellon Machine-Level Programming II: Control CS140 Computer Organization and Assembly Slides Courtesy of: Randal E. Bryant and David R. O Hallaron 1 First https://www.youtube.com/watch?v=ivuu8jobb1q 2
More informationAssembly Programming IV
Assembly Programming IV CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis 1 Administrivia Homework 2 due
More informationFoundations of Computer Systems
18-600 Foundations of Computer Systems Lecture 6: Machine-Level Programming III: Loops, Procedures, the Stack, and More September 18, 2017 Required Reading Assignment: Chapter 3 of CS:APP (3 rd edition)
More information%r8 %r8d. %r9 %r9d. %r10 %r10d. %r11 %r11d. %r12 %r12d. %r13 %r13d. %r14 %r14d %rbp. %r15 %r15d. Sean Barker
Procedure Call Registers Return %rax %eax %r8 %r8d Arg 5 %rbx %ebx %r9 %r9d Arg 6 Arg 4 %rcx %ecx %r10 %r10d Arg 3 %rdx %edx %r11 %r11d Arg 2 %rsi %esi %r12 %r12d Arg 1 %rdi %edi %r13 %r13d ptr %esp %r14
More informationMachine-Level Programming II: Control
Machine-Level Programming II: Control CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides 1 Today Control: Condition codes Conditional
More informationx86-64 Programming III
x86-64 Programming III CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan http://xkcd.com/1652/ Administrivia Homework 2 due Wednesday (7/11) Lab
More informationMachine Program: Procedure. Zhaoguo Wang
Machine Program: Procedure Zhaoguo Wang Requirements of procedure calls? P() { y = Q(x); y++; 1. Passing control int Q(int i) { int t, z; return z; Requirements of procedure calls? P() { y = Q(x); y++;
More informationMachine Level Programming: Control
Machine Level Programming: Control Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed
More informationStack Frame Components. Using the Stack (4) Stack Structure. Updated Stack Structure. Caller Frame Arguments 7+ Return Addr Old %rbp
Stack Frame Components Frame pointer %rbp Stack pointer Caller Frame rguments 7+ Return ddr Old %rbp Saved Registers + Local Variables rgument Build 1 Using the Stack (4) Stack Structure long call_incr()
More informationSungkyunkwan University
Switch statements IA 32 Procedures Stack Structure Calling Conventions Illustrations of Recursion & Pointers long switch_eg (long x, long y, long z) { long w = 1; switch(x) { case 1: w = y*z; break; case
More informationvoid P() {... y = Q(x); print(y); return; } ... int Q(int t) { int v[10];... return v[t]; } Computer Systems: A Programmer s Perspective
void P() { y = Q(x); print(y); return;... int Q(int t) { int v[10]; return v[t]; Computer Systems: A Programmer s Perspective %rax %rbx 0x101 0x41 0x7FFFFA8 0x1 0x7FFFFF8 0xB5A9 0x7FFFFF0 0x789ABC 0x7FFFFE8
More informationThe Stack & Procedures
The Stack & Procedures CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Homework 2 due
More informationMachine Language CS 3330 Samira Khan
Machine Language CS 3330 Samira Khan University of Virginia Feb 2, 2017 AGENDA Logistics Review of Abstractions Machine Language 2 Logistics Feedback Not clear Hard to hear Use microphone Good feedback
More informationAssembly Programming IV
Assembly Programming IV CSE 410 Winter 2017 Instructor: Justin Hsia Teaching Assistants: Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui The Data That Turned the World Upside Down The company
More informationMachine- Level Programming III: Switch Statements and IA32 Procedures
Machine- Level Programming III: Switch Statements and IA32 Procedures 15-213: Introduc;on to Computer Systems 6 th Lecture, Sep. 9, 2010 Instructors: Randy Bryant and Dave O Hallaron Today Switch statements
More informationLecture 4: x86_64 Assembly Language
CSCI-GA.1144-001 PAC II Lecture 4: x86_64 Assembly Language Some slides adapted (and slightly modified) from: Randy Bryant Dave O Hallaron Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com
More informationCS367. Program Control
CS367 Program Control outline program control condition codes branching looping conditional moves switches (special case of branching) Condition Codes Processor State (x86-64, Partial) Info about currently
More informationInstruc(on Set Architecture. Computer Architecture Instruc(on Set Architecture Y86. Y86-64 Processor State. Assembly Programmer s View
Instruc(on Set Architecture Computer Architecture Instruc(on Set Architecture Y86 CSCI 2021: Machine Architecture and Organiza(on Pen- Chung Yew Department Computer Science and Engineering University of
More informationMachine- Level Programming II: Arithme6c & Control
Machine- Level Programming II: Arithme6c & Control 15-213: Introduc0on to Computer Systems 5 th Lecture, Sep. 7, 2010 Instructors: Randy Bryant and Dave O Hallaron Modified by Karen L. Karavanic 2015 1
More informationCarnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition
1 Machine-Level Programming II: Control 15-213: Introduction to Computer Systems 6 th Lecture, Sept. 13, 2018 2 Today Control: Condition codes Conditional branches Loops Switch Statements 3 Recall: ISA
More informationMachine- Level Programming III: Switch Statements and IA32 Procedures
Machine- Level Programming III: Switch Statements and IA32 Procedures CS 485: Systems Programming Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hjp://csapp.cs.cmu.edu/public/instructors.html)
More information2/12/2016. Today. Machine-Level Programming II: Control. Condition Codes (Implicit Setting) Processor State (x86-64, Partial)
Today Machine-Level Programming II: Control CSci 2021: Machine Architecture and Organization Lectures #9-11, February 8th-12th, 2016 Control: Condition codes Conditional branches Loops Switch Statements
More informationMachine-Level Programming II: Control
Machine-Level Programming II: Control 15-213: Introduction to Computer Systems 6 th Lecture, Feb. 2, 2017 Instructors: Franz Franchetti and Seth C. Goldstein 1 Office Hours Thanks for Coming! and sorry
More informationCS 33. Machine Programming (2) CS33 Intro to Computer Systems XII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.
CS 33 Machine Programming (2) CS33 Intro to Computer Systems XII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Processor State (x86-64, Partial) %rax %eax %r8 %r8d %rbx %ebx %r9 %r9d %rcx %ecx
More informationCS429: Computer Organization and Architecture
CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 26, 2018 at 12:02 CS429 Slideset 8: 1 Controlling Program
More informationRegion of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address = address of top element
Machine Representa/on of Programs: Procedures Instructors: Sanjeev Se(a 1 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Stack BoGom Increasing Addresses Register
More informationx86-64 Programming III & The Stack
x86-64 Programming III & The Stack CSE 351 Winter 2018 Instructor: Mark Wyse Teaching Assistants: Kevin Bi Parker DeWilde Emily Furst Sarah House Waylon Huang Vinny Palaniappan http://xkcd.com/1652/ Administrative
More informationCompiling C Programs Into X86-64 Assembly Programs
CSE 2421: Systems I Low-Level Programming and Computer Organization Compiling C Programs Into X86-64 Assembly Programs Part B: If Else, Loops, Recursion & Switch Presentation L Read/Study: Bryant 3.6 Gojko
More informationx86 Programming II CSE 351 Winter
x86 Programming II CSE 351 Winter 2017 http://xkcd.com/1652/ Administrivia 2 Address Computation Instruction v leaq src, dst lea stands for load effective address src is address expression (any of the
More informationIA32 Stack. Stack BoDom. Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address
IA32 Procedures 1 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Stack BoDom Increasing Addresses Register contains lowest stack address address of top element Stack
More informationx86-64 Programming II
x86-64 Programming II CSE 351 Winter 2018 Instructor: Mark Wyse Teaching Assistants: Kevin Bi Parker DeWilde Emily Furst Sarah House Waylon Huang Vinny Palaniappan http://xkcd.com/409/ Administrative Homework
More informationCS 33. Machine Programming (2) CS33 Intro to Computer Systems XI 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.
CS 33 Machine Programming (2) CS33 Intro to Computer Systems XI 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. Observations about arith int arith(int x, int y, int z) { int t1 = x+y; int t2
More informationCS 107. Lecture 13: Assembly Part III. Friday, November 10, Stack "bottom".. Earlier Frames. Frame for calling function P. Increasing address
CS 107 Stack "bottom" Earlier Frames Lecture 13: Assembly Part III Argument n Friday, November 10, 2017 Computer Systems Increasing address Argument 7 Frame for calling function P Fall 2017 Stanford University
More informationx86 Programming III CSE 351 Autumn 2016 Instructor: Justin Hsia
x86 Programming III CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/648/
More informationL09: Assembly Programming III. Assembly Programming III. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson
Assembly Programming III CSE 351 Spring 2017 Guest Lecturer: Justin Hsia Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis
More informationMachine Level Programming II: Arithmetic &Control
Machine Level Programming II: Arithmetic &Control Arithmetic operations Control: Condition codes Conditional branches Loops Switch Kai Shen 1 2 Some Arithmetic Operations Two Operand Instructions: Format
More informationAssembly Programming III
Assembly Programming III CSE 410 Winter 2017 Instructor: Justin Hsia Teaching Assistants: Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui Facebook Stories puts a Snapchat clone above the News
More informationIntel x86-64 and Y86-64 Instruction Set Architecture
CSE 2421: Systems I Low-Level Programming and Computer Organization Intel x86-64 and Y86-64 Instruction Set Architecture Presentation J Read/Study: Bryant 3.1 3.5, 4.1 Gojko Babić 03-07-2018 Intel x86
More informationAssembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Assembly II: Control Flow Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Processor State (x86-64) RAX 63 31 EAX 0 RBX EBX RCX RDX ECX EDX General-purpose
More informationAreas for growth: I love feedback
Assembly part 2 1 Areas for growth: I love feedback Speed, I will go slower. Clarity. I will take time to explain everything on the slides. Feedback. I give more Kahoot questions and explain each answer.
More informationControl flow (1) Condition codes Conditional and unconditional jumps Loops Conditional moves Switch statements
Control flow (1) Condition codes Conditional and unconditional jumps Loops Conditional moves Switch statements 1 Conditionals and Control Flow Two key pieces 1. Comparisons and tests: check conditions
More informationAssembly II: Control Flow
Assembly II: Control Flow Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)
More informationCSCI 2021: x86-64 Control Flow
CSCI 2021: x86-64 Control Flow Chris Kauffman Last Updated: Mon Mar 11 11:54:06 CDT 2019 1 Logistics Reading Bryant/O Hallaron Ch 3.6: Control Flow Ch 3.7: Procedure calls Goals Jumps and Control flow
More informationData Representa/ons: IA32 + x86-64
X86-64 Instruc/on Set Architecture Instructor: Sanjeev Se(a 1 Data Representa/ons: IA32 + x86-64 Sizes of C Objects (in Bytes) C Data Type Typical 32- bit Intel IA32 x86-64 unsigned 4 4 4 int 4 4 4 long
More informationUniversity of Washington
Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq %rbp movq %rsp, %rbp... popq %rbp
More informationWhere We Are. Optimizations. Assembly code. generation. Lexical, Syntax, and Semantic Analysis IR Generation. Low-level IR code.
Where We Are Source code if (b == 0) a = b; Low-level IR code Optimized Low-level IR code Assembly code cmp $0,%rcx cmovz %rax,%rdx Lexical, Syntax, and Semantic Analysis IR Generation Optimizations Assembly
More informationBuilding an Executable
Building an Executable CSE 351 Summer 2018 Instructor: Justin Hsia Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan http://xkcd.com/1790/ Administrivia Lab 2 due Monday (7/16) Homework 3 due
More informationFoundations of Computer Systems
18-600 Foundations of Computer Systems Lecture 5: Data and Machine-Level Programming I: Basics September 13, 2017 Required Reading Assignment: Chapter 3 of CS:APP (3 rd edition) by Randy Bryant & Dave
More informationSystems Programming and Computer Architecture ( )
Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 AS 2016 Compiling C Control Flow 1 8: Compiling C
More informationThe Hardware/Software Interface CSE351 Spring 2013
The Hardware/Software Interface CSE351 Spring 2013 x86 Programming II 2 Today s Topics: control flow Condition codes Conditional and unconditional branches Loops 3 Conditionals and Control Flow A conditional
More informationx86 64 Programming II
x86 64 Programming II CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie
More informationRoadmap. Java: Assembly language: OS: Machine code: Computer system:
Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: get_mpg: pushq movq... popq ret %rbp %rsp, %rbp %rbp 0111010000011000
More informationHow Software Executes
How Software Executes CS-576 Systems Security Instructor: Georgios Portokalidis Overview Introduction Anatomy of a program Basic assembly Anatomy of function calls (and returns) Memory Safety Intel x86
More informationProcessor state. Information about currently executing program. %rax, %rdi, ... %r14 %r15. %rsp. %rip CF ZF SF OF. Temporary data
Processor state Information about currently executing program Temporary data %rax, %rdi, current parameters, local variables Location of runtime stack %rsp Location of current instruction %rip Status of
More informationCSE351 Spring 2018, Midterm Exam April 27, 2018
CSE351 Spring 2018, Midterm Exam April 27, 2018 Please do not turn the page until 11:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls
Princeton University Computer Science 217: Introduction to Programming Systems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent
More informationRoadmap. Java: Assembly language: OS: Machine code: Computer system:
Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq movq... popq ret %rbp %rsp, %rbp
More informationAssembly Language: Function Calls
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems x86-64 solutions Pertinent instructions and conventions 2 Function Call Problems (1) Calling and returning
More informationCSE 351 Midterm Exam Spring 2016 May 2, 2015
Name: CSE 351 Midterm Exam Spring 2016 May 2, 2015 UWNetID: Solution Please do not turn the page until 11:30. Instructions The exam is closed book, closed notes (no calculators, no mobile phones, no laptops,
More informationSystems I. Machine-Level Programming V: Procedures
Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp
More informationx64 Cheat Sheet Fall 2014
CS 33 Intro Computer Systems Doeppner x64 Cheat Sheet Fall 2014 1 x64 Registers x64 assembly code uses sixteen 64-bit registers. Additionally, the lower bytes of some of these registers may be accessed
More informationAssembly Language II: Addressing Modes & Control Flow
Assembly Language II: Addressing Modes & Control Flow Learning Objectives Interpret different modes of addressing in x86 assembly Move data seamlessly between registers and memory Map data structures in
More informationDo not turn the page until 5:10.
University of Washington Computer Science & Engineering Autumn 2018 Instructor: Justin Hsia 2018-10-29 Last Name: First Name: Student ID Number: Name of person to your Left Right All work is my own. I
More informationMachine-Level Programming II: Control and Arithmetic
Machine-Level Programming II: Control and Arithmetic CSCI 2400: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides 1 Today Complete addressing mode, address
More informationCredits to Randy Bryant & Dave O Hallaron
Mellon Machine Level Programming II: Arithmetic & Control Lecture 4, March 10, 2011 Alexandre David Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon 1 Today Complete addressing mode, address
More information1 Number Representation(10 points)
Name: Sp15 Midterm Q1 1 Number Representation(10 points) 1 NUMBER REPRESENTATION(10 POINTS) Let x=0xe and y=0x7 be integers stored on a machine with a word size of 4bits. Show your work with the following
More informationCSE 351 Midterm Exam
University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse February 5, 2018 CSE 351 Midterm Exam Last Name: First Name: SOLUTIONS UW Student ID Number: UW NetID (username):
More informationMachine- Level Programming II: Arithme6c & Control
Machine- Level Programming II: Arithme6c & Control Computer Architecture Instructor: Norbert Lu*enberger based on the book by Randy Bryant and Dave O Hallaron 1 Today Complete addressing mode, address
More informationComputer Organization: A Programmer's Perspective
A Programmer's Perspective Instruction Set Architecture Gal A. Kaminka galk@cs.biu.ac.il Outline: CPU Design Background Instruction sets Logic design Sequential Implementation A simple, but not very fast
More informationMachine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012
n Mello Machine-Level Programming II: Arithmetic & Control 15-213/18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012 Instructors: Gregory Kesden The course that gives CMU its Zip! Last Time:
More informationASSEMBLY III: PROCEDURES. Jo, Heeseung
ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top
More informationAssembly III: Procedures. Jo, Heeseung
Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top
More informationControlling Program Flow
Controlling Program Flow Conditionals (If-statement) Loops (while, do-while, for-loops) Switch Statements New Instructions JMP CMP Conditional jumps (branches) Conditional MOV instruction 1 Conditional
More informationhnp://
The bots face off in a tournament against one another and about an equal number of humans, with each player trying to score points by elimina&ng its opponents. Each player also has a "judging gun" in addi&on
More informationLecture 3 CIS 341: COMPILERS
Lecture 3 CIS 341: COMPILERS HW01: Hellocaml! Announcements is due tomorrow tonight at 11:59:59pm. HW02: X86lite Will be available soon look for an announcement on Piazza Pair-programming project Simulator
More informationCS213. Machine-Level Programming III: Procedures
CS213 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows toward
More informationMachine/Assembler Language Putting It All Together
COMP 40: Machine Structure and Assembly Language Programming Fall 2015 Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah
More informationcmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest
Instruction Set Architecture Computer Architecture: Instruction Set Architecture CSci 2021: Machine Architecture and Organization Lecture #16, February 24th, 2016 Your instructor: Stephen McCamant Based
More informationAssembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32 (1) Characteristics Region of memory managed with stack discipline
More informationGiving credit where credit is due
CSCE 230J Computer Organization Machine-Level Programming III: Procedures Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created
More informationHow Software Executes
How Software Executes CS-576 Systems Security Instructor: Georgios Portokalidis Overview Introduction Anatomy of a program Basic assembly Anatomy of function calls (and returns) Memory Safety Programming
More informationCS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5
CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 5 LAST TIME Began exploring x86-64 instruction set architecture 16 general-purpose registers Also: All registers are 64 bits wide rax-rdx are
More informationMachine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes
Machine-Level Programming II: Arithmetic & Control CS-281: Introduction to Computer Systems Instructor: Thomas C. Bressoud 1 Complete Memory Addressing Modes Most General Form D(Rb,Ri,S)Mem[Reg[Rb]+S*Reg[Ri]+
More informationMachine- level Programming II: Control Flow
Machine- level Programming II: Control Flow Topics Condi;on Codes Se=ng Tes;ng Control Flow If- then- else Varie;es of Loops Switch Statements 1! Condi;on Codes Single Bit Registers CF Carry Flag SF Sign
More information6.1. CS356 Unit 6. x86 Procedures Basic Stack Frames
6.1 CS356 Unit 6 x86 Procedures Basic Stack Frames 6.2 Review of Program Counter (Instruc. Pointer) PC/IP is used to fetch an instruction PC/IP contains the address of the next instruction The value in
More informationThe course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002
15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables class07.ppt
More informationX86 Assembly -Procedure II:1
X86 Assembly -Procedure II:1 IA32 Object Code Setup Label.L61 becomes address 0x8048630 Label.L62 becomes address 0x80488dc Assembly Code switch_eg:... ja.l61 # if > goto default jmp *.L62(,%edx,4) # goto
More informationComputer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu
Computer Architecture I: Outline and Instruction Set Architecture CENG331 - Computer Organization Murat Manguoglu Adapted from slides of the textbook: http://csapp.cs.cmu.edu/ Outline Background Instruction
More informationReview addressing modes
Review addressing modes Op Src Dst Comments movl $0, %rax Register movl $0, 0x605428 Direct address movl $0, (%rcx) Indirect address movl $0, 20(%rsp) Indirect with displacement movl $0, -8(%rdi, %rax,
More informationCSC 252: Computer Organization Spring 2018: Lecture 6
CSC 252: Computer Organization Spring 2018: Lecture 6 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Assignment 2 is out Announcement Programming Assignment
More information