Category : C Source Code
Archive   : CEXPRESS.ZIP
Filename : HEX2INT.ASM

 
Output of file : HEX2INT.ASM contained in archive : CEXPRESS.ZIP
;unsigned char _hex_to_int(hex_string);
; char *hex_string;

EXTRN _memory_model:byte
EXTRN _error_code:byte

_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
PUBLIC _hex_to_int
_hex_to_int proc near
push bp ;
mov bp,sp ;set stack frame
cmp _memory_model,0 ;near or far?
jle begin ;jump if near
inc bp ;else add 2 to BP
inc bp ;
begin: cmp _memory_model,2 ;data near or far?
jb L0 ;jump if near
les di,[bp+4] ;
jmp short L1 ;
L0: mov di,[bp+4] ;
mov ax,ds ;ES = DS
mov es,ax ;
L1: sub ax,ax ;return 0 if error
mov dl,0 ;counts chars
mov _error_code,1 ;errorcode 1 = null string
cmp byte ptr es:[di],0 ;null?
je L6 ;quit if so
LY: cmp byte ptr es:[di],0 ;move ptr to end of string
je L2 ;
inc di ;
jmp short LY ;
L2: sub bx,bx ;
dec di ;move ptr back one
mov bl,es:[di] ;get a char
cmp bl,0 ;end of string?
je LX ;
cmp bl,0 ;end of string?
je L6 ;quit if so
inc _error_code ;errorcode 2 = char out of range
cmp bl,48 ;test range
jb L6 ;
cmp bl,57 ;
jna L4 ;
cmp bl,97 ;
jnb L3 ;
add bl,32 ;make lower case
L3: cmp bl,97 ;'a'
jb L6 ;
cmp bl,102 ;'f'
ja L6 ;
sub bl,87 ;make numeric
jmp short L5 ;
L4: sub bl,48 ;make numeric
L5: mov cl,dl ;
shl cl,1 ;multiply by four
shl cl,1 ;
shl bx,cl ;move mask to position
or ax,bx ;copy over the nibble
inc dl ;inc counter
cmp dl,4 ;
jne L2 ;loop
LX: mov _error_code,0 ;no error
L6: pop bp ;
cmp _memory_model,0 ;quit
jle quit ;
db 0CBh ;RET far
quit: ret ;RET near
_hex_to_int endp
_TEXT ENDS
END


  3 Responses to “Category : C Source Code
Archive   : CEXPRESS.ZIP
Filename : HEX2INT.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/