Introduction to 8086 Assembly
|
|
- Maud Carr
- 5 years ago
- Views:
Transcription
1 Introduction to 8086 Assembly Lecture 13 Inline Assembly
2 Inline Assembly Compiler-dependent GCC -> GAS (the GNU assembler)
3 Intel Syntax => AT&T Syntax Registers: eax => %eax Immediates: 123 => $123 Memory: lbl1 => $lbl1 (address of lbl1) [lbl1] => lbl1 (content of lbl1)
4 Intel Syntax => AT&T Syntax Operand order reversed: mov dest, src => mov src, dest Operand size in command (movb,movw,movl, addb,addw,addl, etc): mov eax, ebx => movl %ebx, %eax add dl, ch => addb %ch, %dl Indirect addressing mov eax, [ebx] => movl (%ebx), %eax add ax, [ebx+4] => addw 4(%ebx), %ax mov dword [ebx], 1 => movl $1, (%ebx)
5 Compile C to AT&T Assembly gcc -S myprogram.c gcc -S -masm=att myprogram.c
6 More on Intel vs. AT&T Syntax
7 Basic inline assembly inline1.c inline2.c asm ("movl $1, %eax"); asm ("movl %eax, %ebx");
8 Basic inline assembly int a; inline3.c asm("movl $10, %eax; xchg %al, %ah"); asm("movl $10, %eax;" "xchg %al, %ah");
9 Global symbols (functions, global variables) inline4.c int g = 0; void print_sum(int a, int b) { printf("sum=%d\n",a+b); asm ("movl $110, g"); // NASM: mov dword [g], 110 printf("g=%d\n",g); asm ("pushl $10;" // NASM: push 10 "pushl $13;" // NASM: push 13 "call print_sum;" // NASM: call print_sum "addl $8, %esp;"); // NASM: add esp, 8
10 Global symbols (functions, global variables) inline4.c int g = 0; void print_sum(int a, int b) { printf("sum=%d\n",a+b); asm ("movl $110, g"); // NASM: mov dword [g], 110 printf("g=%d\n",g); asm ("pushl $10;" // NASM: push 10 "pushl $13;" // NASM: push 13 "call print_sum;" // NASM: call print_sum "addl $8, %esp;"); // NASM: add esp, 8
11 Global symbols (functions, global variables) inline4.c int g = 0; void print_sum(int a, int b) { printf("sum=%d\n",a+b); Do not use this technique! It might not alway work! asm ("movl $110, g"); // NASM: mov dword [g], 110 printf("g=%d\n",g); asm ("pushl $10;" // NASM: push 10 "pushl $13;" // NASM: push 13 "call print_sum;" // NASM: call print_sum "addl $8, %esp;"); // NASM: add esp, 8
12 Global symbols (functions, global variables) inline4.c int g = 0; void print_sum(int a, int b) { printf("sum=%d\n",a+b); what about local variables? asm ("movl $110, g"); // NASM: mov dword [g], 110 printf("g=%d\n",g); asm ("pushl $10;" // NASM: push 10 "pushl $13;" // NASM: push 13 "call print_sum;" // NASM: call print_sum "addl $8, %esp;"); // NASM: add esp, 8
13 How GCC handles inline assembly? inline5.c int a,b,c,d; scanf("%d %d", &a, &b); c = a+b; asm ("charand_command %ebx, %eax"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
14 How GCC handles inline assembly? inline5.c int a,b,c,d; scanf("%d %d", &a, &b); c = a+b; asm ("charand_command %ebx, %eax"); printf("a=%d b=%d, a+b=%d\n", a, b, c); No Error Compiling to Assembly!
15 How GCC handles inline assembly? int a,b,c,d; inline5.c movl addl movl : -16(%rbp), %eax %edx, %eax %eax, -12(%rbp) inline5.asm scanf("%d %d", &a, &b); charand_command %ebx, %eax c = a+b; asm ("charand_command %ebx, %eax"); printf("a=%d b=%d, a+b=%d\n", a, b, c); movl movl movl movl movl movl -16(%rbp), %edx -20(%rbp), %eax -12(%rbp), %ecx %eax, %esi $.LC1, %edi $0, %eax :
16 How GCC handles inline assembly? int a,b,c,d; scanf("%d %d", &a, &b); inline5.c : movl -16(%rbp), %eax addl %edx, %eax movl %eax, -12(%rbp) charand_command %ebx, %eax inline5.asm c = a+b; asm ("charand_command %ebx, %eax"); printf("a=%d b=%d, a+b=%d\n", a, b, c); movl movl movl movl movl movl -16(%rbp), %edx -20(%rbp), %eax -12(%rbp), %ecx %eax, %esi $.LC1, %edi $0, %eax : just inserting inline assembly
17 How GCC handles inline assembly? int a,b,c,d; scanf("%d %d", &a, &b); inline5.c GCC just inserts inline assembly! c = a+b; asm ("charand_command %ebx, %eax"); printf("a=%d b=%d, a+b=%d\n", a, b, c); Assembler Error!
18 How GCC handles inline assembly? int a,b,c,d; scanf("%d %d", &a, &b); c = a+b; inline5.c GCC just inserts inline assembly! It has no idea what inline assembly is doing! asm ("charand_command %ebx, %eax"); printf("a=%d b=%d, a+b=%d\n", a, b, c); Assembler Error!
19 How GCC handles inline assembly? int a,b,c,d; scanf("%d %d", &a, &b); c = a+b; inline5.c asm ("charand_command %ebx, %eax"); printf("a=%d b=%d, a+b=%d\n", a, b, c); GCC just inserts inline assembly! It has no idea what inline assembly is doing! => side effects! Assembler Error!
20 What can go wrong? inline6.c int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
21 What can go wrong? inline6.c int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
22 What can go wrong? Case 1: inline7.c int a,b; register int c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
23 What can go wrong? Case 1: inline7.c int a,b; register int c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c); gcc tries to use a register to store c
24 What can go wrong? Case 1: inline7.c int a,b; register int c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
25 What can go wrong? Case 1: inline7.c int a,b; register int c; scanf("%d %d", &a, &b); c = a+b; might or might not work as registers unexpectedly change. (worked in this case). asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
26 What can go wrong? Case 2: inline6.c int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); b.nasihatkon@kntu:lecture13$ gcc -m32 inline6.c &&./a.out 2 3 a=2 b=3, a+b=5 b.nasihatkon@kntu:lecture13$ gcc -m32 -O1 inline6.c &&./a.out 2 3 a=1 b=1, a+b=2 printf("a=%d b=%d, a+b=%d\n", a, b, c); turn on optimization
27 Solution 1: use volatile keyword inline8.c volatile int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); b.nasihatkon@kntu:lecture13$ gcc -m32 inline8.c &&./a.out 2 3 a=2 b=3, a+b=5 b.nasihatkon@kntu:lecture13$ gcc -m32 -O1 inline8.c &&./a.out 2 3 a=2 b=3, a+b=5 printf("a=%d b=%d, a+b=%d\n", a, b, c); turn on optimization
28 Solution 1: use volatile keyword inline8.c volatile int a,b,c; renders optimization useless! scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); b.nasihatkon@kntu:lecture13$ gcc -m32 inline8.c &&./a.out 2 3 a=2 b=3, a+b=5 b.nasihatkon@kntu:lecture13$ gcc -m32 -O1 inline8.c &&./a.out 2 3 a=2 b=3, a+b=5 printf("a=%d b=%d, a+b=%d\n", a, b, c); turn on optimization
29 Learn more about volatile keyword
30 Solution 2: tell compiler what registers are affected inline8.c volatile int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %eax;" "movl $1, %ebx;" "movl $1, %ecx;" "movl $1, %edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
31 Extended Inline Assembly asm ( assembly code : output registers : input registers : clobbered registers);
32 Solution 2: tell compiler what registers are affected inline9.c int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %%eax;" "movl $1, %%ebx;" "movl $1, %%ecx;" "movl $1, %%edx;" : : : "eax", "ebx", "ecx", "edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
33 Solution 2: tell compiler what registers are affected inline9.c int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %%eax;" "movl $1, %%ebx;" "movl $1, %%ecx;" "movl $1, %%edx;" : : : "eax", "ebx", "ecx", "edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c); use double % for registers
34 Solution 2: tell compiler what registers are affected inline9.c int a,b,c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %%eax;" "movl $1, %%ebx;" clobbered registers "movl $1, %%ecx;" "movl $1, %%edx;" : : : "eax", "ebx", "ecx", "edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
35 Solution 2: tell compiler what registers are affected inline9.c int a,b,c; gcc -m32 inline9.c &&./a.out scanf("%d %d", &a, &b); 2 3 a=2 b=3, a+b=5 c = a+b; b.nasihatkon@kntu:lecture13$ gcc -m32 -O1 inline9.c &&./a.out 2 3 a=2 b=3, a+b=5 asm ("movl $1, %%eax;" "movl $1, %%ebx;" "movl $1, %%ecx;" turn on optimization "movl $1, %%edx;" : : : "eax", "ebx", "ecx", "edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
36 Solution 2: tell compiler what registers are affected inline10.c int a,b; register int c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %%eax;" "movl $1, %%ebx;" "movl $1, %%ecx;" "movl $1, %%edx;" : : : "eax", "ebx", "ecx", "edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
37 Solution 2: tell compiler what registers are affected inline10.c int a,b; register int c; scanf("%d %d", &a, &b); c = a+b; asm ("movl $1, %%eax;" "movl $1, %%ebx;" "movl $1, %%ecx;" "movl $1, %%edx;" : : : "eax", "ebx", "ecx", "edx"); printf("a=%d b=%d, a+b=%d\n", a, b, c);
38 Give input to inline assembly #include <string.h> char msg[] = "Salaaaam Kako!\n"; int length = strlen(msg); inline11.c # sys_write movl $4, %eax # syscall no. movl $1, %ebx # file handle movl $msg, %ecx # message movl $13, %edx # length int $0x80 asm ("movl $4, %%eax;" // system call 4: sys_write "movl $1, %%ebx;" // file handle 1: stdout "int $0x80;" // syscall : : "c" (msg), "d" (length) : "eax", "ebx"); no outputs inputs (input constraints) clobbered registers
39 Give input to inline assembly #include <string.h> char msg[] = "Salaaaam Kako!\n"; int length = strlen(msg); inline11.c # sys_write movl $4, %eax # syscall no. movl $1, %ebx # file handle movl $msg, %ecx # message movl $13, %edx # length int $0x80 asm ("movl $4, %%eax;" // system call 4: sys_write "movl $1, %%ebx;" // file handle 1: stdout "int $0x80;" // syscall : : "c" (msg), "d" (length) : "eax", "ebx"); ecx edx
40 Give input to inline assembly #include <string.h> char msg[] = "Salaaaam Kako!\n"; int length = strlen(msg); inline11.c # sys_write movl $4, %eax # syscall no. movl $1, %ebx # file handle movl $msg, %ecx # message movl $13, %edx # length int $0x80 asm ("movl $4, %%eax;" // system call 4: sys_write "movl $1, %%ebx;" // file handle 1: stdout "int $0x80;" // syscall : : "c" (msg), "d" (length) : "eax", "ebx");
41 Registers a b c d S D r f eax, ax, al ebx, bx, bl ecx, cx, cl edx, dx, dl esi, si edi, di register a floating point register
42 Get output inline12.c int x = 12, y=13; printf("x=%d, y=%d\n", x,y); asm ("xchgl %%eax, %%ebx" : "=a" (x), "=b" (y) : "a" (x), "b" (y) : ); printf("x=%d, y=%d\n", x,y);
43 Get output inline12.c int x = 12, y=13; printf("x=%d, y=%d\n", x,y); asm ("xchgl %%eax, %%ebx" : "=a" (x), "=b" (y) : "a" (x), "b" (y) : ); outputs inputs printf("x=%d, y=%d\n", x,y);
44 Get output inline12.c int x = 12, y=13; printf("x=%d, y=%d\n", x,y); asm ("xchgl %%eax, %%ebx" : "=a" (x), "=b" (y) : "a" (x), "b" (y) : ); outputs inputs printf("x=%d, y=%d\n", x,y);
45 Get output inline13.c int x = 12, y=13; printf("x=%d, y=%d\n", x,y); asm ("xchgl %0, %1" : "=r" (x), "=r" (y) : "0" (x), "1" (y) : ); outputs inputs printf("x=%d, y=%d\n", x,y);
46 Get output inline13.c int x = 12, y=13; printf("x=%d, y=%d\n", x,y); asm ("xchgl %0, %1" : "=r" (x), "=r" (y) : "0" (x), "1" (y) : ); outputs inputs printf("x=%d, y=%d\n", x,y);
47 Use Intel Syntax with GCC Modern versions of GAS support Intel Syntax The GAS GNU Syntax is a bit different from NASM Syntax the.intel_syntax and.att_syntax directives
48 Use Intel Syntax with GCC Put your code between the.intel_syntax (or.intel_syntax noprefix) and.att_syntax directives Better solution: Compile with -masm=intel gcc option.
49 Use Intel Syntax with GCC #include <string.h> inline14.c char msg[] = "Salaaaam Kako!\n"; int length = strlen(msg); asm ("mov eax, 4;" // system call 4: sys_write "mov ebx, 1;" // file handle 1: stdout "int 0x80;" // syscall : : "c" (msg), "d" (length) : "eax", "ebx");
50 Use Intel Syntax with GCC #include <string.h> inline14.c char msg[] = "Salaaaam Kako!\n"; int length = strlen(msg); asm ("mov eax, 4;" // system call 4: sys_write "mov ebx, 1;" // file handle 1: stdout "int 0x80;" // syscall : : "c" (msg), "d" (length) : "eax", "ebx");
51 Be careful with compiler optimization! inline15.c int count = 0; asm ("mov eax, 0" : : : "eax"); for (int i = 0; i < 10; i++) { asm ("inc eax;" : "=a" (count) : : ); printf("count=%d\n", count);
52 Be careful with compiler optimization! inline15.c int count = 0; asm ("mov eax, 0" : : : "eax"); for (int i = 0; i < 10; i++) { asm ("inc eax;" : "=a" (count) : : ); printf("count=%d\n", count);
53 volatile keyword for inline assembly inline16.c int count = 0; asm volatile ("mov eax, 0" : : : "eax"); for (int i = 0; i < 10; i++) { asm volatile ("inc eax;" : "=a" (count) : : ); printf("count=%d\n", count);
54 volatile keyword for inline assembly inline16.c int count = 0; asm volatile ("mov eax, 0" : : : "eax"); for (int i = 0; i < 10; i++) { asm volatile ("inc eax;" : "=a" (count) : : ); printf("count=%d\n", count);
55 Inline assembly is compiler-dependent Microsoft Visual C
56 References & further reading
Credits 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 3 nd Edition by Bryant and O'Hallaron
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 informationx86 assembly CS449 Spring 2016
x86 assembly CS449 Spring 2016 CISC vs. RISC CISC [Complex instruction set Computing] - larger, more feature-rich instruction set (more operations, addressing modes, etc.). slower clock speeds. fewer general
More informationX86 Addressing Modes Chapter 3" Review: Instructions to Recognize"
X86 Addressing Modes Chapter 3" Review: Instructions to Recognize" 1 Arithmetic Instructions (1)! Two Operand Instructions" ADD Dest, Src Dest = Dest + Src SUB Dest, Src Dest = Dest - Src MUL Dest, Src
More informationCS Bootcamp x86-64 Autumn 2015
The x86-64 instruction set architecture (ISA) is used by most laptop and desktop processors. We will be embedding assembly into some of our C++ code to explore programming in assembly language. Depending
More informationLecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86
Lecture 15 Intel Manual, Vol. 1, Chapter 3 Hampden-Sydney College Fri, Mar 6, 2009 Outline 1 2 Overview See the reference IA-32 Intel Software Developer s Manual Volume 1: Basic, Chapter 3. Instructions
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 informationAssembly Language Each statement in an assembly language program consists of four parts or fields.
Chapter 3: Addressing Modes Assembly Language Each statement in an assembly language program consists of four parts or fields. The leftmost field is called the label. - used to identify the name of a memory
More informationx86 Assembly Crash Course Don Porter
x86 Assembly Crash Course Don Porter Registers ò Only variables available in assembly ò General Purpose Registers: ò EAX, EBX, ECX, EDX (32 bit) ò Can be addressed by 8 and 16 bit subsets AL AH AX EAX
More informationCS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017
CS 31: Intro to Systems ISAs and Assembly Martin Gagné Swarthmore College February 7, 2017 ANNOUNCEMENT All labs will meet in SCI 252 (the robot lab) tomorrow. Overview How to directly interact with hardware
More informationThe x86 Architecture
The x86 Architecture Lecture 24 Intel Manual, Vol. 1, Chapter 3 Robb T. Koether Hampden-Sydney College Fri, Mar 20, 2015 Robb T. Koether (Hampden-Sydney College) The x86 Architecture Fri, Mar 20, 2015
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 informationCSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs
CSC 2400: Computer Systems Towards the Hardware: Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32)
More informationAccess. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18
Access Young W. Lim 2017-01-27 Fri Young W. Lim Access 2017-01-27 Fri 1 / 18 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Young W. Lim Access 2017-01-27 Fri 2 / 18 Based
More informationMODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE
EXERCISE 9. Determine the mod bits from Figure 7-24 and write them in Table 7-7. MODE (mod) FIELD CODES mod 00 01 10 DESCRIPTION MEMORY MODE: NO DISPLACEMENT FOLLOWS MEMORY MODE: 8-BIT DISPLACEMENT MEMORY
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 informationUMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.
Intel Assembly Format of an assembly instruction: LABEL OPCODE OPERANDS COMMENT DATA1 db 00001000b ;Define DATA1 as decimal 8 START: mov eax, ebx ;Copy ebx to eax LABEL: Stores a symbolic name for the
More informationCSC 8400: Computer Systems. Machine-Level Representation of Programs
CSC 8400: Computer Systems Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 Compilation Stages
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 informationx86 assembly CS449 Fall 2017
x86 assembly CS449 Fall 2017 x86 is a CISC CISC (Complex Instruction Set Computer) e.g. x86 Hundreds of (complex) instructions Only a handful of registers RISC (Reduced Instruction Set Computer) e.g. MIPS
More informationx86 architecture et similia
x86 architecture et similia 1 FREELY INSPIRED FROM CLASS 6.828, MIT A full PC has: PC architecture 2 an x86 CPU with registers, execution unit, and memory management CPU chip pins include address and data
More informationRegisters. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth
Registers Ray Seyfarth September 8, 2011 Outline 1 Register basics 2 Moving a constant into a register 3 Moving a value from memory into a register 4 Moving values from a register into memory 5 Moving
More informationCS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015
CS165 Computer Security Understanding low-level program execution Oct 1 st, 2015 A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns
More informationW4118: PC Hardware and x86. Junfeng Yang
W4118: PC Hardware and x86 Junfeng Yang A PC How to make it do something useful? 2 Outline PC organization x86 instruction set gcc calling conventions PC emulation 3 PC board 4 PC organization One or more
More informationCSCI 192 Engineering Programming 2. Assembly Language
CSCI 192 Engineering Programming 2 Week 5 Assembly Language Lecturer: Dr. Markus Hagenbuchner Slides by: Igor Kharitonenko and Markus Hagenbuchner Room 3.220 markus@uow.edu.au UOW 2010 24/08/2010 1 C Compilation
More informationAssembly Language: IA-32 Instructions
Assembly Language: IA-32 Instructions 1 Goals of this Lecture Help you learn how to: Manipulate data of various sizes Leverage more sophisticated addressing modes Use condition codes and jumps to change
More informationCMSC Lecture 03. UMBC, CMSC313, Richard Chang
CMSC Lecture 03 Moore s Law Evolution of the Pentium Chip IA-32 Basic Execution Environment IA-32 General Purpose Registers Hello World in Linux Assembly Language Addressing Modes UMBC, CMSC313, Richard
More informationPutting the pieces together
IBM developerworks : Linux : Linux articles All of dw Advanced search IBM home Products & services Support & downloads My account Inline assembly for x86 in Linux e-mail it! Contents: GNU assembler syntax
More informationBinghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections
x86 Assembler Computer Systems: Sections 3.1-3.5 Disclaimer I am not an x86 assembler expert. I have never written an x86 assembler program. (I am proficient in IBM S/360 Assembler and LC3 Assembler.)
More informationMACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION
MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics:
More informationInstruction Set Architectures
Instruction Set Architectures! ISAs! Brief history of processors and architectures! C, assembly, machine code! Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface
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 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 informationCS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016
CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between
More informationInstruction Set Architectures
Instruction Set Architectures ISAs Brief history of processors and architectures C, assembly, machine code Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface contain?
More informationCS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018
CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College September 25, 2018 Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between programmer
More informationIntro to GNU Assembly Language on Intel Processors
Intro to GNU Assembly Language on Intel Processors Prof. Godfrey C. Muganda North Central College February 29, 2004 1 Basic Machine Architecture This family of processors has a 32-bit architecture: its
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 informationX86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson
X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Time ACL-based permissions (UNIX style) Read, Write, execute can be restricted on users and groups
More informationSystem calls and assembler
System calls and assembler Michal Sojka sojkam1@fel.cvut.cz ČVUT, FEL License: CC-BY-SA 4.0 System calls (repetition from lectures) A way for normal applications to invoke operating system (OS) kernel's
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 informationReverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher
Reverse Engineering II: Basics Gergely Erdélyi Senior Antivirus Researcher Agenda Very basics Intel x86 crash course Basics of C Binary Numbers Binary Numbers 1 Binary Numbers 1 0 1 1 Binary Numbers 1
More informationIntroduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration. Xeno Kovah 2014 xkovah at gmail
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah 2014 xkovah at gmail All materials is licensed under a Creative Commons Share Alike license. http://creativecommons.org/licenses/by-sa/3.0/
More informationReverse Engineering II: The Basics
Reverse Engineering II: The Basics Gergely Erdélyi Senior Manager, Anti-malware Research Protecting the irreplaceable f-secure.com Binary Numbers 1 0 1 1 - Nibble B 1 0 1 1 1 1 0 1 - Byte B D 1 0 1 1 1
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 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 informationInterfacing Compiler and Hardware. Computer Systems Architecture. Processor Types And Instruction Sets. What Instructions Should A Processor Offer?
Interfacing Compiler and Hardware Computer Systems Architecture FORTRAN 90 program C++ program Processor Types And Sets FORTRAN 90 Compiler C++ Compiler set level Hardware 1 2 What s Should A Processor
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 informationmith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut
mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut dthiebaut@smith.edu Homework Solutions Outline Review Hexdump Pentium Data Registers 32-bit, 16-bit and 8-bit quantities (registers
More informationGCC and Assembly language. GCC and Assembly language. Consider an example (dangeous) foo.s
GCC and Assembly language slide 1 GCC and Assembly language slide 2 during the construction of an operating system kernel, microkernel, or embedded system it is vital to be able to access some of the microprocessor
More informationCS642: Computer Security
X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Week ACL- based permissions (UNIX style) Read, Write, execute can be restricted on users and groups
More informationEEM336 Microprocessors I. Addressing Modes
EEM336 Microprocessors I Addressing Modes Introduction Efficient software development for the microprocessor requires a complete familiarity with the addressing modes employed by each instruction. This
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 03, SPRING 2013
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 03, SPRING 2013 TOPICS TODAY Moore s Law Evolution of Intel CPUs IA-32 Basic Execution Environment IA-32 General Purpose Registers
More informationThe von Neumann Machine
The von Neumann Machine 1 1945: John von Neumann Wrote a report on the stored program concept, known as the First Draft of a Report on EDVAC also Alan Turing Konrad Zuse Eckert & Mauchly The basic structure
More information6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:
Introduction Efficient software development for the microprocessor requires a complete familiarity with the addressing modes employed by each instruction. This chapter explains the operation of the stack
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 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 informationAssembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Basic Execution Environment RAX RBX RCX RDX RSI RDI RBP RSP R8 R9 R10
More informationx86 Programming I CSE 351 Winter
x86 Programming I CSE 351 Winter 2017 http://xkcd.com/409/ Administrivia Lab 2 released! Da bomb! Go to section! No Luis OH Later this week 2 Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals
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 informationToday: Machine Programming I: Basics
Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics: Registers, operands, move Intro to x86-64 1 Intel x86 Processors Totally dominate
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 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 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 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 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 informationLAB 5 Arithmetic Operations Simple Calculator
LAB 5 Arithmetic Operations Simple Calculator Objective: Practice arithmetic operation for the 80x86, such as add, subtract, multiple, divide, and mod. When dealing with the multiply, divide, and mod instructions
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 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 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 informationCS241 Computer Organization Spring Introduction to Assembly
CS241 Computer Organization Spring 2015 Introduction to Assembly 2-05 2015 Outline! Rounding floats: round-to-even! Introduction to Assembly (IA32) move instruction (mov) memory address computation arithmetic
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 informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 21: Generating Pentium Code 10 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Simple Code Generation Three-address code makes it
More informationCarnegie Mellon. 5 th Lecture, Jan. 31, Instructors: Todd C. Mowry & Anthony Rowe
Machine Level Programming I: Basics 15 213/18 213: 213: Introduction to Computer Systems 5 th Lecture, Jan. 31, 2012 Instructors: Todd C. Mowry & Anthony Rowe 1 Today: Machine Programming gi: Basics History
More informationInline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing
Inline Assembler Willi-Hans Steeb and Yorick Hardy International School for Scientific Computing e-mail: steebwilli@gmail.com Abstract We provide a collection of inline assembler programs. 1 Using the
More informationModule 3 Instruction Set Architecture (ISA)
Module 3 Instruction Set Architecture (ISA) I S A L E V E L E L E M E N T S O F I N S T R U C T I O N S I N S T R U C T I O N S T Y P E S N U M B E R O F A D D R E S S E S R E G I S T E R S T Y P E S O
More informationComputer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)
Part 2 Computer Processors Processors The Brains of the Box Computer Processors Components of a Processor The Central Processing Unit (CPU) is the most complex part of a computer In fact, it is the computer
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 informationx86 64 Programming I CSE 351 Autumn 2018 Instructor: Justin Hsia
x86 64 Programming I 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 informationComputer Architecture and System Programming Laboratory. TA Session 3
Computer Architecture and System Programming Laboratory TA Session 3 Stack - LIFO word-size data structure STACK is temporary storage memory area register points on top of stack (by default, it is highest
More informationChapter 3: Addressing Modes
Chapter 3: Addressing Modes Chapter 3 Addressing Modes Note: Adapted from (Author Slides) Instructor: Prof. Dr. Khalid A. Darabkh 2 Introduction Efficient software development for the microprocessor requires
More informationMACHINE-LEVEL PROGRAMMING I: BASICS
MACHINE-LEVEL PROGRAMMING I: BASICS CS 429H: SYSTEMS I Instructor: Emmett Witchel Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics:
More informationFunction Call Convention
Function Call Convention Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona Tel +41 55 214 41 60 Fax +41 55 214 41 61 team@csnc.ch www.csnc.ch Content Intel Architecture Memory Layout
More informationADDRESSING MODES. Operands specify the data to be used by an instruction
ADDRESSING MODES Operands specify the data to be used by an instruction An addressing mode refers to the way in which the data is specified by an operand 1. An operand is said to be direct when it specifies
More informationComputer Architecture and Assembly Language. Practical Session 3
Computer Architecture and Assembly Language Practical Session 3 Advanced Instructions division DIV r/m - unsigned integer division IDIV r/m - signed integer division Dividend Divisor Quotient Remainder
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 informationLecture 3: Instruction Set Architecture
Lecture 3: Instruction Set Architecture Interface Software/compiler instruction set hardware Design Space of ISA Five Primary Dimensions Number of explicit operands ( 0, 1, 2, 3 ) Operand Storage Where
More informationProgram Exploitation Intro
Program Exploitation Intro x86 Assembly 04//2018 Security 1 Univeristà Ca Foscari, Venezia What is Program Exploitation "Making a program do something unexpected and not planned" The right bugs can be
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 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 informationx86 Assembly Tutorial COS 318: Fall 2017
x86 Assembly Tutorial COS 318: Fall 2017 Project 1 Schedule Design Review: Monday 9/25 Sign up for 10-min slot from 3:00pm to 7:00pm Complete set up and answer posted questions (Official) Precept: Monday
More informationMachine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Machine-level Representation of Programs Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Program? 짬뽕라면 준비시간 :10 분, 조리시간 :10 분 재료라면 1개, 스프 1봉지, 오징어
More informationFunction Calls and Stack
Function Calls and Stack Philipp Koehn 16 April 2018 1 functions Another Example 2 C code with an undefined function int main(void) { int a = 2; int b = do_something(a); urn b; } This can be successfully
More informationAssembly Language Lab # 9
Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2011 Assembly Language Lab # 9 Stacks and Subroutines Eng. Doaa Abu Jabal Assembly Language Lab # 9 Stacks and Subroutines
More informationI/O Functions. Register Names and Purpose. Outline MIPS Assembly Language Programming. MIPS ALP, OISC and X86 ALP. SPIM: Hello World ALP 3/18/2015
MIPS ALP, OISC and X86 ALP A. Sahu CSE, IIT Guwahati Outline MIPS Assembly Language Programming Stack, Call/Return Recursive Call : Factorial Example OISC : One Instruction Set Computer X86 : CISC ALP,
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 informationMachine Level Programming I: Basics
Carnegie Mellon Machine Level Programming I: Basics Kai Shen Why do I care for machine code? Chances are, you ll never write programs in machine code Compilers are much better & more patient than you are
More informationAssembler Programming. Lecture 2
Assembler Programming Lecture 2 Lecture 2 8086 family architecture. From 8086 to Pentium4. Registers, flags, memory organization. Logical, physical, effective address. Addressing modes. Processor Processor
More informationIntroduction to Machine/Assembler Language
COMP 40: Machine Structure and Assembly Language Programming Fall 2017 Introduction to Machine/Assembler Language Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah
More informationThe von Neumann Machine
The von Neumann Machine 1 1945: John von Neumann Wrote a report on the stored program concept, known as the First Draft of a Report on EDVAC also Alan Turing Konrad Zuse Eckert & Mauchly The basic structure
More information