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