This proc is cut straight out of the 16-bit UCR Standard Library. It takes an integer in AX and should output it character by character ( I think ) using a call to a proc called sl_putc.

However, I tried this code...

and its giving a 'divide overflow'. This doesn't seem right that this should cause an error. Seems like quite basic usage.

Also, can someone explain how this function acutally does what it is supposed to do? There's barely any reference to AX so how is it managing to convert a number to ASCII??

Cheers,

S.

```
```

; PutI2- Iterative routine to actually print the value in AX as an integer.

; (Submitted by David Holm)

;

Puti2 proc near

push bx

push cx

push dx

mov bx, 10

xor cx, cx

Puti2Lp: xor dx, cx

div bx

or dl, '0'

push dx

inc cx

or ax, ax

jnz Puti2Lp

Popi2lp: pop ax

call sl_putc

loop Popi2lp

pop dx

pop cx

pop bx

ret

PutI2 endp

However, I tried this code...

```
```

mov ax, 12

call sl_Puti

and its giving a 'divide overflow'. This doesn't seem right that this should cause an error. Seems like quite basic usage.

Also, can someone explain how this function acutally does what it is supposed to do? There's barely any reference to AX so how is it managing to convert a number to ASCII??

Cheers,

S.

The divide instruction operates on DX:AX putting the remainder in DX and the quotient in AX. The algorithm divides by 10 - putting digits on the stack from least significant to most significant. The digits are removed from the stack and stored somewhere.

If we are going to debug "sl_Puti" then you should post the code for that routine. :grin:

But the problem with the above routine is:

If we are going to debug "sl_Puti" then you should post the code for that routine. :grin:

But the problem with the above routine is:

`Puti2Lp: xor dx, cx`

...should be:`Puti2Lp: xor dx, dx`

Thankyou for your help. That change has made it start working.

I started to figure out what it was doing last night too. Just didn't register that the 'div' was operating on ax.

How strange that such a blatant error is in this library. Randall wrote yesterday that MASM 6.11b broke this library and that's why it was discontinued. Well, perhaps that's not the only thing which broke it!

I started to figure out what it was doing last night too. Just didn't register that the 'div' was operating on ax.

How strange that such a blatant error is in this library. Randall wrote yesterday that MASM 6.11b broke this library and that's why it was discontinued. Well, perhaps that's not the only thing which broke it!

This proc is cut straight out of the 16-bit UCR Standard Library. It takes an integer in AX and should output it character by character ( I think ) using a call to a proc called sl_putc.

```
```

; PutI2- Iterative routine to actually print the value in AX as an integer.

; (Submitted by David Holm)

;

Puti2 proc near

push bx

push cx

push dx

mov bx, 10

xor cx, cx

Puti2Lp: xor dx, cx

div bx

or dl, '0'

push dx

inc cx

or ax, ax

jnz Puti2Lp

Popi2lp: pop ax

call sl_putc

loop Popi2lp

pop dx

pop cx

pop bx

ret

PutI2 endp

However, I tried this code...

```
```

mov ax, 12

call sl_Puti

and its giving a 'divide overflow'. This doesn't seem right that this should cause an error. Seems like quite basic usage.

Also, can someone explain how this function acutally does what it is supposed to do? There's barely any reference to AX so how is it managing to convert a number to ASCII??

Cheers,

S.

Boy, this is an *old* bug. What version of the library did you grab?

The "xor dx,cx" instruction should really be "xor dx, dx".

As for the why and how, check out the 16-bit edition of "The Art of Assembly Language".

IIRC, it describes this algorithm somewhere (probably in the chapter on extended

precision arithmetic). This is *old* knowledge though. If it's not explained in the

16-bit edition, the 32-bit edition certainly explains the basic algorithm.

Cheers,

Randy Hyde

Hi there.

The latest item in the version history is - Version 2.4 12-7-91. (Hmm, that's about when I left secondary school.)

I got it from programmersheaven.com

The latest item in the version history is - Version 2.4 12-7-91. (Hmm, that's about when I left secondary school.)

I got it from programmersheaven.com