Trying to get the new ABI working here.

This commit is contained in:
Nicolás A. Ortega 2016-06-07 01:41:40 +02:00
parent bad3aaf268
commit a1d2058ed9
No known key found for this signature in database
GPG Key ID: 4825F773B8D44EFF

View File

@ -4,15 +4,15 @@
.globl _start
_start:
pushq $3 # push the second argument
pushq $2 # push the first argument
movq $3, %rsi # second argument
movq $2, %rdi # first argument
call power # call the function
addq $16, %rsp # move the stack pointer back
;addq $16, %rsp # move the stack pointer back
pushq %rax # save the first answer on stack
pushq $2 # push the second argument
pushq $5 # push the first argument
movq $2, %rsi # push the second argument
movq $5, %rdi # push the first argument
call power # call the function
addq $16, %rsp # move the stack pointer back
;addq $16, %rsp # move the stack pointer back
popq %rdi # the second answer is still in %rax,
# so we can put the first one from the
@ -35,24 +35,21 @@ power:
movq %rsp, %rbp # make stack pointer the base pointer
subq $8, %rsp # get room for our local storage
movq 16(%rbp), %rdi # put first argument in %rdi
movq 24(%rbp), %rsi # put second argument in %rsi
movq %rdi, -4(%rbp) # store the current result
movq %rdi, -8(%rbp) # store the current result
power_loop_start:
cmpq $1, %rsi # if the power is 1, don't do shit
je end_power
movq -4(%rbp), %rax # move the current result into %rax
movq -8(%rbp), %rax # move the current result into %rax
imulq %rdi, %rax # multiply the current result by the
# base number
movq %rax, -4(%rbp) # store the current result
movq %rax, -8(%rbp) # store the current result
decq %rsi # decrease the power (one down)
jmp power_loop_start # run for the next power
end_power:
movq -4(%rbp), %rax # return value goes in %rax
movq -8(%rbp), %rax # return value goes in %rax
movq %rbp, %rsp # restore the stack pointer
popq %rbp # restore the base pointer
ret