Question

Can anyone tell me whats wrong with the div bl instruction in this block of code? Im trying to divide 10/20 and the result should be 0.5. a(DB) and b(DB)

    mov al,  b; b==10
    mov bl,  a; a==20
    div bl ;
    mov bh, ah

Now i get 10 in ah, but the second problem is that i need to resolve (3*a-b/a) so

    mov ah,a; a=20
    mov al,3
    mul ah 
    mov cx,ax; cx=60

    mov al,b
    mov ah,0
    mov bl,a
    div bl
    mov bx, ax

    sub cx,bx

and it doesnt work

Was it helpful?

Solution

DIV is for integer division. 10/20 is 0, and the remainder is 10.

8-bit divide uses AH:AL (or AX) as the source register, placing the result in AL and the remainder in AH. (You seem to have left AH uninitialized).

Fixed point representation of 0.5 is possible with integer arithmetic by first multiplying the source '10' by number of fractions.

e.g.

 Base 10:
 10 * 1000  = 10,000 = "10000 / 1000"   = "ten"
 10000 / 20 =    500 = "  500 / 1000"   = "zero point five"

 Base 16:
 10 * 256 = 10 << 8 = 0x0A00 = 10*256 / 256 = "ten"
 0x0A00 / 20 =        0x0080 =    128 / 256 = "zero point five"

OTHER TIPS

First, div bl would divide ax contents and you only set al. The result will be al set to 0 (quotinent) and ah set to 10 (remainder). There's no way for result becoming 0.5 - integer division never yields non-integer results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top