Without putting too much study into your code, I came up with this:
;; How is this being called? are you invoking this from C?
;; If so, this is a stdcall function, you should change the
;; prototype from cdecl to stdcall (this varies from compiler
;; to compiler)
global asm_hanoi_rec
asm_hanoi_rec:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov ebx, [ebp+24]
cmp eax, 1
jne L5
cmp ebx, 1
je L7
push eax ;; Save EAX for future use
push dword[ebp+20]
push dword[ebp+12]
push han1
call printf ;; EAX is trashed here..
add esp, 12
pop eax ;; Restore EAX
jmp L7
L5:
push eax
push ebx
dec eax
push ebx
push dword[ebp+16]
push dword[ebp+20]
push dword[ebp+12]
push eax
call asm_hanoi_rec
cmp ebx, 1
je L6
push dword[ebp+20]
push dword[ebp+12]
push han1
call printf
add esp, 12
L6:
; mov eax, [ebp+8]
; mov ebx, [ebp+24]
pop ebx
pop eax
dec eax
push ebx
push dword[ebp+20]
push dword[ebp+12]
push dword[ebp+16]
push eax
call asm_hanoi_rec
L7:
mov esp, ebp
pop ebp
ret 20
I haven't tested it to see if it corrects the error in question or not, I just thought I would point out a few things that were really popping out at me.
EDIT: Design wise, I would suggest trying to simply your procedure. maybe something like:
void hanoi_rec(int n_disc, int head, int middle, int tail, int silent){
if( n_disc != 1 ) {
hanoi_rec( n_disc -1, head, tail, middle, silent );
hanoi_rec( n_disc -1, middle, head, tail, silent );
}
if( silent != 1 ) printf( "%d --> %d\n", head, tail );
}
Which would result in:
[BITS 32]
[CPU 486]
extern printf
global _start
; C Version
;void hanoi_rec(int n_disc, int head, int middle, int tail, int silent){
; if( n_disc != 1 ) {
; hanoi_rec( n_disc -1, head, tail, middle, silent );
; hanoi_rec( n_disc -1, middle, head, tail, silent );
; }
; if( silent != 1 ) printf( "%d --> %d\n", head, tail );
;}
section .data
strFmt: DB "%d --> %d", 10, 0
section .text
_start:
xor eax, eax
push dword eax
push dword 3
push dword 2
push dword 1
push dword 5
call hanoi_rec
xor eax, eax
xor ebx, ebx
inc eax
int 80h
hanoi_rec:
%define _n_disc ebp + 8
%define _head ebp + 12
%define _middle ebp + 16
%define _tail ebp + 20
%define _silent ebp + 24
enter 0, 0
mov eax, [_n_disc]
cmp eax, 1
je .endif_1
dec eax
push dword [_silent]
push dword [_middle]
push dword [_tail]
push dword [_head]
push eax
push dword [_silent]
push dword [_tail]
push dword [_head]
push dword [_middle]
push eax
call hanoi_rec
call hanoi_rec
.endif_1:
mov eax, [_silent]
cmp eax, 1
je .endif_2
push dword [_tail]
push dword [_head]
push dword strFmt
call printf
add esp, (4 * 3)
.endif_2:
leave
ret
Regards,
Bryant Keller