Trying to get the new ABI working here.
This commit is contained in:
parent
bad3aaf268
commit
a1d2058ed9
@ -4,22 +4,22 @@
|
||||
.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
|
||||
pushq %rax # save the first answer on stack
|
||||
pushq $2 # push the second argument
|
||||
pushq $5 # push the first argument
|
||||
;addq $16, %rsp # move the stack pointer back
|
||||
pushq %rax # save the first answer on stack
|
||||
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,
|
||||
popq %rdi # the second answer is still in %rax,
|
||||
# so we can put the first one from the
|
||||
# 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
|
||||
movq $60, %rax # exit (%rdi is returned)
|
||||
movq $60, %rax # exit (%rdi is returned)
|
||||
syscall
|
||||
|
||||
#VARIABLES:
|
||||
@ -31,28 +31,25 @@ _start:
|
||||
#
|
||||
.type power, @function
|
||||
power:
|
||||
pushq %rbp # save old base pointer
|
||||
movq %rsp, %rbp # make stack pointer the base pointer
|
||||
subq $8, %rsp # get room for our local storage
|
||||
pushq %rbp # save old base pointer
|
||||
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
|
||||
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
|
||||
imulq %rdi, %rax # multiply the current result by the
|
||||
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)
|
||||
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 %rbp, %rsp # restore the stack pointer
|
||||
popq %rbp # restore the base pointer
|
||||
movq -8(%rbp), %rax # return value goes in %rax
|
||||
movq %rbp, %rsp # restore the stack pointer
|
||||
popq %rbp # restore the base pointer
|
||||
ret
|
||||
|
Loading…
Reference in New Issue
Block a user