TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: DANIEL TROY
from: HUGH NOLAND
date: 1997-09-27 09:11:00
subject: hex2decimal

Daniel Troy wrote:
DT> can anyone improve my rather shitty and long algorythm to convert hex
DT> into decimal???
 
I didn't go over your code, but maybe the following will help:
 
;---------------------------------------------------------------------------
;write value in AX as decimal
;all registers except AX are preserved
;---------------------------------------------------------------------------
write_dec   proc
   push bx                         ;
   push cx                         ;save registers
   push dx                         ;
   mov cx,0                        ;will keep digit count in cx
   mov bx,10                       ;convert to decimal by dividing by 10
w1:
   xor dx,dx
   div bx                          ;divide by 10--store remainder(=last 
decimal
   push dx                         ;digit) on stack
   inc cx                          ;digit-count in cx
   or ax,ax                        ;
   jnz w1                          ;repeat if quotient non-zero
 
   mov bh,0                        ;bh = display-page
w2:
   pop ax                          ;pop digits off stack and output to screen
   add al,30h                      ;(remember cx = number of digits)
   mov ah,0eh                      ;
   int 10h                         ;
   loop w2                         ;
 
   pop dx
   pop cx
   pop bx
   ret
write_dec   endp
--- Maximus/2 3.01
---------------
* Origin: Madman BBS * Chico, California * 916-893-8079 * (1:119/88)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.