Am working on an ALP(for 8086) which is meant to calculate and display the averages of students on different courses offered. After calculations, i want the averages to be displayed in this format: 58.9 60.2 30.8... etc. but the DIV operation only keeps the remainder and not the decimal. which implies that an arithmetic 3/2 will result 1 remainder 1 instead of 1.5. How do i get the decimal?
Multiply by 10, insert a dot.
Which? the integer or the remainder?
calculate the (average X 10)
that will give you numbers like 589 602 308... etc
then, you insert the decimal point as text to get 58.9 60.2 30.8... etc
Hi roivic,
welcome to the forum. To your question: for the 8086, the dividend has to be in AX, the divisor can be a memory location or another register. The result is in AX, the remainder in DX. Hope that helps. You'll find this information inside the Intel or AMD manuals (that download is a MUST).
Gunther
masm32.com/board/index.php?topic=1226.15
Thanks, i already know the result stays in AX and the remainder stays in DX, my problem is actually how to convert the remainder to decimal. e.g these instructions
- MOV AX, 3H
- MOV BX, 2H
- DIV BX
leaves 1H in AX and 1H in DX but i want my answer as 1.5
Thanks hool, followed the link but it kind of look complex :(
Hi roivic,
Quote from: roivic on January 20, 2013, 09:39:47 AM
Thanks, i already know the result stays in AX and the remainder stays in DX, my problem is actually how to convert the remainder to decimal. e.g these instructions
- MOV AX, 3H
- MOV BX, 2H
- DIV BX
leaves 1H in AX and 1H in DX but i want my answer as 1.5
I understand. An easy way to do that is to use floating point numbers and the FPU will bring you the right result. Check out Ray's FPU tutorial http://www.website.masmforum.com/tutorials/fptute/ (http://www.website.masmforum.com/tutorials/fptute/)
Gunther
mov ax,3
mov bx,10
mul bx
mov bl,2
div bx
;ax = 15
;additional code to round to nearest
shl dx,1
cmp dx,bx
sbb ax,-1
now, when you convert AX to ASCII decimal, you will get 15
you can insert a decimal point to make it 1.5
Ok thanks