Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- calls.asm==========================
- global sys_read
- global sys_write
- global sys_errno
- section .text
- generic_syscall_3:
- push ebp
- mov ebp, esp
- push ebx
- mov ebx, [ebp+8]
- mov ecx, [ebp+12]
- mov edx, [ebp+16]
- int 80h
- mov edx, eax
- and edx, 0fffff000h
- cmp edx, 0fffff000h
- jnz .okay
- mov [sys_errno], eax
- xor eax, eax
- not eax
- .okay:
- pop ebx
- mov esp, ebp
- pop ebp
- ret
- sys_read: mov eax, 3
- jmp generic_syscall_3
- sys_write: mov eax, 4
- jmp generic_syscall_3
- section .bss
- sys_errno resd 1
- start.asm==========================
- global _start
- extern main
- section .text
- _start: mov ecx, [esp] ; argc in ecx
- mov eax, esp
- add eax, 4 ; argv in eax
- push eax
- push ecx
- call main
- add esp, 8 ; clean the stack
- mov ebx, eax ; now call _exit
- mov eax, 1
- int 80h
- hello.c==========================
- int sys_write(int fd, const void *buf, int size);
- int main(int argc, char **argv)
- {
- sys_write(1, "Hello, world\n", 13);
- return 0;
- }
- Сборка==========
- nasm -f elf start.asm
- nasm -f elf calls.asm
- gcc -Wall -nostdlib -Os -s -m32 -c hello.c
- ld -strip-all start.o calls.o hello.o -o hello
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement