hex.asm
来自「汇编&c语言code」· 汇编 代码 · 共 64 行
ASM
64 行
; Turbo Assembler Copyright (c) 1988, 1991 By Borland International, Inc.
; HEX.ASM
; From the Turbo Assembler Users Guide
CODE SEGMENT
ASSUME cs:CODE,ds:NOTHING
; Parameters (+2 because of push bp)
byteCount EQU BYTE PTR ss:[bp+6]
num EQU DWORD PTR ss:[bp+8]
; Function result address (+2 because of push bp)
resultPtr EQU DWORD PTR ss:[bp+12]
HexStr PROC FAR
PUBLIC HexStr
push bp
mov bp,sp ;get pointer into stack
les di,resultPtr ;get address of function result
mov dx,ds ;save Turbo's DS in DX
lds si,num ;get number address
mov al,byteCount ;how many bytes?
xor ah,ah ;make a word
mov cx,ax ;keep track of bytes in CX
add si,ax ;start from MS byte of number
dec si
shl ax,1 ;how many digits? (2/byte)
cld ;store # digits (going forward)
stosb ;in destination string's length byte
HexLoop:
std ;scan number from MSB to LSB
lodsb ;get next byte
mov ah,al ;save it
shr al,1 ;extract high nibble
shr al,1
shr al,1
shr al,1
add al,90h ;special hex conversion sequence
daa ;using ADDs and DAA's
adc al,40h
daa ;nibble now converted to ASCII
cld ;store ASCII going up
stosb
mov al,ah ;repeat conversion for low nibble
and al,0Fh
add al,90h
daa
adc al,40h
daa
stosb
loop HexLoop ;keep going until done
mov ds,dx ;restore Turbo's DS
pop bp
ret 6 ;parameters take 6 bytes
HexStr ENDP
CODE ENDS
END
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?