Question

I am having trouble printing the value in al after I divide. I keep getting a weird ascii character, not the 3 like im supposed to be getting. If I put in a instuction mov al,5 it prints perfectly. Any help will be appreciated. Here is the code:

    mov ax,32511
    mov cx,10000

    div cx        ;divide 7eff by 2710.  Result in al will be 3. 

    add al,'0'    ;convert to ascii

    mov ah,2      ;print
    mov dl,al
    int 21h

No correct solution

OTHER TIPS

div cx is actually dividing dx:ax - you should zero dx beforehand for the result you expect.

To expand, it's performing: (dx * 0x10000 + ax) / cx, storing the quotient in ax, and the remainder in dx. If the quotient does not fit in ax, that is: dx >= cx, a divide (overflow) error is raised.

div cx divides dx:ax by cx. So you should clear dx beforehand.

Found the issue, it was my own stupidity.

didnt add this first

    mov       ax,@data            ; establish addressability
    mov       ds,ax               ; for the data segment   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top