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

📄 dos-lib.asm

📁 这是汇编器的源代码
💻 ASM
字号:
extern msg_info

global open_file,create_file,close_file,read_file,write_file,alloc_memory,dealloc_memory,print,printc,get_cmdline,resize_memory

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Funktionen
section code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Opens a file
;;	Input :
;;	AL = 0 (read-only) / 1 (write-only) / 2 (read*write)
;;	Output :
;;	AX = 0xFFFF (error) / file handle
open_file:
	push dx

	mov ah,3dh
	int 21h

	jnc .end

	call ferror

.end
	pop dx
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
create_file:
	push dx

	mov ah,3ch
	int 21h

	jnc .end

	call ferror

.end
	pop dx
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
close_file:
	mov ah,3eh
	int 21h

	jnc .end

	call ferror

.end
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
read_file
	mov ah,3fh
	int 21h

	jnc .end

	call ferror

.end
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
write_file:
	mov ah,40h
	int 21h

	jnc .end

	call ferror

.end
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alloc_memory:
	mov ah,48h
	int 21h

	jnc .end

	call ferror

.end
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
dealloc_memory:
	mov ah,49h
	int 21h

	jnc .end

	call ferror

.end
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
resize_memory:
	mov ah,4ah
	int 21h

	jnc .end

	call ferror

.end
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ferror:
	push si

	cmp ax,1
	je short .error1
	cmp ax,2
	je short .error2
	cmp ax,3
	je short .error3
	cmp ax,4
	je short .error4
	cmp ax,5
	je short .error5
	cmp ax,6
	je short .error6
	cmp ax,7
	je short .error7
	cmp ax,8
	je short .error8

	jmp short .end
.error1
	mov si,file_error1
	call print
	jmp short .end
.error2
	mov si,file_error2
	call print
	jmp short .end
.error3
	mov si,file_error3
	call print
	jmp short .end
.error4
	mov si,file_error4
	call print
	jmp short .end
.error5
	mov si,file_error5
	call print
	jmp short .end
.error6
	mov si,file_error6
	call print
	jmp short .end
.error7
	mov si,file_error7
	call print
	jmp short .end
.error8
	mov si,file_error8
	call print
.end
	pop si
	mov ax,0xffff
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Print string function
;;	Input :
;;	PUSH SI=pointer to string
print:
	pusha
	mov ah,2
.loop
	mov dl,byte[ds:si]
	inc si
	and dl,dl
	jz .end
	int 21h
	jmp short .loop
.end
	popa
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Print character function
;;	Input:
;;	DL=character
printc:
	push ax
	
	mov ah,2
	int 21h
	
	pop ax
	ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Puts the parameters in the string is given to the function
get_cmdline:
	pusha

	push ds

	mov ah, 0x62
	int 0x21
	mov ds, bx

	xor cx,cx
	mov cl,[ds:80h]

	and cl,cl
	jz short no_parameter

	mov si,81h

	push di
	inc di
	inc di
	xor cx,cx
loop_parse:
	lodsb

	cmp al,' '
	je short loop_parse

	inc cx

	stosb
.loop
	lodsb

	cmp al,' '
	je short .end_loop2
	cmp al,0dh
	je .end

	stosb

	jmp short .loop
.end_loop2
	xor al,al
	stosb
	jmp short loop_parse

.end
	xor al,al
	stosb
	pop di
	pop ds
	mov ax,cx
	stosw

	popa
	ret
no_parameter:
	pop ds

	mov si,msg_info
	call print

	popa
	mov ax,0xffff
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

section data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Variablen
file_error1			db 'ERROR : File is already open',13,10,0
file_error2			db 'ERROR : File not found',13,10,0
file_error3			db 'ERROR : Path not found',13,10,0
file_error4			db 'ERROR : No free handle',13,10,0
file_error5			db 'ERROR : Accessed refused',13,10,0
file_error6			db 'ERROR : Invalid handle',13,10,0
file_error7			db 'ERROR : Memory control blocks destroyed',13,10,0
file_error8			db 'ERROR : Insufficient memory',13,10,0

⌨️ 快捷键说明

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