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

📄 rdconfig.asm

📁 一个朋友写的操作系统源码
💻 ASM
字号:

sseg segment stack

     db 128 dup (0)

sseg ends

dseg segment para public 'global'

     extrn parambuf:byte
     extrn paramnr:word
     configpath db 'config.txt',0  ; file name to be open

dseg ends

cseg segment para public 'code'

     assume cs:cseg,ds:dseg,ss:sseg

     public rdconfig,chksynx

     extrn panic:near

     rdconfig proc near

     push ds  ; save caller's segment
     push es
     push bp  ; make stack frame
     mov bp,sp

     mov ax,3d00h  ; read only open file         
     mov dx,offset configpath
     int 21h
     jnc suc
     ; don't clear carry if error detected
     mov sp,bp
     pop bp  ; restore stack frame
     pop es
     pop ds
     ret     ; leave error code in ax

suc:
     mov bx,ax    ;we will read the config file
     xor ax,ax
     mov ah,3fh
     mov dx,offset parambuf
     mov cx,1024
     int 21h
     jnc suc1
     mov sp,bp
     pop bp
     pop es
     pop ds
     ret
suc1:
     mov [paramnr],ax   ; indicate how many byte we read from config file
     clc                ; guaratee no error

     ; the file handler is already set properly

     mov ah,3eh
     int 21h            ; close config file

     ; we don't care if this operating is successful

     mov sp,bp
     pop bp
     pop es
     pop ds
     ret

     rdconfig endp


     chksynx proc near

     push ds
     push es
     push bp
     mov bp,sp

     sub sp,4

     ; stack arranges like this

     ; [bp-2] : first '/' char position
     ; [bp-4] : first '$' char position

     ; try to find the '#', if '#' not present in our parameter
     ; buf, we will refuse to continue operating and panic

     cmp word ptr [paramnr],0    ; configuration file can't be NULL
     jne cnext1
     mov ax,105
     push ax
     call panic
cnext1:
     cld                 ; clear direction
     mov di,offset parambuf
     mov cx,[paramnr]
     mov al,35           ; '#'
     repnz scasb         ; find first '#' char
     jz found1
     mov ax,100          ; get appropriate error code
     push ax
     call panic
found1:

     ; '/' should be first encounted

     cld                 ; clear direction
     mov di,offset parambuf
     mov cx,[paramnr]
     mov al,47           ; '/'
     repnz scasb         ; find first '/' char
     jz found2
     mov ax,106
     push ax
     call panic
found2:
     mov [bp-2],di       ; save position of '/'
     cld                 ; clear direction
     mov di,offset parambuf
     mov cx,[paramnr]
     mov al,36           ; '$'
     repnz scasb         ; find first '$' char
     jz found3
     mov ax,106
     push ax
     call panic
found3:
     mov [bp-4],di
     cmp [bp-2],di       ; who is big?
     jb right
     mov ax,106
     push ax
     call panic
right:
     mov sp,bp
     pop bp
     pop es
     pop ds
     ret

     chksynx endp

cseg ends

end

⌨️ 快捷键说明

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