我想创建一个可以计算除法问题的程序。问题是当我尝试用负数分割时,我的程序崩溃了,尽管我创建了一个名为“DivNeg”的分支,该分支应该可以防止它崩溃。有没有人有如何解决这个问题的想法?将正数除以组合中的负数
这是我的汇编代码
.386
.model flat
public _Divide
.code
_Divide proc
mov eax, [esp + 4] ; First address ; this is the dividend
mov ebx, [esp + 8] ; Second address ; this is the divisor
cmp ebx, 0
je DivZero
cmp ebx, 0
jnae DivNeg
cdq
idiv ebx ; To divide by eax by ebx
mov ebx, [esp + 12] ; Third address; this is the remainder
jmp Done1
DivZero:
mov eax,-1 ; If user divides by zero, this will set the result to negative 1
mov edx, 0 ; If user divides by zero, this will set the remainder to 0
mov ebx,[esp +12] ; Needed for the remainder if divided by 0
cmp ebx, 0
je Done2
Done1:
mov [ebx], edx
je Done1
DivNeg:
cmp ebx, 0
jge Done2
mov eax, -1
neg eax
je DivNeg
Done2:
ret
_Divide endp
end
只是第一次看;你有:'je DivZero; je DivNeg'一个又一个;还有DivNeg应该怎么做?为什么有一个' - 'ascii? –
我创建了DivNeg循环,以便显示除负数的结果和余数。没有它,程序会因某种原因崩溃。作为divNeg的一部分,如果除数小于零,我会将它放在那里。 – Jaquai
我想你应该多读一些关于asm的内容; '循环'没有意义 - 它eax> 0它将永远循环。整个问题对于它应该完成的任务有点“奇怪” –