我想創建一個可以計算除法問題的程序。問題是當我嘗試用負數分割時,我的程序崩潰了,儘管我創建了一個名爲「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它將永遠循環。整個問題對於它應該完成的任務有點「奇怪」 –