Category : Miscellaneous Language Source Code
Archive   : MTD.ZIP
Filename : COMMON.ASM

 
Output of file : COMMON.ASM contained in archive : MTD.ZIP
;**
;** Purpose: Common routines for ASM programs.
;** Author: (c) 1990 by Tom Swan.
;**
;** To compile:
;** tasm /zi common
;**

COMMON_code SEGMENT para public 'CODE'
ASSUME cs:COMMON_code, ds:nothing, es:nothing
PUBLIC HexDigit, IntToHex

;---------------------------------------------------------------
; HexDigit Convert 4-bit value to ASCII hex digit
;---------------------------------------------------------------
; Input:
; dl = value limited to range 0..15
; Output:
; dl = ASCII hex digit equivalent
; Registers:
; dl
;---------------------------------------------------------------
HexDigit PROC near

cmp dl, 10 ; Is dl < 10 (i.e. hex 'A')?
jb HD_10 ; If yes, jump
add dl, 'A'-10 ; Else convert to A...F
ret ; Return to caller
HD_10:
or dl, '0' ; Convert digits 0 to 9
ret ; Return to caller

HexDigit ENDP

;---------------------------------------------------------------
; IntToHex Convert unsigned integer to ASCII hex string
;---------------------------------------------------------------
; Input:
; ax = 16-bit value to convert
; cx = minimum number of digits to output
; es:di = address of string large enough to hold result
; Output:
; es:di = address of byte after last inserted character
; Registers:
; ax, bx, cx, dx, si, di
;---------------------------------------------------------------
IntToHex PROC near

mov bx, 16 ; Radix = 16 (hex)
xor si, si ; Set digit-count to zero
jcxz ITH_20 ; If cx=0, jump to set cx=1
ITH_10:
xor dx, dx ; Extend ax to 32-bit dxax
div bx ; ax<-axdx div bx; dx<-remainder
call HexDigit ; Convert dl to ASCII digit
push dx ; Save digit on stack
inc si ; Count digits on stack
loop ITH_10 ; Loop on minimum digit count
ITH_20:
inc cx ; Set cx = 1 in case not done
or ax, ax ; Is ax = 0? (all digits done)
jnz ITH_10 ; If ax<>0, continue conversion
mov cx, si ; Set cx to stack char count
jcxz ITH_40 ; Skip next loop if cx=0000
cld ; Auto-increment di for stosb
ITH_30:
pop ax ; Pop next digit into al
stosb ; Store digit in str; advance di
loop ITH_30 ; Loop for cx digits
ITH_40:
ret ; Return to caller

IntToHex ENDP ; End of procedure

COMMON_code ENDS ; End of COMMON code segment
END ; End of COMMON module


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : MTD.ZIP
Filename : COMMON.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/