So I am tasked with writing assembly code that will perform a prefix sum on a set of numbers.
The example given was 2 4 6 -1
and the return needs to be 12 10 6
. -1
serves as a stopper.
jmp main
prefix: addl %edx, %eax
ret
print: irmovl $32, %ecx
wrint %eax
wrch %ecx
ret
read: pushl %ebp # ON_ENTRY saving old frame ptr
rrmovl %esp, %ebp # ON_ENTRY set new frame ptr
mrmovl 8(%ebp), %edx # Retrieving parameter
irmovl $1, %ecx # writing ecx with 1
addl %ecx, %esi
addl %edx, %ecx # adding edx and ecx
je baseCase # checking if they equal 0
recStep: rdint %ebx # reading parameter from user
pushl %ebx
call read
popl %ebx
mrmovl 8(%ebp), %edx
pushl %edx
call prefix
popl %edx
call print
jmp end
baseCase: irmovl $0, %eax
end: rrmovl %ebp, %esp # ON_EXIT reset stack ptr
popl %ebp # ON_EXIT restore old base/frame ptr
ret # ON_EXIT
main: irmovl $0x1000, %esp # init stack ptr
irmovl $-1, %esi
rdint %ebx # reading parameter from user
pushl %ebx # pushing parameter
call read # function call
popl %ebx # removing parameter
call prtnl
halt
prtnl: irmovl $10, %edx # assuming edx is caller save
wrch %edx
ret
So basically my code prints 6 10 12
and I need to find a way to reverse this output. Any ideas?