0

I'm trying to create a program in assembly language that copies array X to the stack frame and displays the stack frame on the screen before exit from the procedure. This is what I wrote so far, and it is only giving me errors as it is not compiling on Microsoft C++ Visual Studio.

ExitProcess PROTO,  dwExitCode:DWORD        
calSumP PROTO,baseP:ptr dword, sumP:ptr dword, incre:dword, count:dword

.data

X   sdword   10, -10, 20, -20, 30, -30, 40, -40

.code

begin:
invoke calSumP,addr X, addr X, type X, lengthof X
invoke exitProcess,0

calSumP
proc,baseP:ptr dword, sumP:ptr dword, incre:dword, count:dword
local array1[8]:dword

mov esi,[ebp+8]
mov esi,[ebp+12]
mov esi,[ebp+16]
mov esi,[ebp+20]
mov esi,[ebp+24]
mov esi,[ebp+28]
mov esi,[ebp+32]
mov esi,[ebp+36]
mov eax,0
nextP:
add eax,[esi]
loop    nextP
ret
calSumP endp

invoke  ExitProcess,0
end     begin

Is this the proper way to add the array to the stack? How would I display its contents?

Noah
  • 15,080
  • 13
  • 104
  • 148
  • the stack doesn't have to hold the data, the stack can hold a pointer (resb 4 on x86 or resb 8 on 64-bit) to heap memory or a value elsewhere in memory if needed – phyrrus9 Apr 28 '14 at 23:23
  • @phyrrus9 The stack frequently holds local array data (or structures data) but memory should be allocated before (e.i. `sub esp, 20h`). Of course, in this case if stack array required it should be allocate outside the `calSumP` function and pointer to the memory block should be passed in `calSumP` then. – mblw May 02 '14 at 04:26

0 Answers0