I am trying to divide a negative number. I read that I need to use idiv
, but it still outputs 5 instead of -5
.386
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
.data
AnswerTxt db 'The answer is '
AnswerNum db 11 dup(0)
num_a dd 5
.code
start:
xor edx, edx
mov eax, -25
mov ebx, num_a
idiv ebx
push offset AnswerNum
push ebx
call dwtoa
push 0
push offset AnswerTxt
push offset AnswerTxt
push 0
call MessageBoxA
call ExitProcess
end start
UPDATE (problem solved):
.386
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
.data
AnswerTxt db 'The answer is '
AnswerNum db 11 dup(0)
num_a dd 5
.code
start:
mov eax, -25
mov ebx, num_a
cdq
idiv ebx
push offset AnswerNum
push eax
call dwtoa
push 0
push offset AnswerTxt
push offset AnswerTxt
push 0
call MessageBoxA
call ExitProcess
end start