CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

Size: px
Start display at page:

Download "CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015"

Transcription

1 CS165 Computer Security Understanding low-level program execution Oct 1 st, 2015

2 A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila 2

3 What will executing this program do? #include <stdio.h> void answer(char *name, int x){ } printf( %s, the answer is: %d\n, name, x); void main(int argc, char *argv[]){ } int x; x = ; answer(argv[1], x); 42.c 3

4 To answer the question Is this program safe/secure/vulnerable? We need to know What will executing this program do? 4

5 To answer the question Is this program safe/secure/vulnerable? We need to know What will executing this program do? Understanding the compiler and machine semantics are key. 5

6 Agenda Compilation Workflow x86 Execution Model Basic Execution Memory Operation Control Flow Memory Organization 6

7 Agenda Compilation Workflow x86 Execution Model Basic Execution Memory Operation Control Flow Memory Organization NEXT 7

8 void answer(char *name, int x){ } printf( %s, the answer is: %d\n, name, x); void main(int argc, char *argv[]){ } int x; x = ; answer(argv[1], x); 8

9 void answer(char *name, int x){ } printf( %s, the answer is: %d\n, name, x); void main(int argc, char *argv[]){ } int x; x = ; answer(argv[1], x); Compilation

10 void answer(char *name, int x){ } printf( %s, the answer is: %d\n, name, x); void main(int argc, char *argv[]){ } int x; x = ; answer(argv[1], x); Compilation Alice

11 void answer(char *name, int x){ } printf( %s, the answer is: %d\n, name, x); void main(int argc, char *argv[]){ } int x; x = ; answer(argv[1], x); Compilation Alice Alice, the answer is

12 void answer(char *name, int x){ } printf( %s, the answer is: %d\n, name, x); void main(int argc, char *argv[]){ } int x; x = ; answer(argv[1], x); Compilation Alice The compiler and machine determines the semantics Alice, the answer is

13 Compiled Code Input Source Language Compilation Target Language Output Terminology: Target language = machine-readable code = binary instructions 13

14 Interpreted Code Source Language Input Interpretation Output 14

15 Source Language Compilation Target Language 15

16 Source Language Compilation Target Language 4393.c in C 4393 in x86 16

17 Source Language Compilation Target Language 4393.c in C 4393 in x86 Preprocessor (cpp) Compiler (cc1) Assembler (as) Linker (ld) 4393.c

18 Source Preprocessor (cpp) Source Compiler (cc1) Assembler (as) Linker (ld) $ cpp #include <stdio.h> void answer(char *name, int x){ }... printf( %s, the answer is: %d\n, name, x); #include expansion #define substitution 18

19 Preprocessor (cpp) Compiler (cc1) Source Source Assembly Assembler (as) Linker (ld) $ gcc -S #include <stdio.h> void answer(char *name, int x){ }... printf( %s, the answer is: %d\n, name, x); Creates Assembly 19

20 gcc S 4393.c outputs 4393.s _answer: Leh_func_begin1: pushq %rbp Ltmp0: movq %rsp, %rbp Ltmp1: subq $16, %rsp Ltmp2: movl %esi, %eax movq %rdi, -8(%rbp) movl %eax, -12(%rbp) movq -8(%rbp), %rax... 20

21 Preprocessor (cpp) Compiler (cc1) Assembler (as) Source Source Assembly Binary Linker (ld) $ as <options> _answer: Leh_func_begin1: pushq %rbp Ltmp0: movq %rsp, %rbp Ltmp1: subq $16, %rsp Ltmp2: movl %esi, %eax movq %rdi, -8(%rbp) movl %eax, -12(%rbp) movq -8(%rbp), %rax... Creates object code 4393.s 21

22 Preprocessor (cpp) Compiler (cc1) Assembler (as) Linker (ld) Source Source Assembly Binary Binary $ ld <options> o Links with other files and libraries to produce an exe 22

23 Disassembling Today: using objdump (part of binutils) objdump D <exe> If you compile with -g, you will see more information objdump D S 23

24 Binary Code Segment (.text) Data Segment (.data)... The program binary (aka executable) Final executable consists of several segments Text for code written Read-only data for constants such as hello world and globals... 24

25 Binary Code Segment (.text) Data Segment (.data)... The program binary (aka executable) Final executable consists of several segments Text for code written Read-only data for constants such as hello world and globals... $ readelf S <file> 25

26 Machine Instruction Example int t = x+y; addl 8(%ebp),%eax Similar to expression: x += y More precisely: int eax; int *ebp; eax += *(ebp[2]) 0x80483ca: C Code Add two signed integers Assembly Add 2 4-byte integers Long words in GCC parlance Same instruction whether signed or unsigned Operands: x: Register %eax y: Memory M[%ebp+8] t: Register %eax Object Code Return function value in %eax 3-byte instruction Stored at address 0x80483ca 26

27 Agenda Compilation Workflow x86 Execution Model Basic Execution Memory Operation Control Flow Memory Organization NEXT 27

28 Basic Execution Binary Code Data... Processor File system Process Memory 28

29 Basic Execution Binary Code Data... Processor Stack File system Heap Process Memory 29

30 Basic Execution Binary Code Data... Stack Fetch, decode, execute Processor File system Heap Process Memory 30

31 Basic Execution Binary Code Data... Stack Fetch, decode, execute Processor File system Heap Process Memory read and write 31

32 x86 Processor EIP EFLAGS EAX EDX ECX EBX ESP EBP ESI EDI 32

33 x86 Processor EAX EDX ECX EIP EBX EFLAGS ESP EBP ESI EDI Address of next instruction 33

34 x86 Processor EAX EDX ECX EIP EBX EFLAGS ESP EBP ESI EDI Address of next instruction Condition codes 34

35 x86 Processor EAX EDX ECX EIP EBX EFLAGS ESP EBP ESI EDI Address of next instruction Condition codes General Purpose 35

36 Registers have up to 4 addressing modes EAX 1. Lower 8 bits 2. Mid 8 bits 3. Lower 16 bits 4. Full register EDX ECX EBX ESP EBP ESI EDI 36

37 EAX, EDX, ECX, and EBX EAX EDX ECX EBX AH DH CH BH AL DL CL BL Bit bit registers (three letters) Lower bits (bits 0-7) (two letters with L suffix) Mid-bits (bits 8-15) (two letters with H suffix) EAX EDX ECX EBX AX DX CX BX Bit Lower 16 bits (bits 0-15) (2 letters with X suffix) 37

38 ESP, EBP, ESI, and EDI EAX AH AL ESP SP EDX DH DL EBP BP ECX CH CL ESI SI EBX BH BL EDI DI Bit Lower 16 bits (bits 0-15) (2 letters) 38

39 x86 Implementation instruction instruction instruction EIP is incremented after each instruction Instructions are different length EIP modified by CALL, RET, JMP, and cond. JMP data data data

40 x86 Instruction Set Instructions classes: Data Movement: MOV, PUSH, POP, Arithmetic: TEST, SHL, ADD, I/O: IN, OUT, Control: JMP, JZ, JNZ, CALL, RET String: REP, MOVSB, System: IRET, INT, Volume 2A: Instruction Set Reference, A-M Volume 2B: Instruction Set Reference, N-Z Intel syntax: OP DST, SRC AT&T (gcc/gas) syntax: OP SRC, DST 40

41 Basic Ops and AT&T vs Intel Syntax source first destination first Meaning AT&T Intel ebx = eax eax = eax + ebx movl %eax, %ebx mov ebx, eax addl %ebx, %eax add eax, ebx ecx = ecx << 2 shl $2, %ecx shl ecx, 2 AT&T is at odds with assignment order. It is the default for objdump, and traditionally used for UNIX. Intel order mirrors assignment. Windows traditionally uses Intel, as is available via the objdump -M intel command line option 41

42 Agenda Compilation Workflow x86 Execution Model Basic Execution Memory Operation Control Flow Memory Organization NEXT 42

43 x86: Byte Addressable 43

44 x86: Byte Addressable... Address 3 holds 1 byte Address 2 holds 1 byte Address 1 holds 1 byte Address 0 holds 1 byte 44

45 x86: Byte Addressable It s convention:... lower address at the bottom Address 3 holds 1 byte Address 2 holds 1 byte Address 1 holds 1 byte Address 0 holds 1 byte 45

46 x86: Byte Addressable... I can fetch bytes at any address Address 3 holds 1 byte Address 2 holds 1 byte Address 1 holds 1 byte Address 0 holds 1 byte 46

47 x86: Byte Addressable... I can fetch bytes at any address Address 3 holds 1 byte Address 2 holds 1 byte Address 1 holds 1 byte Address 0 holds 1 byte Memory is just like using an array! 47

48 x86: Byte Addressable... I can fetch bytes at any address Address 3 holds 1 byte Address 2 holds 1 byte Address 1 holds 1 byte Address 0 holds 1 byte Memory is just like using an array! Alternative: Word addressable Example: For 32-bit word size, it s valid to fetch 4 bytes from Mem[0], but not Mem[6] since 6 is not a multiple of 4. 48

49 x86: Addressing bytes Addresses are indicated by operands that have a bracket [] or paren (), for Intel vs. AT&T, resp. 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0x00 Addr

50 x86: Addressing bytes Addresses are indicated by operands that have a bracket [] or paren (), for Intel vs. AT&T, resp. What does mov dl, [al] do? 0xff 0xee 0xdd 0xcc Addr 6 Register Value 0xbb eax edx ebx 0x3 0x0 0x5 0xaa 0x

51 x86: Addressing bytes Addresses are indicated by operands that have a bracket [] or paren (), for Intel vs. AT&T, resp. What does mov dl, [al] do? 0xff 0xee 0xdd Addr 6 Register Value Moves 0xcc into dl 0xcc 0xbb eax edx ebx 0x3 0x0 0x5 0xaa 0x

52 x86: Addressing bytes Addresses are indicated by operands that have a bracket [] or paren (), for Intel vs. AT&T, resp. What does mov edx, [eax] do? 0xff 0xee 0xdd 0xcc Addr 6 Register Value 0xbb eax edx ebx 0x3 0xcc 0x5 0xaa 0x

53 x86: Addressing bytes Addresses are indicated by operands that have a bracket [] or paren (), for Intel vs. AT&T, resp. What does mov edx, [eax] do? 0xff 0xee 0xdd 0xcc Addr 6 Register eax edx ebx Value 0x3 0xcc 0x5 Which 4 bytes get moved, and which is the LSB in edx? 0xbb 0xaa 0x

54 Endianess Endianess: Order of individually addressable units Little Endian: Least significant byte first so address a goes in littlest byte (e.g., AL), a+1 in the next (e.g., AH), etc. 0xff 0xee 0xdd 0xcc Addr 6 Register Value 0xbb eax edx ebx 0x3 0xcc 0x5 0xaa 0x

55 mov edx, [eax] Register eax edx ebx EDX Value 0x3 0xcc 0x5 Bit 0 0xff 0xee 0xdd 0xcc Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 55 6

56 mov edx, [eax] Register eax edx ebx EDX Value 0x3 0xcc 0x5 0xcc Bit 0 0xff 0xee 0xdd 0xcc Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 56 6

57 mov edx, [eax] Register eax edx ebx EDX Value 0x3 0xcc 0x5 0xdd 0xcc Bit 0 0xff 0xee 0xdd 0xcc Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 57 6

58 mov edx, [eax] Register eax edx ebx EDX Value 0x3 0xcc 0x5 0xee 0xdd 0xcc Bit 0 0xff 0xee 0xdd 0xcc Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 58 6

59 mov edx, [eax] Register eax edx ebx EDX Value 0x3 0xcc 0x5 0xff 0xee 0xdd 0xcc Bit 0 0xff 0xee 0xdd 0xcc Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 59 6

60 mov edx, [eax] Register eax edx ebx EDX Value 0x3 0xcc 0x5 0xff 0xee 0xdd 0xcc EDX = 0xffeeddcc! Endianess: Ordering of individually addressable units Little Endian: Least significant byte first... so... address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, and so on. Bit 0 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0x00 Addr

61 mov [eax], ebx Register eax edx ebx EBX Value 0x3 0xcc 0x Bit 0 0xff 0xee 0xdd 0xcc Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 61 6

62 mov [eax], ebx Register eax edx ebx EBX Value 0x3 0xcc 0x Bit 0 0xff 0xee 0xdd 0xcc 05 Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 62 6

63 mov [eax], ebx Register eax edx ebx EBX Value 0x3 0xcc 0x Bit 0 0xff 0xee 0xdd 00 0xcc 05 Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 63 6

64 mov [eax], ebx Register eax edx ebx EBX Value 0x3 0xcc 0x Bit 0 0xff 0xee 00 0xdd 00 0xcc 05 Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 64 6

65 mov [eax], ebx Register eax edx ebx EBX Value 0x3 0xcc 0x Bit 0 0xff 00 0xee 00 0xdd 00 0xcc 05 Addr Endianess: Ordering of individually addressable units 0xbb Little Endian: Least significant byte first... so... 0xaa address a goes in the least significant byte (the littlest bit) a+1 goes into the next byte, 0x00 0 and so on. 65 6

66 There are other ways to address memory than just [register]. These are called Addressing Modes. An Addressing Mode specifies how to calculate the effective memory address of an operand by using information from registers and constants contained with the instruction or elsewhere. 66

67 Motivation: Addressing Buffers Type buf[s]; buf[index] = *(<buf addr>+sizeof(type)*index) 67

68 Motivation: Addressing Buffers typedef uint32_t addr_t; 0 uint32_t w, x, y, z; 0 uint32_t buf[3] = {1,2,3}; 0 addr_t ptr = (addr_t) buf; w = buf[2]; x = *(buf + 2); buf[2] Memory What is x? what memory cell does it ref? buf 1 68

69 Motivation: Addressing Buffers typedef uint32_t addr_t; 0 uint32_t w, x, y, z; 0 uint32_t buf[3] = {1,2,3}; 0 addr_t ptr = (addr_t) buf; w = buf[2]; x = *(buf + 2); y = *( (uint32_t *) (ptr+8)); buf[2] Memory buf 1 69

70 Motivation: Addressing Buffers typedef uint32_t addr_t; 0 uint32_t w, x, y, z; 0 uint32_t buf[3] = {1,2,3}; 0 addr_t ptr = (addr_t) buf; w = buf[2]; x = *(buf + 2); y = *( (uint32_t *) (ptr+8)); buf[2] Memory 0 0 Equivalent 0 (addr_t) (ptr + 8) = (uint32_t *) buf+2 buf 1 70

71 Motivation: Addressing Buffers Type buf[s]; buf[index] = *(<buf addr>+sizeof(type)*index) 71

72 Motivation: Addressing Buffers Type buf[s]; buf[index] = *(<buf addr>+sizeof(type)*index) Say at imm +r 1 72

73 Motivation: Addressing Buffers Type buf[s]; buf[index] = *(<buf addr>+sizeof(type)*index) Say at imm +r 1 Constant scaling factor s, typically 1, 2, 4, or 8 73

74 Motivation: Addressing Buffers Type buf[s]; buf[index] = *(<buf addr>+sizeof(type)*index) Say at imm +r 1 Constant scaling factor s, typically 1, 2, 4, or 8 Say in Register r 2 74

75 Motivation: Addressing Buffers Type buf[s]; buf[index] = *(<buf addr>+sizeof(type)*index) Say at imm +r 1 Constant scaling factor s, typically 1, 2, 4, or 8 Say in Register r 2 imm + r 1 + s*r 2 AT&T: imm (r 1, r 2, s) Intel: r 1 + r 2 *s + imm 75

76 AT&T Addressing Modes for Common Codes Form imm (r) imm (r 1, r 2 ) imm (r 1, r 2, s) imm Meaning on memory M M[r + imm] M[r 1 + r 2 + imm] M[r 1 + r 2 *s + imm] M[imm] 76

77 Carnegie Mellon Address Computation Examples %edx %ecx 0xf000 0x0100 Expression Address Computation Address 0x8(%edx) 0xf x8 0xf008 (%edx,%ecx) 0xf x100 0xf100 (%edx,%ecx,4) 0xf *0x100 0xf400 0x80(,%edx,2) 2*0xf x80 0x1e080 77

78 Referencing Memory Loading a value from memory: mov <eax> = *buf; mov -0x38(%ebp),%eax (A) mov eax, [ebp-0x38] (I) <eax> = buf; Loading an address: lea lea -0x38(%ebp),%eax (A) lea eax, [ebp-0x38] (I) 78

79 Suppose I want to access address 0xdeadbeef directly Loads the address lea eax, 0xdeadbeef (I) Deref the address mov eax, 0xdeadbeef (I) Note missing $. This distinguishes the address from the value 79

80 Understanding Swap void swap(int *xp, int *yp) { int t0 = *xp; int t1 = *yp; *xp = t1; *yp = t0; } Register %edx %ecx %ebx %eax Value xp yp t0 t1 Offset yp xp Rtn adr Old %ebp Stack (in memory) %ebp -4 Old %ebx %esp movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 80

81 %eax %edx %ecx %ebx %esi %edi %esp %ebp Understanding Swap 0x104 yp xp Offset %ebp x120 0x124 Rtn adr Address 0x124 0x120 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 81

82 %eax %edx %ecx %ebx %esi %edi %esp %ebp Understanding Swap 0x124 0x104 yp xp Offset %ebp x120 0x124 Rtn adr Address 0x124 0x120 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 82

83 %eax %edx %ecx %ebx %esi %edi %esp %ebp Understanding Swap 0x124 0x120 0x104 yp xp Offset %ebp x120 0x124 Rtn adr Address 0x124 0x120 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 83

84 %eax %edx %ecx %ebx %esi %edi %esp %ebp Understanding Swap 0x124 0x x104 yp xp Offset %ebp x120 0x124 Rtn adr Address 0x124 0x120 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 84

85 %eax %edx %ecx %ebx %esi %edi %esp %ebp Understanding Swap 456 0x124 0x x104 yp xp Offset %ebp x120 0x124 Rtn adr Address 0x124 0x120 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 85

86 %eax %edx %ecx %ebx %esi %edi %esp %ebp Understanding Swap x124 0x x104 yp xp Offset %ebp x120 0x124 Rtn adr Address 0x124 0x120 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 86

87 %eax %edx %ecx %ebx %esi %edi %esp %ebp Understanding Swap 456 0x124 0x x104 yp xp Offset %ebp x120 0x124 Rtn adr Address 0x124 0x120 0x11c 0x118 0x114 0x110 0x10c 0x108 0x104 0x100 movl 8(%ebp), %edx # edx = xp movl 12(%ebp), %ecx # ecx = yp movl (%edx), %ebx # ebx = *xp (t0) movl (%ecx), %eax # eax = *yp (t1) movl %eax, (%edx) # *xp = t1 movl %ebx, (%ecx) # *yp = t0 87

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

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 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 information

Credits and Disclaimers

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 information

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

MACHINE-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 information

W4118: PC Hardware and x86. Junfeng Yang

W4118: 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 information

Machine Level Programming I: Basics

Machine 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 information

Carnegie Mellon. 5 th Lecture, Jan. 31, Instructors: Todd C. Mowry & Anthony Rowe

Carnegie 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 information

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

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 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 information

CS241 Computer Organization Spring 2015 IA

CS241 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 information

Lecture 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. 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 information

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Assembly 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 information

Instruction Set Architectures

Instruction 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 information

The x86 Architecture

The 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 information

Today: Machine Programming I: Basics

Today: 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 information

CS 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 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 information

Assembly I: Basic Operations. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly 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 information

Instruction Set Architectures

Instruction 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 information

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-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 information

MACHINE-LEVEL PROGRAMMING I: BASICS

MACHINE-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 information

Credits and Disclaimers

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 2 nd Edition by Bryant and O'Hallaron

More information

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor CS 261 Fall 2018 0000000100000f50 55 48 89 e5 48 83 ec 10 48 8d 3d 3b 00 00 00 c7 0000000100000f60 45 fc 00 00 00 00 b0 00 e8 0d 00 00 00 31 c9 89 0000000100000f70 45 f8 89 c8 48 83 c4 10 5d c3 Mike Lam,

More information

x86 architecture et similia

x86 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 information

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Assembly 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 information

x86 Programming I CSE 351 Winter

x86 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 information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

Machine Level Programming I: Basics. Credits to Randy Bryant & Dave O Hallaron

Machine Level Programming I: Basics. Credits to Randy Bryant & Dave O Hallaron Machine Level Programming I: Basics Lecture 3, Feb. 24, 2011 Alexandre David Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon 1 Today: Machine Programming I: Basics History of Intel processors

More information

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

Reverse 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 information

Machine-Level Programming Introduction

Machine-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 information

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

Access. 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 information

The von Neumann Machine

The 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

How Software Executes

How 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 information

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

X86 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 information

Lab 3. The Art of Assembly Language (II)

Lab 3. The Art of Assembly Language (II) Lab. The Art of Assembly Language (II) Dan Bruce, David Clark and Héctor D. Menéndez Department of Computer Science University College London October 2, 2017 License Creative Commons Share Alike Modified

More information

CS412/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 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 information

Software. Hardware. x86 basics. ISA View. a brief history of x86 10/6/15. Program, Application. Programming Language. Compiler/Interpreter

Software. 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 information

CS 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 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 information

CS 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 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 information

Reverse Engineering II: The Basics

Reverse 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 information

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Assembly 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 information

Machine Programming 3: Procedures

Machine 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 information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures Computer Systems: Section 4.1 Suppose you built a computer What Building Blocks would you use? Arithmetic Logic Unit (ALU) OP1 OP2 OPERATION ALU RES ALU + Registers R0: 0x0000

More information

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Binghamton 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 information

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Access. 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 information

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

CSC 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 information

X86 Assembly -Data II:1

X86 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 information

Program Exploitation Intro

Program 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 information

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008

CISC 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 information

System calls and assembler

System 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 information

Today: Machine Programming I: Basics. Machine Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

Today: Machine Programming I: Basics. Machine Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones Today: Machine Programming I: Basics Machine Level Programming I: Basics 15 213/1 213: Introduction to Computer Systems 5 th Lecture, Jan 29, 2013 History of Intel processors and architectures C, assembly,

More information

x86 64 Programming I CSE 351 Autumn 2018 Instructor: Justin Hsia

x86 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 information

The Hardware/Software Interface CSE351 Spring 2015

The 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 information

The von Neumann Machine

The 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

How Software Executes

How 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 information

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CSC 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 information

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

Assembly 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 information

Machine Programming 1: Introduction

Machine 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 information

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Registers. 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 information

Module 3 Instruction Set Architecture (ISA)

Module 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 information

Assembly I: Basic Operations. Jo, Heeseung

Assembly 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 information

CSE351 Spring 2018, Midterm Exam April 27, 2018

CSE351 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 information

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

ASSEMBLY 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 information

X86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson

X86 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 information

Machine-Level Programming I: Introduction Jan. 30, 2001

Machine-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 information

Machine-Level Programming Introduction

Machine-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 information

x86 Assembly Tutorial COS 318: Fall 2017

x86 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 information

Reverse Engineering II: The Basics

Reverse Engineering II: The Basics Reverse Engineering II: The Basics This document is only to be distributed to teachers and students of the Malware Analysis and Antivirus Technologies course and should only be used in accordance with

More information

Machine Program: Procedure. Zhaoguo Wang

Machine 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 information

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012

C to Assembly SPEED LIMIT LECTURE Performance Engineering of Software Systems. I-Ting Angelina Lee. September 13, 2012 6.172 Performance Engineering of Software Systems SPEED LIMIT PER ORDER OF 6.172 LECTURE 3 C to Assembly I-Ting Angelina Lee September 13, 2012 2012 Charles E. Leiserson and I-Ting Angelina Lee 1 Bugs

More information

x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia

x86 Programming I CSE 351 Autumn 2016 Instructor: Justin Hsia x86 Programming I 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/409/

More information

CS642: Computer Security

CS642: 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 information

CS 107 Lecture 10: Assembly Part I

CS 107 Lecture 10: Assembly Part I CS 107 Lecture 10: Assembly Part I Friday, February 9th, 2018 Computer Systems Winter 2018 Stanford University Computer Science Department Reading: Course Reader: x86-64 Assembly Language, Textbook: Chapter

More information

Sungkyunkwan University

Sungkyunkwan 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 information

Instruction Set Architecture (ISA) Data Types

Instruction Set Architecture (ISA) Data Types Instruction Set Architecture (ISA) Data Types Computer Systems: Section 4.1 Suppose you built a computer What Building Blocks would you use? Arithmetic Logic Unit (ALU) OP1 OP2 OPERATION ALU RES Full Adder

More information

Page # CISC 360. Machine-Level Programming I: Introduction Sept. 18, IA32 Processors. X86 Evolution: Programmerʼs View.

Page # 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 information

administrivia 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? 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 information

Machine-Level Programming I: Basics

Machine-Level Programming I: Basics Machine-Level Programming I: Basics CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides 1 Today: Machine Programming I: Basics History

More information

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

MODE (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 information

Introduction to IA-32. Jo, Heeseung

Introduction to IA-32. Jo, Heeseung Introduction to IA-32 Jo, Heeseung IA-32 Processors Evolutionary design Starting in 1978 with 8086 Added more features as time goes on Still support old features, although obsolete Totally dominate computer

More information

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

UMBC. 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 information

CS241 Computer Organization Spring Addresses & Pointers

CS241 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 information

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

6/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 information

INTRODUCTION TO IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung INTRODUCTION TO IA-32 Jo, Heeseung IA-32 PROCESSORS Evolutionary design Starting in 1978 with 8086 Added more features as time goes on Still support old features, although obsolete Totally dominate computer

More information

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated CNIT 127: Exploit Development Ch 1: Before you begin Updated 1-14-16 Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend, such as Denial

More information

How Software Executes

How 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 information

Machine-Level Programming I Introduction

Machine-Level Programming I Introduction Machine-Level Programming I Introduction CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Machine Programming I Basics Instruction

More information

Machine-Level Programming I Introduction

Machine-Level Programming I Introduction Machine-Level Programming I Introduction CSCI 2400: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts 1 Turning a corner Course theme: Low

More information

CSCI 192 Engineering Programming 2. Assembly Language

CSCI 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 information

Chapter 3 Machine-Level Programming I: Basics. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Chapter 3 Machine-Level Programming I: Basics. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition Chapter 3 Machine-Level Programming I: Basics 1 Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics: Registers, operands, move Arithmetic

More information

Complex Instruction Set Computer (CISC)

Complex Instruction Set Computer (CISC) Introduction ti to IA-32 IA-32 Processors Evolutionary design Starting in 1978 with 886 Added more features as time goes on Still support old features, although obsolete Totally dominate computer market

More information

CS Bootcamp x86-64 Autumn 2015

CS 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 information

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Computer 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 information

Giving credit where credit is due

Giving 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 information

Computer Architecture and Assembly Language. Practical Session 3

Computer 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 information

Machine/Assembler Language Putting It All Together

Machine/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 information

The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, 2002

The 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 information

x86 assembly CS449 Fall 2017

x86 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 information

Process Layout and Function Calls

Process 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 information

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,... COMPUTER ARCHITECTURE II: MICROPROCESSOR PROGRAMMING We can study computer architectures by starting with the basic building blocks Transistors and logic gates To build more complex circuits Adders, decoders,

More information

Assembly Language Lab # 9

Assembly 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 information

Function Call Convention

Function 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 information

EEM336 Microprocessors I. Addressing Modes

EEM336 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 information