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

📄 dump.asm

📁 一个操作系统启动代码
💻 ASM
字号:
;*******************************************************************
; Dump
;  (c) Andre v.d. Merwe 4-Feb-1999
;  <dart@pobox.com> <dart@iafrica.com>
;  See "zen.txt" for copyright information
;
; Zen Source Library. Assembler example 3
; http://users.iafrica.com/d/da/dart/zen/zen.html
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Compiler TASM
;
; Dump can be compiled as a normal dos com file. Which means that
;  when loaded by boot.asm it must be loaded to an offset of 100h
;  The advantage of this method is that it can be debugged with any
;  dos debugger (Turbo Debug etc).
;*******************************************************************

   TITLE Dump
	JUMPS
	.model Tiny


	DumpCols	equ	8h
	DumpRows	equ	70h


;---------------------------------------------------------------------------------
.code
.286
org 100h ;Normal com file offset
;---------------------------------------------------------------------------------

start:  
	 ;Set up the stack.
	 ; Starts at end of sector, "grows down" towards the code
	cli
	mov	ax,	cs
	mov	ss,	ax
	mov	sp,	0fffeh
	sti

	
 	 ;Segment registers initialisation - CS = DS = 0
	push	cs 
	pop	ds
	push	cs 
	pop	es
	

	call	func_ClearScreen


	mov	bp,	offset VersionInfo
	call	func_BiosShowMessage

	mov	ah,	0
	int	16h
	mov	ah,	2
	xor	dx,	dx
	int	10h

	call	func_ClearScreen

	
	 ;Default to dumping cs:ip
	push	cs
	pop	es

	push	cs
        pop     ds


	 ;Get IP 
	call	GetIP
GetIP:
	pop	si

Get_Start_Addr:
	int	3
	 ;Get application start offset
	sub	si,	(offset Get_Start_Addr) - (offset start) - 1



top:
	call	func_ClearScreen
	call	func_DumpMem

	 ;Line between dump and menu
	mov	al,	10
	call	func_BiosShowChar
	mov	al,	13
	call	func_BiosShowChar

	 ;Show the menu
	call	ShowMenu


GetKey:
	 ; int 16h - 0  Get char (wait)
	mov	ah,	0
	int	16h


	cmp	al,	'q'		;quit
	je	Exit_App


	cmp	al,	'n'		;next
	je	Next_Row

	cmp	al,	'p'		;prev
	je	Prev_Row

	cmp	al,	's'		;segment
	je	Get_Segment

	cmp	al,	'o'		;offset
	je	Get_Offset

	cmp	al,	'c'		;goto CS:xxxx
	je	Goto_CS


	jmp	GetKey			;Invalid key



Next_Row:				;Dump next row (si + DumpRows)
	add	si,	DumpRows + ( DumpCols * (DumpRows / DumpCols) )
	jmp	top


Prev_Row:				;Dump prev row (si - DumpRows)
	sub	si,	DumpRows + ( DumpCols * (DumpRows / DumpCols) )
	jmp	top


Get_Segment:
	mov	bp,	offset SegmentPrompt
	call	func_GetSegOffset
	mov	es,	dx
	jmp	top

Get_Offset:
	mov	bp,	offset OffsetPrompt
	call	func_GetSegOffset
	mov	si,	dx
	jmp	top


Goto_CS:
	push	cs
	pop	es
	jmp	top


Exit_App:
	db	0EAh,  00h,  00h,  0FFh,  0FFh	; BIOS reset, this is a jump to 0000h:FFFFh
;	int	20h




;********************************************************************
; func_GetSegOffset
;  bp = prompt
;
;  Returns word in dx
;  
;********************************************************************
func_GetSegOffset:
	push	ax
	push	cx
	push	es
	
	xor	dx,	dx


	 ;Set cursor pos
	mov	ah,	02
	mov	dh,	24
	mov	dl,	0
	int	10h

	mov	cx,	60
GetSegOffset_ClearLine:
	mov	al,	' '
	call	func_BiosShowChar
	loop	GetSegOffset_ClearLine

	 ;Set cursor pos
	mov	ah,	02
	mov	dh,	24
	mov	dl,	9
	int	10h

	push	ds
	pop	es
	;bp has prompt
	call	func_BiosShowMessage

	call	func_GetWord_DX
	call	func_ClearScreen

	mov	al,	10
	call	func_BiosShowChar
	mov	al,	13
	call	func_BiosShowChar

	pop	es
	pop	cx
	pop	ax
	ret
;********************************************************************



;********************************************************************
; func_DumpMem
;  es:si = location to dump
;  
;********************************************************************
func_DumpMem:

	pusha

	mov	cx,	DumpRows	;Num of rows to dump
	

	call	func_DumpMem_PrintLocation


	 ;BX contains column count
	xor	bx,	bx

	
Dump_Row:
	 ;Get value at SI
	mov	dx,	es:[si]	
	xchg	dh,	dl


	 ;Point si to next location
	add	si,	2


;-----------------
	mov	di,	offset Char_Data
	add	di,	bx
	add	di,	bx
	xchg	dl,	dh
	mov	ds:[di],	dx
	xchg	dl,	dh
;-----------------

	 ;Print the value
	call	func_PrintDX


	 ;Print a space char
	mov	al,	' '
	Call	func_BiosShowChar


	 ;Start new column?
	inc	bx
	cmp	bx,	DumpCols
        jb      No_New_Line


	 ;Start new column

;-----------------------
	nop
	nop
	nop
	nop
	nop

	push	cx
	mov	cx,	16
	mov	di,	offset Char_Data

	mov	al,	' '
	call	func_BiosShowChar
	call	func_BiosShowChar
	call	func_BiosShowChar

	
Test_Loop:	
	cmp	cx,	0
	je	Out_Test
	
	mov	al,	[di]
	inc	di
	dec	cx

	cmp	al,	0fdh
        ja      CantPrint

	cmp	al,	20h
        jb      CantPrint

        jmp     CanPrint

CantPrint:
        mov     al,     ' '
CanPrint:
	mov	ah,	0eh
	int	10h	
	
	cmp	cx,	0
        ja      Test_Loop

Out_Test:
	pop	cx
;-----------------------
	mov	al,	13
	call	func_BiosShowChar
	mov	al,	10
	call	func_BiosShowChar

	 ;Reset col count
	xor	bx,	bx


	 ;Dont print new line if there is no more data to dump
	cmp	cx,	1
	je	No_New_Line

	
	call	func_DumpMem_PrintLocation


No_New_Line:
	loop	Dump_Row

	popa
	ret



	;--------------------------------------------------
	; Nested procedure.  
        ;  Prints current dump location  (es:si)
	;--------------------------------------------------
	func_DumpMem_PrintLocation:


		 ;Print the dump source (offset)
		mov	dx,	es
		call	func_PrintDX

		mov	al,	':'
		Call	func_BiosShowChar

		 ;Print the dump source (offset)
		mov	dx,	si
		call	func_PrintDX


		 ;Print seperator ' - '
		mov	al,	' '
		Call	func_BiosShowChar
		mov	al,	'-'
		Call	func_BiosShowChar
		mov	al,	' '
		Call	func_BiosShowChar

		ret
	;----------------------------------------------
;********************************************************************



;********************************************************************
; ShowMenu:
;  Display the menu
;  
;********************************************************************
ShowMenu:
	push	ax
	push	bx
	push	dx
	push	es


	 ;int 10h - 0fh  Get active video page (bh)
	mov	ah,	0fh
	int	10h

	 ;int 10h - 3  Get cursor pos + size
	mov	ah,	3
	int	10h

	push	dx


	 ;Set cursor pos
	mov	ah,	02
	mov	dh,	24
	mov	dl,	0
	int	10h


	 ;Display string
	push	ds
	pop	es
	mov	bp,	offset Menu
	mov	dh,	24
	mov	dl,	0
	call	func_BiosShowMessage


	 ;Restore cursor pos
	mov	ah,	2
	pop	dx
	int	10h
	

	pop	es
	pop	dx
	pop	bx
	pop	ax

	ret
;********************************************************************


include utils.inc


;---------------------------------------------------------------------------------
.data
;---------------------------------------------------------------------------------

Menu:
	db	'"n-next"  "p-previous"  "q-quit"  "s-segment"  "o-offset"', 13, 10
	db	'"c - goto CS"', 0


SegmentPrompt:
	db	'segment: ', 0


OffsetPrompt:
	db	'offset: ', 0


Char_Data:
	dw 	8 dup(0)


VersionInfo:
	db	'dump version 0.001', 0
VersionInfoEnd: 


end start

⌨️ 快捷键说明

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