1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.
|
|
- Piers Spencer
- 6 years ago
- Views:
Transcription
1
2 1 /* file cpuid2.s */ 2.section.data 3 output: 4.asciz "The processor Vendor ID is %s \n" 5.section.bss 6.lcomm buffer, 12 7.section.text 8.globl _start 9 _start: 10 movl $0, %eax 11 cpuid 12 movl $buffer, %edi 13 movl %ebx, (%edi) 14 movl %edx, 4(%edi) 15 movl %ecx, 8(%edi) 16 pushl $buffer 17 pushl $output 18 call printf 19 addl $8, %esp 20 pushl $0 21 call exit 1 /* file cpuid.s */ 2.section.data 3 output: 4.ascii "The processor Vendor ID is xxxxxxxxxxxx \n" 5.section.text 6.globl _start 7 _start: 8 movl $0, %eax 9 cpuid 10 movl $output, %edi 11 movl %ebx, 28(%edi) 12 movl %edx, 32(%edi) 13 movl %ecx, 36(%edi) 14 movl $4, %eax 15 movl $1, %ebx 16 movl $output, %ecx 17 movl $42, %edx 18 int $0x80 19 movl $1, %eax 20 movl $0, %ebx 21 int $0x80
3
4
5 int x, y; int x, y;... movl %ebx, %eax... movl %ebx, %eax x=y; x=y; int x, y;... x=y;
6 int x = 0x ; char y = 0xFF;... movl $0x7FFFFFFF, %eax movb $0x6, %al x=y; C declaration intel data type GAS suffix, e.g., for movx instruction x86-32 size (bytes) char byte b 1 short word w 2 int double word l 4 unsigned double word l 4 long int double word l 4 unsigned long double word l 4 char * double word l 4 float single precision s 4 double double precision l 8 long double extended precision t 10/12 x=35; movl $35, %eax
7 1.section.rodata 2 print_str: 3.string "x=0x%x\n" 4.text 5.globl main 6.type 7 main: 8 pushl %ebp 9 movl %esp, %ebp 10 movl $0x , %eax 11 movl $print_str, %ecx 12 pushl %eax 13 pushl %ecx 14 call printf 15 addl $8, %esp 16 movl $0, %eax 17 leave 18 ret 1.section.rodata 2 print_str: 3.string "x=0x%x\n" 4.text 5.globl main 6.type 7 main: 8 pushl %ebp 9 movl %esp, %ebp 10 movl $0x , %eax 11 movb $0xFF, %al 12 movl $print_str, %ecx 13 pushl %eax 14 pushl %ecx 15 call printf 16 addl $8, %esp 17 movl $0, %eax 18 leave 19 ret movl movb $0x7FFFFFFF, %eax $0x6, %al 1.section.rodata 2 print_str: 3.string "x=0x%x\n" 4.text 5.globl main 6.type 7 main: 8 pushl %ebp 9 movl %esp, %ebp 10 movl $0x , %eax 11 movl $print_str, %ecx 12 pushl %eax 13 pushl %ecx 14 call printf 15 addl $8, %esp 16 movl $0, %eax 17 leave 18 ret 1.section.rodata 2 print_str: 3.string "x=0x%x\n" 4.text 5.globl main 6.type 7 main: 8 pushl %ebp 9 movl %esp, %ebp 10 movl $0x , %eax 11 movb $0xFF, %al 12 movl $print_str, %ecx 13 pushl %eax 14 pushl %ecx 15 call printf 16 addl $8, %esp 17 movl $0, %eax 18 leave 19 ret
8 1.section.rodata 2 print_str: 3.string "x=0x%x\n" 4.text 5.globl main 6.type 7 main: 8 pushl %ebp 9 movl %esp, %ebp 10 movl $0x , %eax 11 movb $0xFF, %dl 12 movzbl %dl, %eax 13 movl $print_str, %ecx 14 pushl %eax 15 pushl %ecx 16 call printf 17 addl $8, %esp 18 movl $0, %eax 19 leave 20 ret 21.size main,.-main 1.section.rodata 2 print_str: 3.string "x=0x%x\n" 4.text 5.globl main 6.type 7 main: 8 pushl %ebp 9 movl %esp, %ebp 10 movl $0x , %eax 11 movb $0xFF, %dl 12 movzbl %dl, %eax 13 movl $print_str, %ecx 14 pushl %eax 15 pushl %ecx 16 call printf 17 addl $8, %esp 18 movl $0, %eax 19 leave 20 ret 21.size main,.-main
9 var addr ip 1000 cp 1000 cp ip cp+x 1000+x ip+x 1000+x*sizeof(int) src dst assembly example C equiv imm reg movl $0x52, %eax x=0x52; imm mem movl $0x52, (%eax) *p=0x52; reg reg movl %ebx, %eax a=b; reg mem movl %eax, (%ebx) *p=x; mem reg movl (%eax), %ebx x=*p; mem mem can t be done *p=*q;
10 x y x y %eax %edx %ecx %ebx %esi %edi %esp %ebp yp xp 12 %ebp 0 movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx x11c 0x118 0x114 0x110 0x10c 0x108 0x100 %eax %edx %ecx %ebx %esi %edi %esp %ebp yp xp 12 movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 8 4 %ebp 0-4 0x11c 0x118 0x114 0x110 0x10c 0x108 0x100 void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } swap: pushl %ebp movl %esp,%ebp pushl %ebx movl 12(%ebp),%ecx movl 8(%ebp),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } %ecx yp %edx xp %eax t1 %ebx t yp xp ebp ebx %ebp movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx
11 x y x y %eax %edx %ecx %ebx %esi %edi %esp %ebp yp xp %ebp 0-4 movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 0x11c 0x118 0x114 0x110 0x10c 0x108 0x100 %eax %edx %ecx %ebx %esi %edi %esp %ebp yp xp %ebp 0-4 movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 0x11c 0x118 0x114 0x110 0x10c 0x108 0x100 x y x y %eax %edx %ecx %ebx %esi %edi %esp %ebp yp xp %ebp 0-4 movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 0x11c 0x118 0x114 0x110 0x10c 0x108 0x100 %eax %edx %ecx %ebx %esi %edi %esp %ebp 456 yp xp %ebp 0-4 movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx 0x11c 0x118 0x114 0x110 0x10c 0x108 0x100
12 %eax %edx %ecx %ebx %esi %edi %esp %ebp yp xp %ebp movl 12(%ebp),%ecx # ecx = yp movl 8(%ebp),%edx # edx = xp movl (%ecx),%eax # eax = *yp (t1) movl (%edx),%ebx # ebx = *xp (t0) movl %eax,(%edx) # *xp = eax movl %ebx,(%ecx) # *yp = ebx x y 0x11c 0x118 0x114 0x110 0x10c 0x108 0x100 assembly exp resulting address x(%eax) %eax+x (%eax, %ebx) %eax+%ebx x(%eax, %ebx) x+%eax+%ebx (,%eax,s) (%eax*s) x(,%eax,s) x+(%eax*s) (%eax,%ebx,s) %eax+(%ebx*s) x(%eax,%ebx,s) x+%eax+(%ebx*s)
13 operand value %eax?? $0x108? (%eax)? 4(%eax)? 9(%eax,%edx)? 260(%ecx,%edx)? 0xFC(,%ecx,4)? (%eax,%edx,4)? address 0x100 0x108 0x10C register %eax %ecx %edx value 0xFF 0xAB 0x13 0x11 value 0x100 0x1 0x3 operand value comment %eax 0x100 register 0xAB absolute address $0x108 0x108 immediate (%eax) 0xFF addr 0x100 4(%eax) 0xAB addr 9(%eax,%edx) 0x11 addr 0x10C 260(%ecx,%edx) 0x13 addr 0x108 0xFC(,%ecx,4) 0xFF addr 0x100 (%eax,%edx,4) 0x11 addr 0x10C address 0x100 0x108 0x10C register %eax %ecx %edx value 0xFF 0xAB 0x13 0x11 value 0x100 0x1 0x3 type form operand value name immediate $imm imm immediate register E a R[E a ] register memory imm M[imm] absolute memory (E a ) M[R[E a ]] indirect memory imm(e b ) M[imm+R[E b ]] base+displacement memory (E b,e i ) M[R[E b ]+R[E i ]] indexed memory imm(e b,e i ) M[imm+R[E b ]+R[E i ]] indexed memory (,E i,s) M[R[E i ]*s] scaled indexed memory imm(,e i,s) M[imm+R[E i ]*s] scaled indexed memory (E b,e i,s) M[R[E b ]+R[E i ]*s] scaled indexed memory imm(e b,e i,s) M[imm+R[E b ]+R[E i ]*s] scaled indexed
14 expression leal 6(%eax), %edx leal (%eax,%ecx), %edx leal (%eax,%ecx, 4), %edx leal 7(%eax,%eax,8), %edx leal 0xA(,%ecx,4), %edx leal 9(%eax,%ecx,2), %edx result expression result leal 6(%eax), %edx 6+x leal (%eax,%ecx), %edx x+y leal (%eax,%ecx, 4), %edx x+4y leal 7(%eax,%eax,8), %edx 7+x+8x=7+9x leal 0xA(,%ecx,4), %edx 0xA+4y=10+4y leal 9(%eax,%ecx,2), %edx 9+x+2y %eax %ecx 0x1000 0xA %eax %ecx 0x1000 0xA %eax+%ecx*4 = 0x *4 = 0x = 0x1000+0x28 = 0x1028
15 instruction effect description incl D D D + 1 increment decl D D D 1 decrement negl D D D negate notl D D D complement addl S, D D D + S add subl S, D D D S subtract imull S, D D D S multiply xorl S, D D D S exclusive or orl S, D D D S or andl S, D D D&S and sall k, D D D << k left shift shll k, D D D << k left shift (same as sall) sarl k, D D D >> k shift right arithmetic shrl k, D D D >> k shift right logical
16 1 #include <stdlib.h> 2 3 #define BUF_LEN int main(void) { 6 int x; 7 char *buff; if ((buff = (char*)malloc(buf_len))==null) { 12 fprintf(stderr, "error allocating space. quitting\n"); 13 return 1; 14 } return 0; 18 } 1 class Junk { 2 int x; 3 String s; 4 } 5 6 public class WhereAllocated { 7 public static void main(string args[]) { 8 final int LEN = 1024; 9 int x; 10 Junk j = new Junk(); 11 int A[] = new int[len]; for (int i=0; i<a.length; i++) { /* do something with A[] */ } 20 } 21 }
17
18
19
20
21 parameter location local var 2-8(%ebp) local var 1-4(%ebp) old %ebp (%ebp) return addr 4(%ebp) param 1 8(%ebp) param 2 12(%ebp) param n 4n+4(%ebp) parameter location old %ebp (%ebp) return addr 4(%ebp) param 1 8(%ebp) param 2 12(%ebp) param n 4n+4(%ebp)
22 void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } swap: pushl %ebp movl %esp,%ebp pushl %ebx movl 12(%ebp),%ecx movl 8(%ebp),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret 1.text 2.globl sumtwomine 3.type 4 sumtwomine: 5 pushl %ebp 6 movl %esp, %ebp 7 movl 12(%ebp), %eax 8 movl 8(%ebp), %edx 9 addl %edx, %eax 10 popl %ebp 11 ret type fname: pushl %ebp movl %esp, %ebp /* add space for local vars if */ /* necessary by subtracting */ /* from %esp */... /* if you ve added space for */ /* local vars, free the space */ /* by adding to %esp */ movl popl ret %ebp, %esp %ebp
23 1.text 2.globl sumtwomine 3.type 4 sumtwomine: 5 pushl %ebp 6 movl %esp, %ebp 7 movl 12(%ebp), %eax 8 movl 8(%ebp), %edx 9 addl %edx, %eax 10 popl %ebp 11 ret 1.text 2.globl sumtwo 3.type 4 sumtwo: 5 pushl %ebp 6 movl %esp, %ebp 7 movl 12(%ebp), %eax 8 movl 8(%ebp), %edx 9 leal (%edx,%eax), %eax 10 popl %ebp 11 ret
24
25 void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } swap: pushl %ebp movl %esp,%ebp pushl %ebx movl 12(%ebp),%ecx movl 8(%ebp),%edx movl (%ecx),%eax movl (%edx),%ebx movl %eax,(%edx) movl %ebx,(%ecx) movl -4(%ebp),%ebx movl %ebp,%esp popl %ebp ret 1.section.text 2.globl _start 3.globl factorial #this is unneeded unless we want to share 4 #this function among other programs 5 _start: 6 pushl $4 #The factorial takes one argument - the 7 #number we want a factorial of. So, it 8 #gets pushed 9 call factorial #run the factorial function 10 addl $4, %esp #Scrubs the parameter that was pushed on 11 #the stack 12 movl %eax, %ebx #factorial returns the answer in %eax, but 13 #we want it in %ebx to send it as our exit 14 #status 15 movl $1, %eax #call the kernel s exit function 16 int $0x80
26 1.type 2 factorial: 3 pushl %ebp #standard function stuff - we have to 4 #restore %ebp to its prior state before 5 #returning, so we have to push it 6 movl %esp, %ebp #This is because we don t want to modify 7 #the stack pointer, so we use %ebp. 8 9 movl 8(%ebp), %eax #This moves the first argument to %eax 10 #4(%ebp) holds the return address, and 11 #8(%ebp) holds the first parameter 12 cmpl $1, %eax #If the number is 1, that is our base 13 #case, and we simply return (1 is 14 #already in %eax as the return value) 15 je end_factorial 16 decl %eax #otherwise, decrease the value 17 pushl %eax #push it for our call to factorial 18 call factorial #call factorial 19 movl 8(%ebp), %ebx #%eax has the return value, so we 20 #reload our parameter into %ebx 21 imull %ebx, %eax #multiply that by the result of the 22 #last call to factorial (in %eax) 23 #the answer is stored in %eax, which 24 #is good since that s where return 25 #values go. 26 end_factorial: 27 movl %ebp, %esp #standard function return stuff - we 28 popl %ebp #have to restore %ebp and %esp to where 29 #they were before the function started 30 ret #return from the function (this pops the 31 #return value, too)
Ge-ng at things on the chip you can t easily reach from C
chapter 3 part 2 1 Ge-ng at things on the chip you can t easily reach from C 2 CPUID CPUID example from Blum, Professional Assembly Language. Programmer to Programmer. Very good maybe lidle bit dated Available
More informationAssembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University
Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Moving Data (1) Moving data: movl source, dest Move 4-byte ( long )
More informationAssembly I: Basic Operations. Jo, Heeseung
Assembly I: Basic Operations Jo, Heeseung Moving Data (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C
More informationASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung
ASSEMBLY I: BASIC OPERATIONS Jo, Heeseung MOVING DATA (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C
More informationTurning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p
Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm
More informationMachine Programming 1: Introduction
Machine Programming 1: Introduction CS61, Lecture 3 Prof. Stephen Chong September 8, 2011 Announcements (1/2) Assignment 1 due Tuesday Please fill in survey by 5pm today! Assignment 2 will be released
More informationMachine-Level Programming Introduction
Machine-Level Programming Introduction Today Assembly programmer s exec model Accessing information Arithmetic operations Next time More of the same Fabián E. Bustamante, Spring 2007 IA32 Processors Totally
More informationMachine-Level Programming I: Introduction Jan. 30, 2001
15-213 Machine-Level Programming I: Introduction Jan. 30, 2001 Topics Assembly Programmer s Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate
More informationAssembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction
Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer
More informationMachine-Level Programming Introduction
Machine-Level Programming Introduction Today! Assembly programmer s exec model! Accessing information! Arithmetic operations Next time! More of the same Fabián E. Bustamante, 2007 X86 Evolution: Programmer
More informationCISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008
CISC 360 Machine-Level Programming I: Introduction Sept. 18, 2008 Topics Assembly Programmerʼs Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate
More informationThe course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, 2002
15-213 The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, 2002 Topics Assembly Programmer s Execution Model Accessing Information Registers Memory Arithmetic operations
More informationAssembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012
19:211 Computer Architecture Lecture 10 Fall 20 Topics:Chapter 3 Assembly Language 3.2 Register Transfer 3. ALU 3.5 Assembly level Programming We are now familiar with high level programming languages
More informationProcess Layout and Function Calls
Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized
More informationCS241 Computer Organization Spring Addresses & Pointers
CS241 Computer Organization Spring 2015 Addresses & Pointers 2-24 2015 Outline! Addresses & Pointers! leal - load effective address! Condition Codes & Jumps! conditional statements: if-then-else! conditional
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 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 informationCS241 Computer Organization Spring 2015 IA
CS241 Computer Organization Spring 2015 IA-32 2-10 2015 Outline! Review HW#3 and Quiz#1! More on Assembly (IA32) move instruction (mov) memory address computation arithmetic & logic instructions (add,
More informationX86 Assembly -Data II:1
X86 Assembly -Data II:1 Administrivia HW1 due tonight Paper to locker, file to blackboard Lab1 Check scoreboard Quiz0 Remind me if you don t see in the lecture slide online Reading: chapter 3 now! II:2
More informationThe Hardware/Software Interface CSE351 Spring 2015
The Hardware/Software Interface CSE351 Spring 2015 Lecture 7 Instructor: Katelin Bailey Teaching Assistants: Kaleo Brandt, Dylan Johnson, Luke Nelson, Alfian Rizqi, Kritin Vij, David Wong, and Shan Yang
More informationMachine-Level Programming III: Procedures
Machine-Level Programming III: Procedures IA32 Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address address of top element Bottom Increasing
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 informationSungkyunkwan University
- 2 - Complete addressing mode, address computation (leal) Arithmetic operations Control: Condition codes Conditional branches While loops - 3 - Most General Form D(Rb,Ri,S) Mem[ Reg[ R b ] + S Reg[ R
More informationProcess Layout, Function Calls, and the Heap
Process Layout, Function Calls, and the Heap CS 6 Spring 20 Prof. Vern Paxson TAs: Devdatta Akhawe, Mobin Javed, Matthias Vallentin January 9, 20 / 5 2 / 5 Outline Process Layout Function Calls The Heap
More informationMachine-level Programming (3)
Machine-level Programming (3) Procedures A: call A call A return Two issues How to return to the correct position? How to pass arguments and return values between callee to caller? 2 Procedure Control
More informationPage # CISC 360. Machine-Level Programming I: Introduction Sept. 18, IA32 Processors. X86 Evolution: Programmerʼs View.
Machine-Level Programming I: Introduction Sept. 18, 2008 Topics CISC 360 Assembly Programmerʼs Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate
More informationMeet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT
Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT CS33 Intro to Computer Systems XI 1 Copyright 2017 Thomas
More informationIA32 Processors The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, X86 Evolution: Programmer s View
Machine-Level Programming I: Introduction Sept. 10, 2002 class05.ppt 15-213 The course that gives CMU its Zip! Topics Assembly Programmer s Execution Model Accessing Information Registers Memory Arithmetic
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 information! Starting in 1978 with ! Added more features as time goes on. ! Still support old features, although obsolete
Machine-Level Programming I: Introduction Sept. 10, 2002 class05.ppt 15-213 The course that gives CMU its Zip! Topics! Assembly Programmer s Execution Model! Accessing Information " Registers " Memory!
More informationHomework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1
Homework In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, 361-367 Practice Exam 1 1 In-line Assembly Code The gcc compiler allows you to put assembly instructions in-line
More informationMachine- level Programming
Machine- level Programming Topics Assembly Programmer s Execu:on Model Accessing Informa:on Registers Memory Arithme:c opera:ons 1! Evolu:onary Design Star:ng in 1978 with 8086 IA32 Processors Added more
More informationadministrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?
administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? exam on Wednesday today s material not on the exam 1 Assembly Assembly is programming
More informationHandout #2: Machine-Level Programs
15-213 Handout #2: Machine-Level Programs on Linux/IA32 Randal E. Bryant David R. O Hallaron October 15, 1999 1 Introduction This document describes how machine-level programs are encoded for Intel IA32
More informationCS , Fall 2001 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2001 Exam 1 October 9, 2001 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write
More information4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only
Instructions: The following questions use the AT&T (GNU) syntax for x86-32 assembly code, as in the course notes. Submit your answers to these questions to the Curator as OQ05 by the posted due date and
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 informationMachine Programming 3: Procedures
Machine Programming 3: Procedures CS61, Lecture 5 Prof. Stephen Chong September 15, 2011 Announcements Assignment 2 (Binary bomb) due next week If you haven t yet please create a VM to make sure the infrastructure
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 informationCAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm
CAS CS 210 - Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm This problem set is to be completed individually. Explain how you got to your answers
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 informationY86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View
Computer Architecture I Instruction Set Architecture Assembly Language View Processor state Registers, memory, Instructions addl, movl, andl, How instructions are encoded as bytes Layer of Abstraction
More informationInstructor: Alvin R. Lebeck
X86 Assembly Programming with GNU assembler Lecture 7 Instructor: Alvin R. Lebeck Some Slides based on those from Randy Bryant and Dave O Hallaron Admin Reading: Chapter 3 Note about pointers: You must
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 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 informationInstruction Set Architecture
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View! Processor
More informationInstruction Set Architecture
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View Processor
More informationAS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions
CS220 Logic Design Outline Calling Conventions Multi-module Programs 1 Calling and Returning We have already seen how the call instruction is used to execute a subprogram. call pushes the address of the
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 informationSoftware. Hardware. x86 basics. ISA View. a brief history of x86 10/6/15. Program, Application. Programming Language. Compiler/Interpreter
x6 basics ISA context and x6 history Translation: Compile C à machine code Disassemble machine code x6 Basics: isters Data movement instructions Memory addressing modes Arithmetic instructions 1 Software
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 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 informationCMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang
Project 3 Questions CMSC 313 Lecture 12 How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP
More informationGiving credit where credit is due
CSCE 230J Computer Organization Machine-Level Programming I: Introduction 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 informationCMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009
CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009 Name Score out of 70 UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. For TRUE/FALSE questions, write the
More informationCompiler Construction D7011E
Compiler Construction D7011E Lecture 8: Introduction to code generation Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 What is a Compiler? Compilers
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 informationCS 3843 Final Exam Fall 2012
CS 3843 Final Exam Fall 2012 Name (Last), (First) ID Please indicate your session: Morning Afternoon You may use a calculator and two sheets of notes on this exam, but no other materials and no computer.
More informationCMSC 313 Lecture 12 [draft] How C functions pass parameters
CMSC 313 Lecture 12 [draft] How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP removes an
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 informationQuestions about last homework? (Would more feedback be useful?) New reading assignment up: due next Monday
Questions about last homework? (Would more feedback be useful?) New reading assignment up: due next Monday addl: bitwise for signed (& unsigned) 4 bits: 1000 = -8, 0111 = 7-8 + -8 = -16 = 0 1000 + 1000
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013 CONST POINTERS CONST POINTERS 4 ways to declare pointers in combination with const:!! int *ptr! const int *ptr!
More informationAssembly Language: Function Calls
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference
More informationProcedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27
Procedure Calls Young W. Lim 2016-11-05 Sat Young W. Lim Procedure Calls 2016-11-05 Sat 1 / 27 Outline 1 Introduction References Stack Background Transferring Control Register Usage Conventions Procedure
More informationSecond Part of the Course
CSC 2400: Computer Systems Towards the Hardware 1 Second Part of the Course Toward the hardware High-level language (C) assembly language machine language (IA-32) 2 High-Level Language g Make programming
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"
More informationCS241 Computer Organization Spring Loops & Arrays
CS241 Computer Organization Spring 2015 Loops & Arrays 2-26 2015 Outline! Loops C loops: while, for, do-while Translation to jump to middle! Arrays Read: CS:APP2 Chapter 3, sections 3.6 3.7 IA32 Overview
More informationQuestion 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110
Questions 1 Question 4.1 1: (Solution, p 5) Define the fetch-execute cycle as it relates to a computer processing a program. Your definition should describe the primary purpose of each phase. Question
More informationInstruction Set Architecture
CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter
More informationCISC 360 Instruction Set Architecture
CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"
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 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 informationWhat is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation
Compiler Construction SMD163 Lecture 8: Introduction to code generation Viktor Leijon & Peter Jonsson with slides by Johan Nordlander Contains material generously provided by Mark P. Jones What is a Compiler?
More informationAn Experience Like No Other. Stack Discipline Aug. 30, 2006
15-410 An Experience Like No Other Discipline Aug. 30, 2006 Bruce Maggs Dave Eckhardt Slides originally stolen from 15-213 15-410, F 06 Synchronization Registration If you're here but not registered, please
More informationStack Discipline Jan. 19, 2018
15-410 An Experience Like No Other Discipline Jan. 19, 2018 Dave Eckhardt Brian Railing Slides originally stolen from 15-213 1 15-410, S 18 Synchronization Registration The wait list will probably be done
More informationChapter 3 Machine-Level Programming II Control Flow
Chapter 3 Machine-Level Programming II Control Flow Topics Condition Codes Setting Testing Control Flow If-then-else Varieties of Loops Switch Statements Condition Codes Single Bit Registers CF Carry Flag
More informationAssembly Language: Function Calls. Goals of this Lecture. Function Call Problems
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning
More informationProcedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29
Procedure Calls Young W. Lim 2017-08-21 Mon Young W. Lim Procedure Calls 2017-08-21 Mon 1 / 29 Outline 1 Introduction Based on Stack Background Transferring Control Register Usage Conventions Procedure
More informationCPS104 Recitation: Assembly Programming
CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in
More informationCSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature
CSE2421 FINAL EXAM SPRING 2013 Name KEY Instructions: This is a closed-book, closed-notes, closed-neighbor exam. Only a writing utensil is needed for this exam. No calculators allowed. If you need to go
More informationCredits and Disclaimers
Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 2 nd Edition by Bryant and O'Hallaron
More informationIntel assembly language using gcc
QOTD Intel assembly language using gcc Assembly language programming is difficult. Make no mistake about that. It is not for wimps and weaklings. - Tanenbaum s 6th, page 519 These notes are a supplement
More informationFunction Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)
Function Calls COS 217 Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) 1 Goals of Today s Lecture Finishing introduction to assembly language o EFLAGS register
More informationCS429: Computer Organization and Architecture
CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: October 1, 2014 at 08:36 CS429 Slideset 7: 1 Topics
More informationCS , Fall 2002 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2002 Exam 1 October 8, 2002 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write
More informationCS61 Section Solutions 3
CS61 Section Solutions 3 (Week of 10/1-10/5) 1. Assembly Operand Specifiers 2. Condition Codes 3. Jumps 4. Control Flow Loops 5. Procedure Calls 1. Assembly Operand Specifiers Q1 Operand Value %eax 0x104
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 informationMachine-Level Programming I: Introduction
Machine-Level Programming I: Introduction Topics n Assembly Programmer s Execution Model n Accessing Information l Registers l Memory n Arithmetic operations IA32 Processors Totally Dominate Computer Market
More informationInstruction Set Architecture
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant adapted by Jason Fritts http://csapp.cs.cmu.edu CS:APP2e Hardware Architecture - using Y86 ISA For learning aspects
More informationCIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final
Spring 2012 Name: Page Points Score 1 14 2 7 3 6 4 5 5 5 6 5 7 10 8 11 9 10 10 9 11 8 12 10 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc.
More informationWinter Compiler Construction T11 Activation records + Introduction to x86 assembly. Today. Tips for PA4. Today:
Winter 2006-2007 Compiler Construction T11 Activation records + Introduction to x86 assembly Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Today ic IC Language Lexical Analysis
More informationAccess. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19
Access Young W. Lim 2017-06-10 Sat Young W. Lim Access 2017-06-10 Sat 1 / 19 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Data Movement Examples Young W. Lim Access 2017-06-10
More informationSystem Programming and Computer Architecture (Fall 2009)
System Programming and Computer Architecture (Fall 2009) Recitation 2 October 8 th, 2009 Zaheer Chothia Email: zchothia@student.ethz.ch Web: http://n.ethz.ch/~zchothia/ Topics for Today Classroom Exercise
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 informationCredits and Disclaimers
Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 2 nd Edition by Bryant and O'Hallaron
More informationSystems I. Machine-Level Programming I: Introduction
Systems I Machine-Level Programming I: Introduction Topics Assembly Programmerʼs Execution Model Accessing Information Registers IA32 Processors Totally Dominate General Purpose CPU Market Evolutionary
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 informationCPEG421/621 Tutorial
CPEG421/621 Tutorial Compiler data representation system call interface calling convention Assembler object file format object code model Linker program initialization exception handling relocation model
More information