Last active
August 29, 2015 14:10
-
-
Save hypevhs/c7df3e3aef3a46f4bf37 to your computer and use it in GitHub Desktop.
calling C from assembly (64 bit)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://i.imgur.com/TNS0NW7.png