0
;==================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.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by NotNull
0

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?

0

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.

Edited by NotNull: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.