⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strings.asm

📁 X86 GX1 BOOTLOAD代码 ,支持WINCE操作系统!
💻 ASM
字号:
;**************************************************************************
;*
;*  STRINGS.ASM
;*
;*  Copyright (c) 1998-1999 National Semiconductor Corporation.
;*  All Rights Reserved.
;*
;*  Function:
;*    Routines to print strings and numerical values on the screen.
;*
;*  $Revision:: 1   $
;*
;**************************************************************************

	.486P
	INCLUDE MACROS.INC
	INCLUDE DEF.INC
	INCLUDE PORT80.INC
	INCLUDE STRINGS.INC

_TEXT SEGMENT PUBLIC use16 'CODE'

	ASSUME CS:SEGGROUP

;**************************************************************************
;*
;*	HEX_DWORD
;*
;*	Display a dword value in hex (0..FFFFFFFF)
;*
;*	Entry:
;*	  EAX = DWORD to print
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
hex_dword PROC NEAR PUBLIC
	push	eax
	shr	eax, 16
	call	hex_word
	pop	eax
	call	hex_word
	ret
hex_dword ENDP

;**************************************************************************
;*
;*	HEX_WORD
;*
;*	Display a word value in hex (0..FFFF)
;*
;*	Entry:
;*	  AX = WORD to print
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
hex_word PROC	NEAR PUBLIC
ASSUME	ds:nothing, es:nothing
	xchg	ah, al
	call	hex_byte
	xchg	ah, al
hex_word ENDP

;**************************************************************************
;*
;*	HEX_BYTE
;*
;*	Display a byte value in hex (0..FF)
;*
;*	Entry:
;*	  AL = BYTE to print
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
hex_byte PROC	NEAR PUBLIC
	push	ax
	shr	al, 4
	call	hex_nibble
	pop	ax
hex_byte ENDP

;**************************************************************************
;*
;*	HEX_NIBBLE
;*
;*	Display a nibble value in hex (0..F)
;*
;*	Entry:
;*	  AL = nibble to print
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
hex_nibble PROC NEAR PUBLIC		; Print a hex nibble to the CRT
	push	ax
	and	al, 0Fh			; Strip off lower bits if necessary

; Convert Hex to ASCII

	add	al, 090H
	daa				; Decimal adjust for addition
	adc	al, 040H
	daa				; Decimal adjust for addition
	call	write_tty
	pop	ax
	ret
hex_nibble ENDP

;**************************************************************************
;*
;*	DEC_DWORD
;*
;*	Display a dword value in decimal (0..4294967295)
;*
;*	Entry:
;*	  EAX = DWORD to print
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
dec_dword	PROC NEAR PUBLIC
	pusha
	xor	edx, edx

	mov	ecx, 1000000000	; divide number by 100000000 to get first digit

dec_dword_zero:			; go through this loop until we reach a digit that is not zero
	div	ecx
	cmp	eax, 0
	jne	dec_dword_nonzero	;if the digit is not a zero, jump to the next loop, and print the char
	push	edx		; move the remainder into ax < 10000
	mov	eax, ecx
	mov	ecx, 10
	xor	edx, edx
	div	ecx
	mov	ecx, eax
	pop	eax
	xor	edx, edx
	cmp	ecx, 1
	jne	dec_dword_zero
	jmp	dec_dword_loop_done

dec_dword_loop:
	div	ecx
dec_dword_nonzero:
	call	hex_nibble	; print the first digit - will be < 9, so we can use hex nibble
	push	edx		; move the remainder into ax < 10000
	mov	eax, ecx
	mov	ecx, 10
	xor	edx, edx
	div	ecx
	mov	ecx, eax
	pop	eax
	xor	edx, edx
	cmp	ecx, 1
	jne	dec_dword_loop

dec_dword_loop_done:
	call	hex_nibble	; print the last digit, and we're done

	popa
	ret
dec_dword	ENDP

;**************************************************************************
;*
;*	DEC_WORD
;*
;*	Display a word value in decimal (0..65535)
;*
;*	Entry:
;*	  AX = WORD to print
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
dec_word	PROC NEAR PUBLIC
	pusha
	xor	dx, dx		; clear dx - we only want to print the value in ax

	mov	cx, 10000	; divide number by 10000 to get first digit
dec_word_zero:			; go through this loop until we reach a digit
	div	cx		;  that is not zero
	cmp	ax, 0
	jne	dec_word_nonzero	; if the digit is not a zero, jump to the next loop,
	push	dx		;  and print the char
	mov	ax, cx		; move the remainder into ax < 10000
	mov	cx, 10
	xor	dx, dx
	div	cx
	mov	cx, ax
	pop	ax
	xor	dx, dx
	cmp	cx, 1
	jne	dec_word_zero
	jmp	dec_word_loop_done

dec_word_loop:
	div	cx
dec_word_nonzero:
	call	hex_nibble	; print the first digit - will be < 9, so we can use hex nibble
	push	dx		; move the remainder into ax < 10000
	mov	ax, cx
	mov	cx, 10
	xor	dx, dx
	div	cx
	mov	cx, ax
	pop	ax
	xor	dx, dx
	cmp	cx, 1
	jne	dec_word_loop

dec_word_loop_done:
	call	hex_nibble	; print the last digit, and we're done

	popa
	ret
dec_word	ENDP

;**************************************************************************
;*
;*	DEC_BYTE
;*
;*	Display a byte value in decimal (0..255)
;*
;*	Entry:
;*	  AL = BYTE to print
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
dec_byte	PROC NEAR PUBLIC
	push	ax
	push	cx
	xor	ah, ah		; clear ah - we only want to print al

	mov	cl, 100		; divide al by 100 to get the first digit
	div	cl
	call	hex_nibble	; digit will be < 9 so printing the hex value is the same...
	mov	al, ah		; move the remainder into al - will be less than 100
	xor	ah, ah

	mov	cl, 10
	div	cl
	call	hex_nibble
	mov	al, ah

	call	hex_nibble

	pop	cx
	pop	ax
	ret
dec_byte	ENDP

;**************************************************************************
;*
;*	prints
;*
;*	Display an ASCIIZ string.
;*
;*	Entry:
;*	  DS:SI points to string
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
prints PROC NEAR PUBLIC
@@:	lodsb
	cmp	al, 0
	jz	SHORT @F
	call	write_tty
	jmp	SHORT @B

@@:
	ret
prints ENDP

;**************************************************************************
;*
;*	write_tty
;*
;*	Generic TTY routine
;*
;*	Entry:
;*	  AL = character to display
;*
;*	Output:
;*	  TTY/STDOUT display
;*
;*	Destroys:
;*
;**************************************************************************
write_tty PROC NEAR PUBLIC
	write_stdout
	ret
write_tty ENDP

;**************************************************************************
;*
;*	displayMessage
;*
;*	Entry:
;*	Output:
;*	Destroys:
;*
;**************************************************************************
displayMessage PROC NEAR PUBLIC
	push	ax
	push	cx
	push	si
	mov	cx, 1
here1:
	mov	al, byte PTR cs:[si]
	cmp	al, '$'
	je	here2

	pusha
	mov	ah, 0eh
	int	010h
	popa

	inc	si
	jmp	here1
here2:
	pop	si
	pop	cx
	pop	ax
	ret
displayMessage ENDP



;**************************************************************************
;*
;*	dumpCxEsSi
;*
;*	Entry:
;*	Output:
;*	Destroys:
;*
;**************************************************************************
dumpCxEsSi PROC NEAR PUBLIC
	push	ax
	push	cx
	push	si
here1:
	mov	al, byte PTR es:[si]
	cmp	cx, 0
	je	here2

	dec	cx
	pusha
	call	hex_byte
	popa

	inc	si
	jmp	here1
here2:
	pop	si
	pop	cx
	pop	ax
	ret
dumpCxEsSi ENDP

_TEXT ENDS	

END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -