This is a part of my homework. I have completed part 1. Part 2 asks that I re-write my part 1:
"Write a modified version of part A, in which the function is to be called as though it had the following prototype:
void sumPowers(int n, int *pSum);
is this asking me to input n and a pointer to the sum or the address at which sum is stored?
An attachment of my code:
[SECTION .data]
n: dd 0
fmt1: db "%d", 0
fmt2: db "%d", 10, 0
[SECTION .text]
global main
extern scanf, printf
main: push EBP
mov EBP, ESP
push EBX
push ESI
push EDI
first:
push n
push fmt1
call scanf
add ESP, 8
cool:
mov EDI,[n]
push EDI
call sumPowers
add ESP, 4
push EAX
push fmt2
call printf
add ESP, 8
last: pop EDI
pop ESI
pop EBX
mov ESP, EBP
pop EBP
ret
sumPowers:
push EBP
mov ESP,EBP
mov ECX, 2
mov EBX, 2
mov EDX,3
mov EAX, 0 ; Initialize the counter
mov ESI, EDI ; Store n in ESI
sub ESI,1
loop1: cmp EAX, ESI ;
jge step1
imul ECX,EBX
add EDX,ECX
add EAX,1
jmp loop1
step1: mov EAX, ECX ; Initialize the sum
pop EBP
ret