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

📄 printff.asm

📁 汇编编程艺术
💻 ASM
📖 第 1 页 / 共 2 页
字号:
		call	sl_LSFPA
DoTheReste:	mov	ax, cx
		call	pute
		xchg	di, bx
		ret
;
PrintDPFP:	call	GetPtr
		xchg	di, bx
		call	sl_LDFPA
		jmp	DoTheRestf
;
PrintDPFPE:	call	GetPtr
		xchg	di, bx
		call	sl_LDFPA
		jmp	DoTheReste
;
PrintEPFP:	call	GetPtr
		xchg	di, bx
		call	sl_LEFPA
		jmp	DoTheRestf
;
PrintEPFPE:	call	GetPtr
		xchg	di, bx
		call	sl_LEFPA
		jmp	DoTheReste
;
;
;
; Print a signed decimal value here.
;
PrintDec:	call	GetPtr			;Get next pointer into ES:BX
		mov	ax, es:[bx]		;Get value to print.
		call	ISize			;Get the size of this guy.
		sub	al, cl			;Compute padding size
		neg	al
		cbw
		mov	cx, ax
		mov	ax, es:[bx]		;Retrieve value to print.
		js	NoPadDec		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustDec
		call	PrintPad		;Print padding characters
		call	Puti			;Print the integer
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustDec:	call	Puti
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadDec:	call	Puti
		ret
;
;
;
; Print a character variable here.
;
PrintChar:	call	GetPtr			;Get next pointer into ES:BX
		mov	al, es:[bx]		;Retrieve value to print.
		mov	ch, 0
		dec	cx
		js	NoPadChar		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustChar
		call	PrintPad		;Print padding characters
		call	Putc			;Print the character
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustChar:	call	Putc
		call	PrintPad
		ret
;
; Print non-justified character here:
;
NoPadChar:	call	Putc
		ret
;
;
;
;
; Print a hexadecimal word value here.
;
PrintHexWord:	call	GetPtr			;Get next pointer into ES:BX
		mov	ax, es:[bx]		;Get value to print.
		mov	ch, 0
		sub	cx, 4			;Compute padding
		js	NoPadHexW		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustHexW
		call	PrintPad		;Print padding characters
		call	Putw			;Print the hex value
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustHexW:	call	Putw
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadHexW:	call	Putw
		ret
;
;
;
;
; Print hex bytes here.
;
;
PrintHexByte:	call	GetPtr			;Get next pointer into ES:BX
		mov	ax, es:[bx]		;Get value to print.
		mov	ch, 0
		sub	cx, 2			;Compute padding
		js	NoPadHexB		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustHexB
		call	PrintPad		;Print padding characters
		call	Puth			;Print the hex value
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustHexB:	call	Puth
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadHexB:	call	Puth
		ret
;
;
;
; Output unsigned decimal numbers here:
;
PrintUDec:	call	GetPtr			;Get next pointer into ES:BX
		mov	ax, es:[bx]		;Get value to print.
		call	USize			;Get the size of this guy.
		mov	ch, 0
		sub	cx, ax		     	;Compute padding
		mov	ax, es:[bx]		;Retrieve value to print.
		js	NoPadUDec		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustUDec
		call	PrintPad		;Print padding characters
		call	Putu			;Print the integer
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustUDec:	call	Putu
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadUDec:	call	Putu
		ret
;
;
;
;
; Output a string here:
;
PrintString:	call	GetPtr			;Get next pointer into ES:BX
;
; Compute the length of the string:
;
		push	di
		push	cx
		mov	cx, -1
		mov	di, bx
		mov	al, 0
	repne	scasb
		mov	ax, cx
		neg	ax
		dec	ax
		dec	ax
		pop	cx
		pop	di
		mov	ch, 0
		sub	cx, ax			;Field width - String Length.
;
		js	NoPadStr		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustStr
		call	PrintPad		;Print padding characters
		call	Puts			;Print the string
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustStr:	call	Puts
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadStr:	call	Puts
		ret
GetFmtItem	endp
;
;
;
; Print a signed long decimal value here.
;
LongDec:	call	GetPtr			;Get next pointer into ES:BX
		mov	ax, es:[bx]		;Get value to print.
		push	dx
		mov	dx, es:2[bx]
		call	LSize			;Get the size of this guy.
		pop	dx
		mov	ch, 0
		sub	cx, ax		     	;Compute padding
		mov	ax, es:[bx]		;Retrieve value to print.
		js	NoPadLong		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustLong
		call	PrintPad		;Print padding characters
		mov	dx, es:2[bx]		;Get H.O. word
		call	PutL			;Print the integer
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustLong:	push	dx
		mov	dx, es:2[bx]		;Get H.O. word
		call	PutL
		pop	dx
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadLong:	mov	dx, es:2[bx]		;Get H.O. word
		call	Putl
		ret
;
;
; Print an unsigned long decimal value here.
;
LongU:		call	GetPtr			;Get next pointer into ES:BX
		mov	ax, es:[bx]		;Get value to print.
		push	dx
		mov	dx, es:[bx]
		call	ULSize			;Get the size of this guy.
		pop	dx
		mov	ch, 0
		sub	cx, ax		     	;Compute padding
		mov	ax, es:[bx]		;Retrieve value to print.
		js	NoPadULong		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustULong
		call	PrintPad		;Print padding characters
		mov	dx, es:2[bx]		;Get H.O. word
		call	PutUL			;Print the integer
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustULong:	push	dx
		mov	dx, es:2[bx]		;Get H.O. word
		call	PutUL
		pop	dx
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadULong:	mov	dx, es:2[bx]		;Get H.O. word
		call	Putul
		ret
;
;
; Print a long hexadecimal value here.
;
LongX:		call	GetPtr			;Get next pointer into ES:BX
		mov	ch, 0
		sub	cx, 8			;Compute padding
		js	NoPadXLong		;Is CX negative?
		cmp	dl, 0			;Right justified?
		jne	LeftJustXLong
		call	PrintPad		;Print padding characters
		mov	ax, es:2[bx]		;Get H.O. word
		call	Putw
		mov	ax, es:[bx]
		call	Putw
		ret				;We're done!
;
; Print left justified value here.
;
LeftJustxLong:	mov	ax, es:2[bx]		;Get H.O. word
		call	Putw
		mov	ax, es:[bx]		;Get L.O. word
		call	Putw
		call	PrintPad
		ret
;
; Print non-justified value here:
;
NoPadxLong:	mov	ax, es:2[bx]		;Get H.O. word
		call	Putw
		mov	ax, es:[bx]
		call	Putw
		ret
;
;
;
;
; Puts- Outputs the zero terminated string pointed at by ES:BX.
;
Puts		proc	near
PutsLp:		mov	al, es:[bx]
		cmp	al, 0
		je	PutsDone
		call	putc
		inc	bx
		jmp	PutsLp
;
PutsDone:	ret
Puts		endp
;
;
;
;
;
; PrintPad-	Prints padding characters.  Character to print is in DH.
;		We must print it CX times.  CX must be greater than zero.
;
PrintPad	proc	near
		push	ax
		mov	al, dh
		jcxz	NoPadding
PPLoop:		call	Putc
		loop	PPLoop
NoPadding:	pop	ax
		ret
PrintPad	endp
;
;
;
;
;
; GetPtr- Grabs the next pointer which DS:DI points at and returns this
;	  far pointer in ES:BX.
;
GetPtr		proc	near
		les	bx, [di]
		add	di, 4
;
; See if this is a handle rather than a pointer.
;
		cmp	ah, '^'
		jne	NotHandle
		les	bx, es:[bx]
NotHandle:	ret
GetPtr		endp
;
;
;
;
;
; GetDecVal-	Converts the string of decimal digits in AL and [SI] into
;		an integer and returns this integer in CL/CH.
;
GetDecVal	proc	near
		push	dx
		dec	si
		xor	cx, cx
DecLoop:	lodsb
		cmp	al, '0'
		jb	NoMore
		cmp	al, '9'
		ja	NoMore
		and	al, 0fh
		shl	cl, 1			;Compute CL := CL*10 + al
		mov	dl, cl
		shl	cl, 1
		shl	cl, 1
		add	cl, dl
		add	cl, al
		jmp	DecLoop
;
NoMore:		cmp	al, '.'
		jne	ReallyNoMore
;
; User entered nnn.nnn here.  Process for floating point values:
;
DecLoop2:	lodsb
		cmp	al, '0'
		jb	ReallyNoMore
		cmp	al, '9'
		ja	ReallyNoMore
		and	al, 0fh
		shl	ch, 1			;Compute CX := CX*10 + al
		mov	dh, ch
		shl	ch, 1
		shl	ch, 1
		add	ch, dh
		add	ch, al
		jmp	DecLoop2
;
ReallyNoMore:	pop	dx
		ret
GetDecVal	endp
;
stdlib		ends
		end

⌨️ 快捷键说明

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