Skip to content

Instantly share code, notes, and snippets.

@hypevhs
Last active August 29, 2015 14:10
Show Gist options
  • Save hypevhs/c7df3e3aef3a46f4bf37 to your computer and use it in GitHub Desktop.
Save hypevhs/c7df3e3aef3a46f4bf37 to your computer and use it in GitHub Desktop.
calling C from assembly (64 bit)
.section .data
prompt: .asciz "Please input a number:\n"
format: .asciz "%d"
output: .asciz "The largest value is %d\n"
debug: .asciz "You gave me : '%d'!\n"
.section .text
.globl main
main:
movq $prompt, %rdi
movq $0, %rax
call printf # Print out the input prompt.
subq $8, %rsp # Allocate int on the stack.
movq $format, %rdi
movq %rsp, %rsi # Can't use register for scanf. Use mem location.
movq $0, %rax
call scanf # Get integer from input.
movq $debug, %rdi
movq (%rsp), %rsi
movq $0, %rax
call printf # Print out the input prompt.
addq $8, %rsp # Clean up that int.
ret
@hypevhs
Copy link
Author

hypevhs commented Nov 30, 2014

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