HDR of Assembly Source series

Source: Internet
Author: User
Tags exit

This is the past DOS era of the compilation of source code, although has passed, but for the study of the assembly is still helpful, assembly language is just a basic programmer language, most people can grasp, not necessarily in-depth research.

PAGE 60, 132
TITLE HDR 22-feb-85 Device Driver Header |
;-----------------------------------------------------------------------|
; |
; Device Driver Library |
; Device Driver Header |
; |
;-----------------------------------------------------------------------|
; REVISION HISTORY |
; |
; Number Dd-mmm-yy who WHY |
;-------|---------------|-----------------------|-----------------------|
;  0.0 | 22-feb-85 | Frank Whaley | Initial Release |
;-----------------------------------------------------------------------|
PAGE
;-----------------------------------------------------------------------|
; Equates |
;-----------------------------------------------------------------------|
Stksiz EQU 2048; Local stack size
PAGE
;-----------------------------------------------------------------------|
; Group Selection |
;-----------------------------------------------------------------------|
Pgroup Group PROG, TAIL
Dgroup Group DATA, Dtail
PROG Segment Para Public ' PROG '
PROG EndS
Data Segment Para public ' data '; Define
DATA EndS
Assume Cs:prog, Ds:data, Es:data, Ss:data
PAGE
;-----------------------------------------------------------------------|
; Program Segment |
;-----------------------------------------------------------------------|
PROG Segment Para Public ' PROG '
Extrn init:near, Mediache:near, buildbpb:near
Extrn ioctlin:near, Input:near, ndinput:near
Extrn inputsta:near, Inputflu:near, output:near
Extrn outverif:near, Outstatu:near, outflush:near
Extrn ioctlout:near, Devopen:near, devclose:near
EXTRN Remmedia:near
ORG 0
HDR Proc Far
;-----------------------------------------------------------------------|
; Device Header |
;-----------------------------------------------------------------------|
DD-1; -> Next Device
; DW Theattribute; You must enter attribute field
DW 8000H; Character only device
DW strategy; -> Device Strategy
DW Interrupt; -> Device Interrupt
; DB thename; Must put something here
DB "MON"; Mono
;-----------------------------------------------------------------------|
; Code Segment Variables |
;-----------------------------------------------------------------------|
Rhptr DD (?) ; -> Request Header
Ssentry DW (?) ; Entry SS
Spentry DW (?) ; Entry SP
PAGE
;-----------------------------------------------------------------------|
; Device Strategy |
; |
; ENTRY:ES:BX-> Request Header |
; |
; Exit:request Header copied to REQHDR |
; All Registers Preserved |
; |
;-----------------------------------------------------------------------|
Strategy:
MOV Word Ptr cs:rhptr,bx; Save Request Header PTR
MOV Word Ptr cs:rhptr + 2,es
PUSHF; (+1) Save the World
PUSH ES; (+2)
PUSH DS; (+3)
PUSH SI; (+4)
PUSH DI; (+5)
PUSH CX; (+6)
PUSH BX; (+7)
MOV SI,BX
MOV Bx,es
MOV DS,BX; Ds:si-> Request Header
MOV Bx,offset Pgroup:tail
MOV cl,4
SHR BX,CL
MOV Cx,cs
ADD BX,CX
MOV ES,BX
MOV Di,offset Dgroup:reqhdr; Es:di-> REQHDR
CLD
XOR Ch,ch
MOV Cl,[si]
REP MOVSB; Copy Request Header
POP BX; (+6) Restore
POP CX; (+5)
POP DI; (+4)
POP SI; (+3)
POP DS; (+2)
POP ES; (+1)
Popf; (+0)
Ret
PAGE
;-----------------------------------------------------------------------|
; Device Interrupt |
; |
; entry:anything |
; |
; Exit:all Registers Preserved |
; |
;-----------------------------------------------------------------------|
Interrupt:
PUSH DS; (+1) Save the World
PUSH ES; (+2)
PUSH AX; (+3)
PUSH BX; (+4)
PUSH CX; (+5)
PUSH DX; (+6)
PUSH SI; (+7)
PUSH DI; (+8)
PUSH BP; (+9)
MOV Cs:ssentry,ss; Save Entry SS
MOV cs:spentry,sp; and SP
MOV Ax,offset Pgroup:tail; Set our DS, SS, BP, and SP
MOV cl,4
SHR AX,CL
MOV Cx,cs
ADD AX,CX
MOV Bx,offset Dgroup:mystack
MOV Ds,ax
MOV Es,ax
MOV Ss,ax
MOV SP,BX
MOV BP,BX
;
; Call our function
;
MOV AL,REQHDR + 2; AL = Command Code
SHL al,1
Cbw
MOV Si,offset Dgroup:functab
ADD Si,ax
Call Word Ptr [SI]
;
; Copy back Request Header
;
LES di,rhptr; Es:di-> Original Space
MOV Si,offset Dgroup:reqhdr; Ds:si-> Our (updated) copy
CLD
XOR Ch,ch
MOV Cl,[si]
REP MOVSB; Copy Request Header
MOV Ss,cs:ssentry; Restore Original Stuff
MOV Sp,cs:spentry
POP BP; (+8) Restore
POP DI; (+7)
POP SI; (+6)
POP DX; (+5)
POP CX; (+4)
POP BX; (+3)
POP AX; (+2)
POP ES; (+1)
POP DS; (+0)
Ret
HDR ENDP
PROG EndS
TAIL Segment Public ' PROG '; For finding end of code segment
TAIL EndS
PAGE
;-----------------------------------------------------------------------|
; Data Segment |
;-----------------------------------------------------------------------|
Data Segment Para Public ' data '
Public REQHDR
DB stksiz DUP (?) ; Our stack, overflows into code
Mystack Label Word
Functab Label Word
DW Offset Pgroup:init
DW Offset Pgroup:mediache
DW Offset PGROUP:BUILDBPB
DW Offset Pgroup:ioctlin
DW Offset Pgroup:input
DW Offset Pgroup:ndinput
DW Offset Pgroup:inputsta
DW Offset Pgroup:inputflu
DW Offset Pgroup:output
DW Offset Pgroup:outverif
DW Offset Pgroup:outstatu
DW Offset Pgroup:outflush
DW Offset Pgroup:ioctlout
DW Offset Pgroup:devopen
DW Offset Pgroup:devclose
DW Offset Pgroup:remmedia
REQHDR DB 256 DUP (?) ; Copy of Request Header
DATA EndS
Dtail Segment Public ' DATA '; For finding end of data segment
Dtail EndS
End HDR; of HDR. Asm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.