x86 Assembly Question about outputting

Posted by jdea on Stack Overflow See other posts from Stack Overflow or by jdea
Published on 2010-06-06T22:57:15Z Indexed on 2010/06/06 23:02 UTC
Read the original article Hit count: 399

Filed under:
|
|
|

My code looks like this

_declspec(naked) void 
 f(unsigned int input,unsigned int *output)
{
 __asm{

  push dword ptr[esp+4]
  call factorial

  pop ecx

  mov [output], eax //copy result
  ret
 }
}

__declspec(naked) unsigned int
factorial(unsigned int n)
{
 __asm{

  push esi
  mov esi, dword ptr [esp+8]
  cmp esi, 1
  jg RECURSE
  mov eax, 1    
  jmp END

  RECURSE:
   dec esi 
   push esi
   call factorial
   pop esi
   inc esi
   mul esi

  END:
   pop esi
   ret
 }
}

Its a factorial function and I'm trying to output the answer after it recursively calculates the number that was passed in

But what I get returned as an output is the same large number I keep getting Not sure about what is wrong with my output, by I also see this error CXX0030: Error: expression cannot be evaluated

Thanks!

© Stack Overflow or respective owner

Related posts about assembly

Related posts about x86