IA32 Assembly Programming in Linux

Slides:



Advertisements
Similar presentations
University of Washington Procedures and Stacks II The Hardware/Software Interface CSE351 Winter 2013.
Advertisements

Dynamic Memory Management CAS CS210 Ying Ye Boston University.
CS 241 Section Week #5 2/23/12. 2 Topics This Section MP4 overview Function Pointers Pthreads File I/O.
The ‘system-call’ interface We see how an application program can invoke privileged kernel services.
Ways to read data from disk to memory Tan Li. read, write read, write -- low level file access, it's an operation between two file discriptors. SYNOPSIS.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
1 Reminders Project 1 due tomorrow by 6:00 Office hours in 006 today at 4:30 Start thinking about project groups (3 people) for the rest of the quarter.
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
CSE 451 Section 4 Project 2 Design Considerations.
September 22, 2014 Pengju (Jimmy) Jin Section E
Practical Session 8 Computer Architecture and Assembly Language.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
Languages and tools. BY SA machine code.
CS162B: Assembly and C Jacob T. Chan. Objectives ▪ System calls ▪ Relation of System calls to Assembly and C ▪ Special System Calls (exit, write, print,
Implementing system calls in the Y86 model Soumava Ghosh.
Assembly Questions תרגול 12.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Lecture-1 Compilation process
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
6. More on Pointers 14 th September IIT Kanpur C Course, Programming club, Fall
Implementing System Calls CS552 Kartik Gopalan. CS552/BU/Spring2008 Steps in writing a system call 1.Create an entry for the system call in the kernel’s.
System Calls. The Linux we use is: Linux-Mandrake 7.0. In this project, you are going to change some kernel files and recompile the kernel. After you.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
Stack-based buffer overflows Yves Younan DistriNet, Department of Computer Science Katholieke Universiteit Leuven Belgium
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Practical Session 5 Computer Architecture and Assembly Language.
Compiler Construction Code Generation Activation Records
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Assembly 08. Outline Local Labels Jump Lengths External Libraries Macros 1.
Practical Session 4. GNU Linker Links object files together Used as the last step in the compilation We will use ld to link together compiled assembly.
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Practical Session 5 Computer Architecture and Assembly Language.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University.
Pointers and Classes.
Computer Architecture and Assembly Language
Practical Session 5.
Credits and Disclaimers
Credits and Disclaimers
Homework Reading Machine Projects Labs PAL, pp ,
Exploiting & Defense Day 2 Recap
Homework Reading Machine Projects Labs
Homework In-line Assembly Code Machine Language
Assembly Language Programming V: In-line Assembly Code
14th September IIT Kanpur
Assembly Language Programming I: Introduction
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Assembly Language Programming II: C Compiler Calling Sequences
The Runtime Environment
Machine-Level Programming III: Procedures Sept 18, 2001
Discussions on HW2 Objectives
The Runtime Environment
Discussions on HW2 Objectives
C structures and Compilation to IA32
Functions Lecture 5.
02/02/10 20:53 Assembly Questions תרגול 12 1.
Implementing System Calls
Credits and Disclaimers
Credits and Disclaimers
Credits and Disclaimers
Computer Architecture and Assembly Language
Presentation transcript:

IA32 Assembly Programming in Linux 작성자: 박창범

Sample Code (AT&T syntax) /* ssize_t write(int fd, const void *buf, size_t count); */ /* write(fileno(stdout), "hello", 6); */ .include "defines.h" .data hello: .string "hello world\n" .text .globl _start _start: movl $SYS_write,%eax // SYS_write = 4 movl $STDOUT,%ebx // fd = fileno(stdio) movl $hello,%ecx // buf = str movl $12,%edx // count = 0x6 int $0x80 movl $SYS_exit,%eax xorl %ebx,%ebx ret Section Declaration .data section var_name: .var_type [value] .text section .globl function_name function_name: [codes]

System Call System call number goes into %eax The args go in %ebx,%ecx,%edx,%esi,%edi in order The return value of the syscall is stored in %eax Calling: int $0x80 The syscall number can be found in /usr/include/sys/syscall.h The macros are defined as SYS_<syscall name> i.e. SYS_exit, SYS_close, in provided sample code and “defines.h”

Syscalls with > 5 args Same as Syscalls with < 6 args but except argument passing the args are arranged in memory and the pointer to the first arg is stored in %ebx /* mappedptr=mmap(NULL,filelen,PROT_READ,MAP_SHARED,fd,0); */ movl %edx,(%esp) movl %eax,4(%esp) movl $PROT_READ,8(%esp) movl $MAP_SHARED,12(%esp) movl $fd,%ebx movl (%ebx),%eax movl %eax,16(%esp) movl %edx,20(%esp) movl $SYS_mmap,%eax movl %esp,%ebx int $0x80

Mixing C-Assembly Make object file Use Makefile %> gcc –c xxx.S Use Makefile We can use another assembler GAS(AT&T syntax), NASM(Intel syntax)

Tips Use gcc –S xxx.c We can get xxx.S Referring assembly code generated by compiler could be helpful (don’t just copy generated code)

References http://www.linuxassembly.org/ http://www.linuxassembly.org/howto/Assembly-HOWTO.html http://linuxassembly.org/articles/linasm.html