Download presentation
Presentation is loading. Please wait.
1
Recitation 1 Session 5 Ishani Chakraborty
2
Machine Level Representation What happens to a C program when we compile it ? $ gcc prog.c Preprocessor (expands code) Compiler (source2asm) Assembler (asm2object) Linker (Combines objects to form a single executable)
3
Assembly code Generated by –s option $ gcc –O2 –S code.c Using GCC compiler, the assembly code is generated in GAS format (GNU Assembler)
4
#include int accum = 0; int sum(int x, int y) { int t = x+y; accum = accum + t; return t; } add.c $ gcc –O2 –S add.c (generate asm.s code) vi add.s $ gcc –O2 –c add.c (generate binary machine.o code) $ gcc add.s $ gcc add.o
5
$ vi add.s
6
$ objdump –d add.o
7
Example: asm => c movl 16(%ebp), %eax movl 12(%ebp), %edx subl %eax, %edx movl %edx, %eax imull 8(%ebp),%edx sall $31, %eax sarl $31, %eax xorl %edx, %eax
8
int asm2c(int x, int y, int z) { int t1 = y - z; int t2 = x * t1; int t3 = (t1 > 31; int t4 = t3 ˆ t2; return t4; }
9
Control Flow Control the sequence of operations. –Default: Sequential –Non sequential through conditionals/loops/switches etc. Condition Codes: To perform non-sequential jumps. CF, ZF, SF, OF. Jump instructions: jmp, je,jne,jg (signed greater), jge, ja (unsigned greater),…
10
Jump targets are using PC – relative ie., the difference between address of target instruction and instruction following the jump. eg., what is the jump target for instr 1 and 2 ? (1)0x08:7e11jle 1b …. (2)0x19:7ff5jg 10 ….
12
int absdiff2(int x, int y) { int result; if (x< y) result = y-x; else result = x-y; return result; }
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.