我正在嘗試在NASM程序集中編寫一個將十進制數轉換爲二進制數的程序。 到目前爲止,我編寫了一些採用輸入數字的代碼,將其除以2並顯示餘數。但我有一個問題,我得到分割後的無限循環,其實我一直在EAX一個大於0在組件分割後的無限循環NASM
; ----------------------------------------------------------------------------------------
; nasm -felf decbin.asm && gcc decbin.o -o decbin
; ----------------------------------------------------------------------------------------
section .data
in_message db "Enter a number in decimal:",0 ;input message
out_message db "The binary number is:%d",10,0 ;output message
integer times 4 db 0 ;32bits integer
formatin db "%d",0
binary db 2;used for div
section .text
global main
extern printf
extern scanf
main:
;;; Ask for integer
push in_message
call printf
add esp,4 ;remove parameters
push integer ;address of integer where number will be stored
push formatin ;%d parameter, arguments are right to left
call scanf
add esp,8 ;remove parameters
mov eax,[integer]
jmp loop
;;; terminate if zero
mov al,1
mov ebx,0
int 80h
loop:
xor edx,edx
mov ebx,[binary] ;mov binary to ebx
div ebx
push edx
push formatin
call printf
add esp,8
cmp eax,0 ;compare the quotient with 0;
jnz loop
你應該做一些調試。 – 2014-10-19 09:20:34