Home » Uncategorized » qbe on alpine linux (musl libc)

qbe on alpine linux (musl libc)

https://c9x.me/compile/

// file.ssa

function w $add(w %a, w %b) { # Define a function add
@start
%c =w add %a, %b # Adds the 2 arguments
ret %c # Return the result
}
export function w $main() { # Main function
@start
%r =w call $add(w 1, w 1) # Call add(1, 1)
call $printf(l $fmt, w %r, …) # Show the result
ret 0
}
data $fmt = { b “One and one make %d!\n”, b 0 }

./qbe -o asm.s file.ssa

// asm.s

.text
add:
pushq %rbp
movq %rsp, %rbp
movl %edi, %eax
addl %esi, %eax
leave
ret
/* end function add */

.text
.globl main
main:
pushq %rbp
movq %rsp, %rbp
movl $1, %esi
movl $1, %edi
callq add
movl %eax, %esi
leaq fmt(%rip), %rdi
movl $0, %eax
callq printf
movl $0, %eax
leave
ret
/* end function main */

.data
.align 8
fmt:
.ascii “One and one make %d!\n”
.byte 0
/* end data */

 

– callq printf // need to be fixed!

+ callq printf@plt

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s