win32汇编实现汉诺塔

 
.386
.model stdcall, flat
option casemap:none

include msvcrt.inc
includelib msvcrt.lib

.data
format	db	'%d:  %c->%c', 13, 10, 0
tmp	dword	41h, 42h, 43h
count	dword	0

.code
Hanio proc, A:dword, B:dword, D:dword, n:dword	;C是关键字,只好用D代替了
	.if n == 1
		inc count
		invoke crt_printf, offset format, count, A, D
	.else	
		push ebx

		mov ebx, n
		dec ebx

		invoke Hanio, A, D, B, ebx

		inc count
		invoke crt_printf, offset format, count, A, D

		invoke Hanio, B, A, D, ebx

		pop ebx
	.endif
	ret
Hanio endp

start:
	invoke Hanio, tmp, tmp+4, tmp+8, 5;知道为什么Hanio中为什么不直接用n-1了吧
	ret;偷懒
end	start

你可能感兴趣的:(c,汇编)