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,22 +4,22 @@
.globl _start .globl _start
_start: _start:
pushq $3 # push the second argument movq $3, %rsi # second argument
pushq $2 # push the first argument movq $2, %rdi # first argument
call power # call the function 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 %rax # save the first answer on stack
pushq $2 # push the second argument movq $2, %rsi # push the second argument
pushq $5 # push the first argument movq $5, %rdi # push the first argument
call power # call the function 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, popq %rdi # the second answer is still in %rax,
# so we can put the first one from the # so we can put the first one from the
# stack to %rdi to keep both answers # stack to %rdi to keep both answers
addq %rax, %rdi # add them together and store result addq %rax, %rdi # add them together and store result
# in %rdi # in %rdi
movq $60, %rax # exit (%rdi is returned) movq $60, %rax # exit (%rdi is returned)
syscall syscall
#VARIABLES: #VARIABLES:
@ -31,28 +31,25 @@ _start:
# #
.type power, @function .type power, @function
power: power:
pushq %rbp # save old base pointer pushq %rbp # save old base pointer
movq %rsp, %rbp # make stack pointer the base pointer movq %rsp, %rbp # make stack pointer the base pointer
subq $8, %rsp # get room for our local storage subq $8, %rsp # get room for our local storage
movq 16(%rbp), %rdi # put first argument in %rdi movq %rdi, -8(%rbp) # store the current result
movq 24(%rbp), %rsi # put second argument in %rsi
movq %rdi, -4(%rbp) # store the current result
power_loop_start: power_loop_start:
cmpq $1, %rsi # if the power is 1, don't do shit cmpq $1, %rsi # if the power is 1, don't do shit
je end_power 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 imulq %rdi, %rax # multiply the current result by the
# base number # 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) decq %rsi # decrease the power (one down)
jmp power_loop_start # run for the next power jmp power_loop_start # run for the next power
end_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 movq %rbp, %rsp # restore the stack pointer
popq %rbp # restore the base pointer popq %rbp # restore the base pointer
ret ret