Coder's Guild Mailing List

Re: Printig Long Ints in Assembly

Posted by Dmitry Uvarov on 1999-05-11

On Tue, 11 May 1999, Ali Bhai wrote:

> Hi senior assembly coders,
> 
> I am sure that you people must have faced the same problem ie printing
> double words in assembly. The limit of div instruction doesn't allow us to
> do so. I don't want to use math coprocessor. I want to write pure 8086 code
> that prints long ints. The algorithm I have implemented repeatedly divides a
> number by 10 and stores the remainders. When the quotient becomes 0, I
> reprint the values after popping them off the stack. This works for short
> ints (word in pascal and assembly 0 - 65535).
> 
> However, the same algo doesn't work for double word greater than 0009FFFFh
> ie dx:ax = 0009:FFFFh. Division by zero (ie overflow occurs when division of
> this number by 10 takes place). Can you help me out?
> 
Division by zero may be if:
 1) you really divide by zero ;)
 2) division result is overflow:
        div instruction needs to have double word in dx:ax and result is
placed into ax. If result doesnt fit in ax it cause division by zero
error.
Try to use 386 div instruction:
  edx:eax - source qword; -> eax = result.
you can extend your double word to qword by placing it into eax register
and then use cdq instruction.

Dmitry
ICQ# 20079823
homepage: http://pascal.bizhosting.com
-----------------------------------------------------------------------
I'm going to live forever, or die trying!
        -- Spider Robinson