스택에 푸시 된 정수를 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]은 I는 MOV의 EAX MOV로의 EAX, [EBP + 8]로 변경하면 0이 아닌 12345로 EAX 설정 12345 다 OK이다.
어떤 OS (DOS)를 사용하고 있습니까? –
Win XP – st0n3
을 사용하고 있습니다. 이것은 16 비트 프로그램 또는 32 비트입니까? 32 비트 레지스터를 사용하고 도스 인터럽트 int 21을 호출하기 때문에! –