Below is our example assembly file, example.s
, from class today. You can use clang example.s
to assemble it and ./a.out
to then run it.
.globl main
main:
pushq %rbp
movq $0, %rbp
condition:
cmpq $42, %rbp
jg after
movq %rbp, %rsi
leaq fmtstring(%rip), %rdi
callq printf
addq $1, %rbp
jmp condition
after:
xorl %eax, %eax
popq %rbp
retq
fmtstring:
.asciz "i = %ld\n"