我正在努力idiv
正常工作,我读过你把你想要除以 25 的东西放进去,然后ebx
把你想要除以 5 的东西放进去,然后你做
idiv ebx
然后将EAX
= 5 然后EDX
= 0。
但是在我的程序中并没有这样做,我所做的输入是100000000
输出:
千字节:100000000
兆字节:1869375819
想知道我在这里做错了什么?
%include "asm_io.inc"
;
; initialized data is put in the .data segment
;
segment .data
prompt db "Please enter the number of bytes:", 0
param db "1 = Calculate it in kilobytes", 0Ah, "2 = Calculate it in megabytes", 10, 0
output db "Kilobytes: %d", 0Ah, "MegaBytes: %d", 10, 0
;
;
segment .bss
;
input resd 1
input2 resd 1
choice resd 1
;
; code is put in the .text segment
;
segment .text
global asm_main
extern printf
asm_main:
enter 0,0
pusha
mov eax, prompt
call print_string
call read_int
mov [input], eax
mov [input2], eax
sub esp, 10h
push dword [output]
push dword [input2]
push dword [input]
mov eax, param
call print_string
call read_int
cmp eax, 1
je kilobyte; Jump if eax is equal to 1
cmp eax, 2
je megabyte; Jump if eax equal to 2
kilobyte:
pop eax ; Pop input into eax
cdq
mov ebx, 1024 ; Put 1024 into ebx
idiv ebx ; EAX = 100000000/1024 = 97656
mov [input], eax ; Move 97656 into var=input
push dword [input] ; Put into stack
jmp megabyte
megabyte:
pop eax ; Pop input into eax
cdq
mov ebx, 1048576 ; Put 1048576 into ebx
idiv ebx ; EAX = 100000000/1024 = 95
mov [input2], eax ; Move 95 into var=input
push dword [input] ; Put into stack
jmp printOut
printOut:
mov dword [esp], output
call printf
add esp, 4 * 3
add esp, 10h
popa
mov eax, 0
leave
ret
更新
好吧,我输入了,xor edx, edx
但我仍然得到与以前相同的输出。我查看了我的电子书和其他网站,它说了同样的话,所以我真的不确定我做错了什么。也尝试了idiv
没有运气的路线。