所以我的任务是编写汇编代码,对一组数字执行前缀求和。
给出的例子是2 4 6 -1
并且返回需要是12 10 6
。-1
充当塞子。
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
所以基本上我的代码打印出来6 10 12
了,我需要找到一种方法来反转这个输出。有任何想法吗?