0
我正在尝试编写一个函数来将堆栈中推入的整数转换为ASCII码。转换工作正常,但我在堆栈上传递的参数有问题。在NASM堆栈上传递参数的问题
org 100h
section .text
start:
mov eax, 12345
push eax
call print_int
add esp, 4 ;clear the stack
jmp _exit
;value is in the stack
print_int:
push ebp
mov ebp, esp
mov ecx, 0Ah ;divide by 10
mov eax, [ebp+8] ;value is in ebp + 8
again1:
mov edx, 0
idiv ecx ;quotent in EAX, remainder in EDX
push edx
cmp eax, 0
jne again1
printing:
;output a digit
pop edx ;get digit from stack
add dl, 30h ;convert to ASCII
mov ah, 02h
int 21h ; print
cmp esp, ebp
jne printing
mov esp, ebp
pop ebp
ret
_exit:
mov al, 0
mov ah, 4ch
int 21h
section .data
section .bss
的问题是MOV EAX,[EBP + 8]设置EAX为0,而不是12345。如果我改变MOV EAX,[EBP + 8]为MOV EAX,12345一切正常。
您正在使用哪种操作系统(DOS)? – 2011-01-29 23:07:15
我使用Win XP – st0n3 2011-01-29 23:49:13