; Expects...
;   AX      = word to be converted
;   DS:SI = segment:offset of where to put it
Word2String
   mov cx, ax            ; hold on to ax as it will be trashed soon
   xchg ah, al            ; swap high & low bytes to do it in the right order
   call Byte2String   
   mov ax, cx            ; reload ax - it has been trashed by Byte2String
   add si, 2            ; increment our destination
   call Byte2String
   ret

; Expects...
;   AL      = byte to be converted
;   DS:SI = segment:offset of where to put it
Byte2String:
   mov di, hex_digits   ; lookup table

   mov bx, ax            ; scratch space

   and bx, 0x000f         ; mask top bits.  I have to use BX 
                        ;  rather than just deal with BL,
                        ;  because later I offset by BX,
                        ;  and garbage in BH could screw that up

   mov ah, [di + bx]      ; temp copy to ah.  can't
                        ;  directly copy mem to mem

   mov [si + 1], ah      ; copy temp to destination
   
   mov bl, al            ; now doing second digit - copy again

   shr bl, 4            ; shift down.  BH is still clean, so no need
                        ;  to AND it as we did for first digit
                        ;
                        ; note - this consufes DEBUG - it only knows
                        ;  about the old-style SHR using CL as the shift
                        ;  amount

   mov ah, [di + bx]      ; another temp copy
   mov [si], ah         ; and copy to destination

   ret

-- MattWalsh - 24 Apr 2004

Topic revision: r1 - 24 Apr 2004 - 20:16:00 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback