Skip to content

Instantly share code, notes, and snippets.

@akiradeveloper
Created February 20, 2021 23:54
Show Gist options
  • Save akiradeveloper/8836cf63aeef0c4b19a42188f6b4fe67 to your computer and use it in GitHub Desktop.
Save akiradeveloper/8836cf63aeef0c4b19a42188f6b4fe67 to your computer and use it in GitHub Desktop.
how is this made??
```c
int abs(int x) {
if (x >= 0) {
return x;
} else {
return -x;
}
}
int main(void) {
return abs(-3);
}
```
=>
```
$ make dump
rm -f test.o crt0.o
gcc -march=i386 -m32 -nostdlib -fno-pie -fno-asynchronous-unwind-tables -fno-stack-protector -c test.c
nasm -f elf crt0.asm
ld -m elf_i386 -s --entry=start --oformat=binary -Ttext 0x7c00 -o main crt0.o test.o
objdump -M intel -m i386 -b binary -D main
main: file format binary
Disassembly of section .data:
00000000 <.data>:
0: e8 1a 00 00 00 call 0x1f
5: e9 f6 83 ff ff jmp 0xffff8400
a: 55 push ebp
b: 89 e5 mov ebp,esp
d: 83 7d 08 00 cmp DWORD PTR [ebp+0x8],0x0
11: 78 05 js 0x18
13: 8b 45 08 mov eax,DWORD PTR [ebp+0x8]
16: eb 05 jmp 0x1d
18: 8b 45 08 mov eax,DWORD PTR [ebp+0x8]
1b: f7 d8 neg eax
1d: 5d pop ebp
1e: c3 ret
1f: 55 push ebp
20: 89 e5 mov ebp,esp
22: b8 03 00 00 00 mov eax,0x3
27: 5d pop ebp
28: c3 ret
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment