1

I am trying to calculate the result with three inputs but I have been getting error. I guess something is wrong with push and pop instructions. I have posted the picture of error. Any help is highly appreciated. I am using Visual Studio 2015.

I am trying to calculate the result with three inputs but I have been getting error. I guess something is wrong with push and pop instructions. I have posted the picture of error. Any help is highly appreciated. I am using Visual Studio 2015.

UPDATED: This problem has been solved by replacing [add esp, 8] with [add esp, 12]

.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096

.DATA
number1 DWORD ?
number2 DWORD ?
number3 DWORD ? 
prompt1 BYTE "Enter first number, x", 0 
prompt2 BYTE    "Enter second number, y", 0 
prompt3 BYTE       "Enter second number, z", 0 
string  BYTE    40 DUP(? ) 
resultLbl BYTE    "result", 0 
sum     BYTE    11 DUP(? ), 0

   .CODE    
  _MainProc PROC 
   input   prompt1, string, 40 
   atod    string 
   mov     number1, eax

   input   prompt2, string, 40 
   atod    string 
   mov     number2, eax

   input   prompt3, string, 40 
   atod    string
   mov     number3, eax

   push number3 
   push number2 
   push number1

   call fctn1 
   
   add esp, 8
   dtoa    sum, eax 
   output  resultLbl, sum
   mov     eax, 0 
   ret    
   _MainProc ENDP




   fctn1 PROC 
   push ebp 
   mov ebp, esp 

   push ebx

   mov eax, [ebp + 8] 
   imul eax, 3 
   mov ebx, [ebp+12]
   imul ebx, 7 
   add eax, ebx 
   mov ecx, [ebp+16]
   imul ecx, 2 
   add eax, ecx

   pop ebx 
   pop ebp
   ret
   fctn1 ENDP

   END

enter image description here

Tuk Tuk
  • 337
  • 1
  • 2
  • 11

0 Answers0