News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Getting decimals

Started by roivic, January 19, 2013, 06:06:39 PM

Previous topic - Next topic

roivic

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?

jj2007

Multiply by 10, insert a dot.

roivic

Which? the integer or the remainder?

dedndave

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

Gunther

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
You have to know the facts before you can distort them.

hool

masm32.com/board/index.php?topic=1226.15

roivic

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

roivic

Thanks hool, followed the link but it kind of look complex :(

Gunther

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/

Gunther
You have to know the facts before you can distort them.

dedndave

    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

roivic