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

📄 archive.asm

📁 windows汇编语言程序设计 吴中平著 一书所附所有源代码。 该书重点讲解了Windows环境下汇编语言程序设计的基本原理及其实现过程
💻 ASM
📖 第 1 页 / 共 2 页
字号:
.386p;本程序必须申明,8088的条件转移偏移量在-128~+127之内,386基本无限制。
F1      EQU 3b00h;定义常量,下同
F2      EQU 3c00h
F3      EQU 3d00h
F4      EQU 3e00h
F5      EQU 3f00h
ALTX   EQU 2d00h
ESCKEY EQU 1bH
TRUE   EQU 0ffh
FALSE   EQU 0

Student struc
        RecNo            DW  0
        SurName         DB  6   dup (0)
        LENNAME      EQU $-SurName;SurName字段长度的修改不影响程序,下同。
        Sex                 DB  0
        Birthday            DB  10  dup (0)
        LENDAY         EQU  $-Birthday
        Native              DB  30  dup (0)
        LENNATIVE    EQU $-Native
        ID                   DB  8   dup (0)
        LENID             EQU $-ID
        Statement         DB  100 dup (0)
        LENSta            EQU $-Statement
        RECORDERLEN   EQU $-RecNo 
Student ends

SetCursor macro y,x;设置当前页的光标定位宏,当前为0页。
        mov ah,2
        mov bh,0
        mov dh,y
        mov dl,x
        int 10h
endm

ReadCursor macro; 读取当前页的光标位置宏,当前为0页。
        mov ah,3
        mov bh,0
        int 10h
endm

EchoString macro num,attr,page,varname,count;Echo at current cursor
;BIOS  INT 10H的13号功能调用显示字符串宏。
        ReadCursor;设置DX。
        lea bp,varname
        mov ax,seg varname
        mov es,ax;ES:BP为串首地址。
        mov al,num;,num为1时,光标移动。
        mov bl,attr;属性
        mov bh,page;页号
        mov cx,count;串长
        mov ah,13h
        mov al,num
        int 10h
endm


ScrollUp macro num,attr,top,left,bottom,right
;BIOS  INT 10H的6号功能调用清屏或上卷宏。
        mov ah,6
        mov al,num;0  清屏,1 上卷
        mov ch,top
        mov cl,left
        mov dh,bottom
        mov dl,right
        mov bh,attr
        int 10h
endm

FileOpen macro rw,file_name
;DOS  INT 21H的3dh号功能调用打开文件宏。
        mov ax,seg file_name;file_name为ASCIZ串。
        mov ds,ax
        lea dx,file_name
        mov al,rw;读写方式
        mov ah,3dh
        int 21h
endm

FileClose macro File
;DOS  INT 21H的3eh号功能调用关闭文件宏。
        mov bx,File
        mov ah,3eh
        int 21h
endm

FileRead macro count,var,File
;DOS  INT 21H的3fh号功能调用读文件宏。
        mov ax,seg var
        mov ds,ax
        lea dx,var;DS:DX为读出来的数据送往的首地址。
        mov cx,count
        mov bx,File
        mov ah,3fh
        int 21h
endm

FileWrite macro count,var,File
;DOS  INT 21H的40h号功能调用写文件宏。
        mov ax,seg var
        mov ds,ax
        lea dx,var;把DS:DX为首地址的数据写入文件中。
        mov cx,count
        mov bx,File
        mov ah,40h
        int 21h
endm

FPMove macro direct,dwea,File
;DOS  INT 21H的42h号功能调用移动文件指针宏。
        mov eax,dwea;偏移量。
        mov dx,ax
        sar eax,16
        mov cx,ax
        mov al,direct;偏移方式。
        mov bx,File
        mov ah,42h
        int 21h
endm

EnCRLF macro crlf;换行
        mov ax,seg crlf
        mov ds,ax
        lea dx,crlf
        mov ah,9
        int 21h
endm

ClearBuffer macro varname,count;清缓冲区内容
        mov ax,seg varname
        mov es,ax
        lea di,varname
        mov cx,count
        mov al,0
        rep stosb
endm


Seg_Data  segment  use16
      File                 DW    	?;文件代号
      Filetemp          DW    	?;临时文件代号
      CurRecNo       DW             ?;当前记录号
      EntryPort        DW 	    0;调用者的标识
      CurCursor       DW 	    ?;当前光标号
      FileName         DB 	   ".\archive.dat",0;ASCIZ
      NoExistFile      DB 	"File is not exist!",7,"System automatically Create a File for you ,Please Append(F2) recorder!$"
      NullFile           DB	"File is NULL!",7,"Please Append(F2) recorder!$"
      AppQuest        DB 	"Do you want to append another (Y/N?)"
      QUESTLEN     EQU 	$-AppQuest
      AnyKey           DB 	"Press any key to Continue,ESC to Exit"
      ANYKEYLEN  EQU 	$-AnyKey
      TailQuest          DB 	"Already reach file`s end,Press any key to exit!"
      FILETAILLEN  EQU 	$-TailQuest
      ModifyQuest     DB 	"Do you want to modify current recorder(Y),ESC to Exit,other to Continue!"
      MODIFYLEN    EQU 	$-ModifyQuest
      DeleteQuest       DB  "Do you want to delete current recorder(Y),ESC to Exit,other to Continue!"
      DELETELEN     EQU 	$-DeleteQuest
      FindIdea            DB 	"+++++++++++find by SurName+++++++++++++"
      IDEALEN          EQU 	$-FindIdea
      ModDelQuest     DB 	"Press M to Modify,D to Delete ,ESC to Exit,other to Continue!"
      MDLEN             EQU 	$-ModDelQuest
      FindTailQuest     DB "Already reach file`s end, Do you Find again(Y),ESC to Exit!"
      FINDTAILLEN  EQU 	$-FindTailQuest
      F2Select            DB 	"File is NULL!",7,"You must select F2!"
      F2LEN              EQU 	$-F2Select
      Head                 DB     "======================STUDENT`S ARCHIVE MANAGE SYSTEM "
                              DB "===================="
      HEADLEN         EQU 	$-Head
      VRecNo            DB 	"RecNo:"
      RECNOLEN      EQU 	$-VRecNo
      VSurName         DB 	"SurName:"
      NAMELEN        EQU 	$-VSurName
      BSurName         DB  	7,?,7 dup(?);控制输入的长度,为DOS 21H的9号功能调用,下同。
      VSex                 DB 	"Sex:"
      SEXLEN           EQU 	$-VSex
      BSex                 DB  	2,?,2 dup(?)
      VBirthday          DB 	"Birthday:"
      DAYLEN           EQU 	$-VBirthday
      BBirthday           DB  	11,?,11 dup(?)
      VNative             DB 	"Native:"
      NATIVELEN     EQU 	$-VNative
      BNative             DB  	31,?,31 dup(?)
      VID                  DB 	"ID:"
      IDLEN             EQU 	$-VID
      BID                  DB  	9,?,9 dup(?)
      VStatement        DB  	"Statement:"
      STATEMENTLEN   EQU 	$-VStatement
      BStatement         DB  	101,?,101 dup(?)
      F1Key                DB 	"  F1--Display"
      F1KEYLEN        EQU 	$-F1Key
      F2Key                DB 	"F2--Append"
      F2KEYLEN        EQU 	$-F2Key
      F3Key                DB 	"F3--Modify"
      F3KEYLEN        EQU 	$-F3Key
      F4Key               DB 	"F4--Delete"
      F4KEYLEN        EQU 	$-F4Key
      F5Key                DB 	"F5--Find"
      F5KEYLEN        EQU 	$-F5Key
      ALTXKey          DB 	"ALT X--Exit",0dh,0ah
      ALTXKEYLEN   EQU 	$-ALTXKEY
      Crlf                    DB            0dh,0ah,'$'
      Buffer             student   <>   ;自定义的变量,作为缓冲数据之用。
      BtoDbuffer         DB  	5 dup(?),'$';转换记录号为十进制数
      FindSurName      DB  	7,?,7 dup(?);查询方式
      FinStrLen           DW 	?;保存要查询的内容
      count                 DW 	0;作为显示次数之用
Seg_Data ENDS


Seg_Stack  segment  use16
      DW    512    dup  (?)
      Top   label  WORD
Seg_Stack  ends

Seg_Code segment use16
main proc far
      Assume  cs:Seg_Code , ds:Seg_Data , ss:Seg_Stack
 Start:
        mov    ax ,  Seg_Stack
        mov    ss ,  ax
        mov    sp ,  offset Top
        mov    ax ,  Seg_Data
        mov    ds ,  ax
        mov    es ,  ax
;=========================================
        FileOpen 2,FileName
        jc errorno;文件不存在。
        mov File,ax
        mov Filetemp,ax
        mov bx,ax
        FileRead RECORDERLEN,buffer,File
        cmp ax,0
        jz errornu;文件存在,但内容为空。
        FPMove 0,0,File;Move to head;文件指针回到头。
        jmp entry
errorno:
        lea dx,NoExistFile
        mov ah,9
        int 21h
        lea dx,FileName
        mov cx,0
        mov ah,3ch;建立新文件。
        int 21h
        mov File,ax
        mov Filetemp,0ffh
        jmp entry
errornu:
        mov Filetemp,0ffh;标识文件存在,但内容为空。
entry:
        mov ah,0
        mov al,3
        int 10h;80*25的文本方式
        mov ax,1001h
        mov bh,3
        int 10h;设置屏幕边框。

        EchoString 1,0fh,0,Head,HEADLEN
;下面的宏指令调用是文件信息的提示。
        SetCursor 2,0
        EchoString 1,0ah,0,F1Key,F1KEYLEN
        SetCursor 2,F1KEYLEN+3
        EchoString 1,0ah,0,F2Key,F2KEYLEN
        SetCursor 2,F1KEYLEN+F2KEYLEN+6
        EchoString 1,0ah,0,F3Key,F3KEYLEN
        SetCursor 2,F1KEYLEN+F2KEYLEN+F3KEYLEN+9
        EchoString 1,0ah,0,F4Key,F4KEYLEN
        SetCursor 2,F1KEYLEN+F2KEYLEN+F3KEYLEN+F4KEYLEN+12
        EchoString 1,0ah,0,F5Key,F5KEYLEN
        SetCursor 2,F1KEYLEN+F2KEYLEN+F3KEYLEN+F4KEYLEN+F4KEYLEN+15
        EchoString 1,0ah,0,ALTXKey,ALTXKEYLEN
select:;只能选择F1~F5、ALT X键,否则发出警声
        mov ah,0
        int 16h
        cmp ax,F1
        jz F1Display         
        cmp ax,F2
        jz F2Append
        cmp ax,F3
        jz F3Modify
        cmp ax,F4
        jz F4Delete
        cmp ax,F5
        jz F5Find
        cmp ax,ALTX
        jz exit
        mov dl,7
        mov ah,6
        int 21h
        jmp select
F1Display:
        cmp Filetemp ,0ffh;文件为空时,必须追加记录后才能执行,下同。
        jnz ExeCall1
        EchoString 1,8Ch,0,F2Select,F2LEN
        jmp select
ExeCall1:
        call DisplayAll;调用显示记录子程序。
        cmp eax,0;返回码,非常重要,复杂的程序往往需要返回码值,下同。
        jz select
F2Append:
        call Append;调用追加记录子程序。
        cmp eax,0
        jz select
F3Modify:
        cmp Filetemp ,0ffh
        jnz ExeCall3
        EchoString 1,8Ch,0,F2Select,F2LEN
        jmp select
ExeCall3:
        call Modify;调用修改记录子程序。
        cmp eax,0
        jz  select
F4Delete:
        cmp Filetemp ,0ffh
        jnz ExeCall4
        EchoString 1,8Ch,0,F2Select,F2LEN
        jmp select
ExeCall4:
        call Delete;调用删除记录子程序。
        cmp eax,0
        jz  select
F5Find:
        cmp Filetemp ,0ffh
        jnz ExeCall5
        EchoString 1,8Ch,0,F2Select,F2LEN
        jmp select
ExeCall5:
        call Find;调用查询记录子程序。
        cmp eax,0
        jz select
;=========================================
exit:
        mov bx,File
        mov ah,3eh
        int 21h;关闭打开的文件,以清文件缓冲区。
        ScrollUp 0,0Fh,0,0,24,79;清屏。
        SetCursor 0,0
        mov ax,4c00h
        int 21h
main Endp


DisplayAll proc near
        ScrollUp 0,0Fh,3,0,24,79
        SetCursor 3,0
echoagain:;显示、修改、删除、查询子程序时显示记录的入口。       
        FileRead RECORDERLEN,buffer,File;把文件的当前记录读到缓冲区。
        cmp ax,0;文件指针到达尾部?
        jz tail
        cmp buffer.RecNo,0
        jz echoagain;逻辑删除者不显示出来。
        inc count ;保证每屏只显示两条记录。
        lea bx,BtoDBuffer
        mov ax,buffer.RecNo
        mov CurRecNo,ax
        call BtoD;把WORD型的记录号转化为字符型。
        cld
        mov al,'0'
        lea di,BtoDBuffer
        repz scasb
        dec di
        push di
        EchoString  1,0dh,0,VRecNo,RECNOLEN
        pop di
        mov ah,9
        mov dx,di
        int 21h
        EnCRLF Crlf
        EchoString  1,0dh,0,VSurName,NAMELEN;提示显示,下同。
        EchoString  1,0fh,0,buffer.SurName,LENNAME:内容显示,下同。
        EnCRLF Crlf
        EchoString  1,0dh,0,VSex,SEXLEN
        cmp buffer.Sex,0
        jz logicfemales
        mov dl,'1'
        jmp Logicsex
logicfemales: ;在性别中原来输入为0,则显示为0,其它均为1的逻辑值
        mov dl,'0'
logicsex:
        mov ah,2    
        int 21h
        EnCRLF Crlf

⌨️ 快捷键说明

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