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

📄 utl.asm

📁 8086汇编语言编写的文本编辑器源码,功能比较简单
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	cmp	al,'0'
	jc	@isalphnum_99		;Not alphanumeric
	cmp	al,'9'+1
	cmc
	jnc	@isalphnum_99		;Number
	cmp	al,'A'
	jc	@isalphnum_99		;Not alphanumeric
	cmp	al,'Z'+1
	cmc
	jnc	@isalphnum_99		;Uppercase letter
	cmp	al,'a'
	jc	@isalphnum_99		;Not alphanumeric
	cmp	al,'z'+1
	cmc
@isalphnum_99:
	ret
isalphnum endp



;+
; FUNCTION : iscntrl
;
;	Check if control character and DEL (00h-1Fh and 0FFh).
;
; Parameters:
;	AL	= character to be checked
;
; Returns:
;	CF	= 0 if AL is a control character or DEL
;		  1 not a control char or DEL
; Register(s) destroyed:
;-
iscntrl	proc	near
	cmp	al,DEL
	jne	@iscntrl_99
	cmp	al,' '
	cmc
@iscntrl_99:
	ret
iscntrl	endp



;+
; FUNCTION : isspace
;
;	Check if a character is a SPACE or a TAB
;
; Parameters:
;	AL	= character to check
;
; Returns:
;	ZF	= 1 if AL is a space or a tab
;		  0 otherwise
; Register(s) destroyed:
;
;-
isspace	proc	near
	cmp	al,TAB
	je	@isspace_99
	cmp	al,SPACE
@isspace_99:
	ret
isspace	endp



;+
; FUNCTION : isdelim
;
;	Check if a character is an MSDOS delimiter.
;
; Parameters:
;	AL	= character to check
;
; Returns:
;	ZF	= 1 if AL is a delimiter
;		  0 otherwise
; Register(s) destroyed:
;
;-
isdelim	proc	near
	call	near ptr isspace	;Check if space or tab
	je	@isdelim_99		;Yes, go return
	cmp	al,'/'
	je	@isdelim_99		;Yes, go return
	cmp	al,'|'
	je	@isdelim_99		;Yes, go return
	cmp	al,'<'
	je	@isdelim_99		;Yes, go return
	cmp	al,'>'
@isdelim_99:
	ret
isdelim	endp



;+
; FUNCTION : skip_whitespace
;
;	Searches for the next non-whitespace character in a given string.
;
; Parameters:
;	SI	-> pointer to string
;	CX	== num chars in the string
;
; Returns:
;	CF	= 1 if end-of string reached else 0
;	SI	->next non-whitespace character or end-of-string
;	CX	<-num remaining characters including one pointed to by SI
;
; Register(s) destroyed:
;	AX
;-
skip_whitespace proc near
	jcxz	@skip_whitespace_98		;Empty string
@skip_whitespace_10:
	lodsb					;AL<-next char
	call	near ptr isspace		;Whitespace character ?
	loope	@skip_whitespace_10		;Repeat until
;						 non-whitespace or string ends
	je	@skip_whitespace_98		;End-of-string
; Non-whitespace char found
	dec	si				;SI->non-whitespace char
	inc	cx				;CX<-remaining number of bytes
	clc					;CF<-0 (char found)
	jmp	short @skip_whitespace_99

@skip_whitespace_98:
; End of string reached.
	stc					;Set CF

@skip_whitespace_99:
	ret
skip_whitespace endp




;+ FUNCTION : skip_nonwhite, skip_nondelim
;
;	Searches for the next whitespace character / delimiter in a given
;	string.
;
; Parameters:
;	SI	-> pointer to string
;	CX	== num chars in the string
;
; Returns:
;	CF	= 1 if end-of string reached else 0
;	SI	->next whitespace character or end-of-string
;	CX	<-num remaining characters including one pointed to by SI
;
; Register(s) destroyed:
;	AX
;-
skip_non proc near
skip_nonwhite LABEL near
	push	dx
	mov	dx,offset DGROUP:isspace
	jmp	short @skip_non	

skip_nondelim LABEL near
	push	dx
	mov	dx,offset DGROUP:isdelim
@skip_non:
	jcxz	@skip_non_98			;Empty string
@skip_non_10:
	lodsb					;AL<-next char
	call	dx				;nonwhite / delimiter
;						 character ? 
	loopne	@skip_non_10			;Repeat until
;						 whitespace or string ends
	jne	@skip_non_98			;End-of-string
; whitespace char found
	dec	si				;SI->whitespace char
	inc	cx				;CX<-remaining number of bytes
	clc					;CF<-0 (char found)
	jmp	short @skip_non_99

@skip_non_98:
; End of string reached.
	stc					;Set CF

@skip_non_99:
	pop	dx
	ret
skip_non endp






;+
; FUNCTION : push_word
;
;	Looks for the next word (delimited by whitespace) and pushes it
;	onto the specified string stack.
;
; Parameters:
;	BX	-> strstack descriptor
;	SI	-> string
;	CX	== length of string (< 256)
;
; Returns:
;	AX	<- 0 if no errors
;		  -1 if no room in stack
;		  +1 if no word in string
;	SI	-> char after first word (or end-of-string)
;	CX	<- num remaining characters
;
; Register(s) destroyed:
;	DX
;-
push_word proc	near
; Skip forward to first word
	call	near ptr skip_whitespace	;Returns
;						 SI->start of word
;						 CX<-remaining chars
	jcxz	@push_word_98			;No words in line
	mov	dx,si				;DX->start of word
	push	cx				;Save count
	call	near ptr skip_nonwhite		;Find end of word
;						 SI->beyond word
;						 CX<-remaining chars
	pop	ax
	sub	ax,cx				;AX<-length of word
	push	cx				;Save remaining char count
	xor	cx,cx				;CX<-0 (don't force push)
	call	near ptr strstk_push		;Store macro name into
;						 macro stack. Params
;						 AX,BX,CX,DX
;						 Returns Cf = 0 or 1
	pop	cx				;CX<-remaining character
;	Assume no error
	mov	ax,0	;DON'T DO xor ax,ax SINCE CF to be preserved
	jnc	@push_word_99			;Jump if no error
	dec	ax				;Error AX <- -1
	jmp	short @push_word_99		;Exit

@push_word_98:
; No words found in line. Set return codes.
	mov	ax,1				;Code for blank line

@push_word_99:
	ret
push_word	endp





;+
; FUNCTION : push_string
;
;	Pushed the specified string onto the specified stack.
;
; Parameters:
;	BX	-> strstack descriptor
;	SI	-> string
;	CX	== length of string must be < 256
;
; Returns:
;	CF	<- 0 if no errors
;		   1 if no room in stack
;
; Register(s) destroyed:
;	AX,CX,DX
;-
push_string proc	near
	mov	dx,si				;DX->start of string
	mov	ax,cx				;AX<-length of string
	xor	cx,cx				;CX<-0 (don't force push)
	call	near ptr strstk_push		;Store macro name into
;						 macro stack. Params
;						 AX,BX,CX,DX
;						 Returns Cf = 0 or 1
	ret
push_string	endp



;+
; FUNCTION : bell
;
;	Called to ring the bell.
;
; Parameters:
;	None.
;
; Returns:
;	Nothing.
; Register(s) destroyed:
;	AX
;-
bell	proc	near
	cmp	silent,1
	je	@bell_99
	@DispCh	BEL
@bell_99:
	ret
bell	endp


;+
; FUNCTION : output_counted_string
;
; Parameters :
;	CX - Number of bytes to display
;	DX - address of string
; Registers destroyed:
;	AX,BX,CX,DX
output_counted_string proc near
	mov	ah,40h
	mov	bx,1				;stdout handle
	int	21h				;Params ax,bx,cx,dx
	ret
output_counted_string endp

;+
; FUNCTION: output_newline
;
; Registers destroyed:
;	AX,BX,CX,DX
;-
output_newline proc near
	@DispCh	CR
	@DispCh	LF
	ret
output_newline endp






CSEG	ENDS

	END

⌨️ 快捷键说明

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