How to display 11.1 after div in assembly?

How to display 11.1 after div? For example, 32/5 = 6.4, I can only display 6, so how do I display 6.4?

OUT23:

    MOV BL,CNT  ;CNT is the total number of even number
    DIV BL
    MOV DL,AL
    MOV BH,AL
    MOV AH,09H
    LEA DX,MSG23
    INT 21H
    MOV DL,BH   ;print out the average, only the integer part able to display
    MOV AH,02
    ADD DL,30H
    INT 21H
+3
source share
3 answers

DIV- integer division instruction. If you want floating point division, you need to look FDIV.

+2
source

As already mentioned, DIVperforms integer division. Since this is integer division, the resulting coefficient and the remainder are available in separate pairs of registers, the exact registers depend on the size of the divider.

1 byte divider

AX - Dividend
AH - Remainder
AL - Quotient

2 byte divider

DX:AX - Dividend
DX - Remainder
AX - Quotient

4 byte divider

EDX:EAX - Dividend
EDX - Remainder
EAX - Quotient

1- 'BL', AH. 32/5 AL 6, AH 2, , 2/5, 0.4 6.4.

FPU, 32 5 FPU FLD, , FDIV, FPU, FPU.

FSTP. , , IEEE , .

+2

, , . , 10 ,

32/5

  • :

    32/5 = 6 → Print out "6."
    
  • :

    Remainder: 2, multiply it by 102*10 = 20
    20/5 = 4 → Print out "4"
    Remainder: 0, stop here
    

, , 10 . , , . : 25/11 = 2.27272727...

  25/11 = 2 R 32.
3*10/11 = 2 R 82
8*10/11 = 7 R 37
3*10/11 = 2 R 82
8*10/11 = 7 R 37
and so on...

, , 10 N, N


FDIV FDIV . , , , .

:

  • Separate the whole part of the result and print it, and then .
  • Multiply the integer by 10, the integer will be the next fractional digit
  • Remove the integer part and repeat the above step until you reach the desired accuracy.

A rough example is like this, ignoring errors due to binary floating point properties

11.157
Int part: 11    → print 11.
Fractional part:
0.157*10 = 1.57 → print 1
 0.57*10 = 5.7  → print 5
  0.7*10 = 7    → print 7

More information can be found in Turn float to string.

+2
source

Source: https://habr.com/ru/post/1791679/


All Articles