home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
_tr_hexa.asm
< prev
next >
Wrap
Assembly Source File
|
1990-10-21
|
3KB
|
101 lines
; _TR_HEXA.ASM
;
; by Ralph Davis, Leonard Zerman
;
; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
;
; Syntax: HEX(numvar) && numvar is a numeric variable
;
; Function to convert long integer passed via the
; C interface routine (HEX.C) to hexadecimal string
;
PUBLIC __TR_HEXASM
;========================================================
; Useful macro
HEXCNVT MACRO
AND AL,0FH
ADD AL,90H ; Convert to ASCII hex digit
DAA
ADC AL,40H
DAA
ENDM
;========================================================
DGROUP GROUP _DATA
;********************************************************
_DATA SEGMENT WORD PUBLIC 'DATA'
HEXSTRING DB 8 DUP (' '),0
_DATA ENDS
;********************************************************
;********************************************************
_TR_HEXA_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TR_HEXA_TEXT,DS:_DATA
;--------------------------------------------------------
__TR_HEXASM PROC FAR
PUSH BP
MOV BP,SP
PUSH DS
MOV AX,DGROUP
MOV DS,AX
PUSH CX
PUSH SI
MOV SI,OFFSET DGROUP:HEXSTRING
MOV AX,[BP+8] ; load high byte into AX
MOV BX,[BP+6] ; and low byte into BX
OR AX,AX ; Is AX all zeroes?
JZ CX4 ; Yes, process as 4-digit number
TEST_BX_SN: OR BX,BX ; Is sign bit of BX on?
JNS CX8 ; No, so AX can't be sign extension
CMP AX,0FFFFH ; Yes--check if AX all 1 bits
JNE CX8 ; AX not sign extension of BX
CX4: MOV CX,4
CLC
ROTATE_INT:
REPT 4
ROL BX,1
ENDM
MOV AL,BL
HEXCNVT
MOV [SI],AL
INC SI
LOOP ROTATE_INT
JMP SHORT EXIT
CX8: MOV CX,8
CLC
ROTATE_LONG:
REPT 4
RCL BX,1 ; Shift MSB into lower nibble
RCL AX,1 ; of BX
ADC BX,0 ; Move carry bit from AX into BX
ENDM
PUSHF
PUSH AX
MOV AL,BL
HEXCNVT
MOV [SI],AL
INC SI
POP AX
POPF
LOOP ROTATE_LONG
EXIT: MOV BYTE PTR [SI],0
MOV DX,DS
MOV AX,OFFSET DGROUP:HEXSTRING
POP SI
POP CX
POP DS
POP BP
RET
__TR_HEXASM ENDP
;-------------------------------------------------------------
_TR_HEXA_TEXT ENDS
;***************************************************************
END