Skip to content

Instantly share code, notes, and snippets.

@kawakami-o3
Last active July 4, 2019 07:03
Show Gist options
  • Save kawakami-o3/ae0325c1d666b3b467cf0df988ec5750 to your computer and use it in GitHub Desktop.
Save kawakami-o3/ae0325c1d666b3b467cf0df988ec5750 to your computer and use it in GitHub Desktop.
print without libc
// Just an example.
#include<unistd.h>
int main() {
write(1, "hello\n", 6);
}
.section .rodata
.LC0:
.string "hello\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $6, %edx
movl $.LC0, %esi
movl $1, %edi
movl $1, %eax
syscall
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
@kawakami-o3
Copy link
Author

@kawakami-o3
Copy link
Author

@kawakami-o3
Copy link
Author

@kawakami-o3
Copy link
Author

$ as main.s -o main.o && ld main.o && ./a.out
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
hello
fish: './a.out' terminated by signal SIGSEGV (Address boundary error)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment