;==================Prompts===============
warning  db     "Invalid order. The dividend should be greater than the divisor",0
prompt1	 db	0dh,0ah,"Please enter a dividend ",0
prompt2  db	0dh,0ah,"Please enter a divisor ",0
Display  db     0dh,0ah,"Quotient: ",0
Display2 db	0dh,0ah,"Remainder: ",0
;==================Variables=============
dividend word  ?      ; Holds the dividend
divisor  word  ?      ; Holds the divisor 
quotient word  ?      ; Holds the quotient 
Remain   word  ?      ; Holds the remainder
;==================Main==================
.code
main PROC
.startup

mov dx, offset prompt1
call writestring 
call readint

mov dividend, ax

mov dx, offset prompt2
call writestring
call readint

mov divisor, bx

CWD
div bx

mov quotient, ax

mov dx, offset Display
call writestring
call writeint


exit
main ENDP
END main

Let me start by saying the I'm a complete greenhorn when it comes to assembly. My professor seems to think it's a good idea to give us a crash course before our final but anyway. The program gets the dividend and divisor correctly but for some reason div bx
ax/bx gives me an error when I have 10 in ax and 2 in bx. Why is that.

This is driving me up the wall because I did the exact same thing I did in another program and it worked.

Recommended Answers

All 2 Replies

Have you checked that the readint and writestring procedure does not modify ax or bx, readint and writestring must have this statements if they use ax or bx:

readint PROC
push   ax
push   bx

; some code

pop    bx
pop    ax
readint ENDP

Same for writestring procedure

What kind of error do you get, run-time or assembly time?

I don't see whats wrong, but:

mov ax, 0x8000
cwd                    ; sign extended word to dword, a.e. DX=FFFF
div bx                 ; DX:AX / BX
; try XOR'ing DX to zero.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.