Dev of Assembly Source series

Source: Internet
Author: User
Tags exit header range requires

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.

Name Dev
Page 60,132
Title ' DEV---installed device drivers '
; DEV---A utility to the device header information for
; All installed device drivers
;
; Requires Pc-dos or MS-DOS 2.0.
;
; Used in the form:
; A>dev
;
; Version 1.0 December 12, 1984
; Copyright (c) 1984 by Ray Duncan
CR Equ 0DH; ASCII Carriage return
LF equ 0ah; ASCII line Feed
Blank Equ 20h; ASCII Space Code
EOM equ ' $ '; end of string marker
CSEG segment para public ' CODE '
Assume Cs:cseg,ds:data,es:data,ss:stack
dev proc Far entry point from Pc-dos
Push DS; save ds:0000 for final
XOR Ax,ax; return to Pc-dos
Push AX
mov ax,data; make our data segment
MOV ds,ax; addressable via DS and ES.
MOV Es,ax
MOV ah,30h check version of Pc-dos.
int 21h
CMP al,2
Jae Dev1;p roceed, DOS 2.0 or greater.
mov dx,offset msg2;D OS 1.x---print error message.
JMP DEV6
Dev1:mov Cx,ax Save DOS version number.
MOV ah,15 now try and open the "NUL" device.
MOV Dx,offset NULFCB
int 21h
or Al,al; opened successfully?
JZ dev2; Yes, jump.
mov dx,offset MSG1 No, print error MSG and exit.
JMP DEV6
Dev2:; Pick up double pointer to device
;d River chain out of reserved
; area in FCB. This is mapped
;d ifferently in DOS 2.x and DOS 3.x.
CMP cl,2 is this DOS 2.x?
JA dev3; no, jump.
mov Bx,word ptr nulfcb+25
mov Es,word ptr nulfcb+27
JMP dev4
Dev3:; Come here if DOS 3.0 or greater.
mov Bx,word ptr nulfcb+26
mov Es,word ptr nulfcb+28
Dev4:call Header;p rint sign-on message and
; column headings.
DEV5:; trace through the device chain
Call Prdev;p rint device header information
; For driver pointed to by ES:BX.
;p ick up addr of next header.
Les Bx,dword ptr es:[bx]
CMP Bx,-1 found last one yet?
Jne dev5 No, try next.
  
MOV dx,offset msg3 Yes, print "End of device chain".
Dev6:mov ah,9;p Rint the string whose address
int 21h; is in DX.
RET; then return to DOS.
Dev ENDP
Header proc near;p rint out headings for device
mov dx,offset HDR;d River information.
MOV ah,9
int 21h
Ret
Header ENDP
Prdev proc near;p rint out device info.
; ES:BX is pointer to device header,
; which must be preserved.
MOV ax,es convert segment of device header
MOV Di,offset INF1
Call HEXASC
MOV ax,bx convert offset of device header.
MOV Di,offset INF2
Call HEXASC
mov ax,es:[bx+4]; get attribute word, save a
Push ax copy of it, then convert it.
MOV Di,offset inf3
Call HEXASC
mov ax,es:[bx+6]; convert PTR to device strategy.
MOV Di,offset Inf4
Call HEXASC
mov ax,es:[bx+8]; convert PTR to device int handler.
MOV Di,offset Inf5
Call HEXASC
; if not char device, clear out name
; field and set number of units.
Pop ax, get-back attribute word.
Test ax,08000h is bit 15 = 1?
JNZ prdev7 Yes, it ' s character Dev, jump.
; No, it ' s block device.
; Set flag to skip device name.
mov byte ptr inf8,eom
mov al,es:[bx+10];p ick up number of units.
AAM; Convert to ASCII decimal and
Add ax, ' a '; store into output string.
mov byte ptr inf7+1,al
mov byte ptr inf7,ah
; set type = B for block
mov byte ptr inf6, ' B '
JMP prdev9
PRDEV7:; If char device, move its 8-character
; name into the output string.
XOR Si,si
Prdev8:mov AL,ES:[SI+BX+10]
mov [si+inf8],al
Inc si
CMP si,8
Jne PRDEV8
; Remove # of Units field.
mov word ptr inf7, '
; set type = C for Character.
mov byte ptr inf6, ' C '
Prdev9:mov dx,offset inf; now print device information
mov ah,9 and exit.
int 21h
Ret
Prdev ENDP
HEXASC proc near, convert binary Word to hex ASCII.
; Call with ax=binary value
; Di=addr to store string
; returns AX, CX, DI destroyed.
Push ax Save copy of original value.
MOV Al,ah
Call Btoa, convert upper byte.
add di,2; increment output address.
Pop ax
Call Btoa, convert lower byte.
RET; return to caller.
HEXASC ENDP
Btoa proc near, convert binary byte to hex ASCII.
; Call with al=binary value
; Di=addr to store string
; returns AX, CX destroyed.
mov ah,al, save lower nibble.
MOV cx,4 shift Right 4 positions
SHR AL,CL to get upper nibble.
Call ASCII, convert 4 bits to ASCII equivalent
mov [Di],al store into output string.
mov al,ah; get back lower nibble.
and AL,0FH
Call ASCII, convert 4 bits to ASCII
mov [di+1],al and store into output string.
RET; back to caller.
Btoa ENDP
ASCII proc near convert 4 lower bits of AL
Add al, ' 0 '; into the equivalent ASCII char.
CMP al, ' 9 '; in the range {0...9,a ... F
Jle Ascii2 and return char. In AL.
Add al, ' A '-' 9 '-1; Fudge factor "for range a-f.
Ascii2:ret return to caller.
ASCII ENDP
Cseg ends
Data segment para public ' data '
MSG1 DB CR,LF
DB ' Failed to open NUL device. '
DB Cr,lf,eom
MSG2 DB CR,LF
DB ' Requires DOS version 2 or greater. '
DB Cr,lf,eom
MSG3 DB CR,LF
DB ' End of device chain. '
DB Cr,lf,eom
HDR DB CR,LF
DB ' Addr Attr '
DB ' Str Int Type Units Name '
DB EOM
INF DB CR,LF
INF1 db ' XXXX: '; SEG Device header
Inf2 db ' XXXX '; Offs Device Header
Inf3 db ' XXXX '; attribute
Inf4 db ' XXXX '; strategy
Inf5 db ' XXXX '; interrupt handler
Inf6 db ' X '; type (block or char)
Inf7 db ' XX '; units (if block device)
Inf8 db '; name (if char device)
DB EOM
; FCB to open NUL device
NULFCB DB 0;d Rive
DB ' NUL '; name of NUL device
DB 8 dup (')
DB DUP (0)
Data ends
Stack segment para stack ' stack '
DB DUP (?)
Stack ends
End Dev

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.