分享
 
 
 

MASM-文件记录操作

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

文件记录操作

该程序实现及其说明:

1)从磁盘文件中读入记录数据.(这里磁盘文件中的数据为字符串格式,而且字符型串与数值型的串混杂在一起,要从中分离数值型字符串并将其转化为数值以便进行数值运算等.我这里作了简化这程序核心目的不在这.)

记录文件格式:(串与串第一个字符之间间隔8个字符,可以按这格式添加若干行,但列数和列名如下得一致.呵呵,这麻烦点,程序了简单多了啊,不信编编试试看)

name math englsh yuwen

zhou 89 79 68

lanx 96 78 88

maro 78 88 97

ping 79 97 84

ming 75 78 97

2)分离后的数字串数据分组保存并转化成相应的数值,编写排序,串拷贝等等函数对起操作并显示.(这里显示代码借了我上个程序<打字练习程序>,详见我BLOG).与

3)程序启动时候,先进入密码验证阶段,密码有系统时间生成,这里需要留意的是去系统时间后将系统时间转化输出成指定格式的6位十进制串.按找密码提示输入密码进入下一环节,这里设计到密码串比较的问题,参见相关代码块.

密码验证采用了错误循环输入处理,但只能输入三次.

4)进入装载文件块.这模块功能和代码及操作与程序<打字练习程序>基本一致.这里添加了

5)屏幕输出结果模块.这模块主要在paixu_out模块中实现.如果注意到宏CLEARSCREAM具有定制界面功能,还可以利用他定制自己的界面,不过这当然要自己在适当的地方添加CLEARSCREAM宏代码.

6)关于函数的功能说明参见函数名和其实现代码.与以前程序一样,函数名或宏就表明了其主要实现的功能.程序中有些函数代码可以优化,找找看.

7)希望这个程序对你有所帮助.程序在MASM5中调试通过.拷贝下列原码自己运行下先啊.如果不能运行,和我联系:发消息或EMAIL:hbyufan@163.com

;程序:mima.asm

;作者:周志明

;------------------------------------------

CLEARSCREAM MACRO alz,bhz,chz,clz,dhz,dlz

push ax

push bx

push cx

push dx

mov al,alz

mov bh,bhz

mov ch,chz

mov cl,clz

mov dh,dhz

mov dl,dlz

mov ah,6h

int 10h

pop dx

pop cx

pop bx

pop ax

ENDM

STIMEMC MACRO

push cx

push dx

mov ah,2ch

int 21h

mov stime[0],ch

mov stime[1],cl

mov stime[2],dh

pop dx

pop cx

ENDM

READGB MACRO bhz

push ax

push bx

push cx

push dx

mov bh,bhz

mov ah,3

int 10h

mov gbattr[0],dh

mov gbattr[1],dl

pop dx

pop cx

pop bx

pop ax

ENDM

SETGB MACRO bhz,dhz,dlz

push ax

push bx

push cx

push ax

push si

mov bh,bhz

mov dh,dhz

mov dl,dlz

mov ah,2

int 10h

pop si

pop dx

pop cx

pop bx

pop ax

ENDM

TISHI MACRO row,col,addr

push ax

push bx

push cx

push dx

SETGB 0,row,col

mov ah,09h

lea dx,addr

int 21h

pop dx

pop cx

pop bx

pop ax

ENDM

;=======================================================

data segment

addr db 300 dup('$')

path db 50 dup(0)

ts00 db 'Load File$'

ts01 db 'Load:$'

ts02 db 'OK?$'

ts03 db 'Path Error! Press any key to reinput!$'

stime db 3 dup(0)

temp db 10 dup(0)

inpw db 10 dup('$')

pw db 10 dup('$')

strflag db 0

gbattr db 4 dup(0)

ts0 db 'sn:$'

ts1 db 'password:$'

ts2 db 'Success!Press any key to continue!$'

ts3 db 'Error!Press any key to continue!$'

ts4 db 'Sorry,Three times over!Press any key to ESC!$'

tspx1 db 'Stu-Records:$'

tspx2 db 'PaiXuHou Stu-Records:$'

rcdstart dw 0

rcdnum dw 5 ;/////////

rcdlessons dw 3 ;////////

cname db 240 dup('$')

math db 30 dup(0)

english db 30 dup(0)

yuwen db 30 dup(0)

sum dw 30 dup(0)

sumflag db 0

aveflag db 0

row db 0

colum db 0

gbtemp db 10 dup(0)

dspts0 db 'sum$'

dspts1 db 'ave$'

data ends

;=========================================================

code segment

assume ds:data,cs:code

start:

mov ax,data

mov ds,ax

mov ah,0h

mov al,03h ;80*25/16

int 10h

;-------------------------------

CLEARSCREAM 0,07,0,0,25,79

CLEARSCREAM 0,37h,8,16,17,63

CLEARSCREAM 0,57h,10,20,15,59

TISHI 9,20,ts0

STIMEMC

call OutTime

TISHI 15,22,inpw ;///test

TISHI 13,20,ts1

call InPassWord

;-----------------------------

CLEARSCREAM 0,07H,0,0,24,79

CLEARSCREAM 0,5eh,9,14,14,65

TISHI 10,35,ts00

TISHI 12,25,ts01

call LoadFile

TISHI 13,45,ts02

mov ah,01h

int 21h

mov ah,01h ;//

int 21h ;//

;------------------------------

CLEARSCREAM 0,07,0,0,25,79

CLEARSCREAM 0,1eh,1,0,23,79

; CLEARSCREAM 0,60h,4,19,20,69

call paixu_out

;------------------------------

mov ah,01h

int 21h

exit:

mov ah,4ch

int 21h

;================================================-----

btod_out proc near ;num store in bx

push ax

push cx

push dx

mov cl,10

mov ax,bx

div cl

add ah,'0'

add al,'0'

mov temp[2],ah

mov temp[1],al

rnext0: mov dl,temp[1]

mov ah,02h

int 21h

mov dl,temp[2]

mov ah,02h

int 21h

pop dx

pop cx

pop ax

ret

btod_out endp

;--------------------------------------------------

OutTime proc near

;stime[0],stime[1],stime[2]

mov al,stime[0]

cbw

mov bx,ax

CALL btod_out

mov al,temp[1]

mov ah,temp[2]

mov inpw[0],al

mov inpw[1],ah

mov ah,2h

mov dl,':'

int 21h

mov al,stime[1]

cbw

mov bx,ax

CALL btod_out

mov al,temp[1]

mov ah,temp[2]

mov inpw[2],al

mov inpw[3],ah

mov ah,2h

mov dl,':'

int 21h

mov al,stime[2]

cbw

mov bx,ax

CALL btod_out

mov al,temp[1]

mov ah,temp[2]

mov inpw[4],al

mov inpw[5],ah

ret

OutTime endp

;--------------------------------------------------

InPassWord proc near

mov si,0

mov di,3

IPLFROTA:

READGB 0

mov ah,01h

int 21h

cmp al,0dh

jnz id0dnt

SETGB 0,gbattr[0],gbattr[1]

jmp IPLFROTA

id0dnt: cmp al,08h

jz IPLFBK

mov pw[si],al

inc si

mov ah,02h

mov dl,08h

int 21h

mov dl,'*'

int 21h

cmp si,06

jz IPLoadNext

jmp IPLFROTA

jmp IPLoadNext

IPLFBK: cmp si,0

jnz iplfnz

READGB 0

inc gbattr[1]

SETGB 0,gbattr[0],gbattr[1]

jmp IPLFROTA

iplfnz: mov pw[si],0

dec si

mov ah,02h

mov dl,' '

int 21h

mov ah,02h

mov dl,08h

int 21h

jmp IPLFROTA

IPLoadNext:

mov cx,03h

iptimes:

mov cx,6

mov bx,offset inpw

mov bp,offset pw

call strcpare

;--------------------

mov al,strflag

cmp al,0

jz ipexit

TISHI 15,20,ts3

mov ah,01h

int 21h

CLEARSCREAM 0,57h,10,20,15,59

TISHI 13,20,ts1

mov si,0

dec di

cmp di,0

jnz ipdint

mov ah,4ch

int 21h

ipdint:jmp IPLFROTA

ipexit: TISHI 15,20,ts2

mov ah,01h

int 21h

ret

InPassWord endp

;--------------------------------------------------

strcpare proc near

;cx store character numbers

;bx,bp

;return strflag

mov strflag,0

strrota:

mov ax,[bx]

cmp ax,[bp]

ja strAbove

jb strBlow

inc bx

inc bp

loop strrota

mov strflag,0

jmp strexit

strAbove:

mov strflag,2

jmp strexit

strBlow:

mov strflag,1

jmp strexit

strexit:

ret

strcpare endp

;--------------------------------------------------

LoadFile proc near

push ax

push bx

push cx

push dx

push si

mov si,0

LFROTA: mov ah,01h

int 21h

cmp al,0dh

jz LoadNext

cmp al,08h

jz LFBK

mov path[si],al

inc si

jmp LFROTA

jmp LoadNext

LFBK: cmp si,0

jnz lfnz

READGB 0

inc gbattr[1]

SETGB 0,gbattr[0],gbattr[1]

jmp LFROTA

lfnz: mov path[si],0

dec si

mov ah,02h

mov dl,' '

int 21h

mov ah,02h

mov dl,08h

int 21h

jmp LFROTA

LoadNext:

mov ah,3dh

mov dx,seg path

mov ds,dx

mov dx,offset path

mov al,00

int 21h

jc LoadERROR

;bx use to save file code

mov bx,ax

mov si,0

mov dx,seg addr

mov ds,dx

mov dx,offset addr

mov cx,1

mov di,0

LROT: mov ah,3fh

int 21h

cmp ax,0

jnz lfnt0

jmp lfret

lfnt0:

inc dx

inc si

jmp LROT

jmp lfret

LoadERROR:

TISHI 14,20,ts03

mov ah,01h

int 21h

CLEARSCREAM 0,5eh,9,14,14,65

TISHI 10,35,ts00

TISHI 12,25,ts01

mov si,0

jmp LFROTA

lfret: pop si

pop dx

pop cx

pop bx

pop ax

ret

LoadFile endp

;--------------------------------------------------

Separate proc near

push si

;//--------------------

;//Get first record's position//Store in rcdstart

mov si,0

FRSrota:

mov dl,addr[si]

inc si

cmp dl,0dh

jnz FRSrota

lea bx,addr[si]

mov rcdstart,bx

;//-------------------

;---------------------//Separate name and every scord

;//name ->cname[] (char)

;scord ->math[],english[],yuwen[] (int)

mov cx,rcdnum

lea bx,addr[si]

call chartoint

lea bx,addr[si]

call LoadName

;---------------------

pop si

ret

Separate endp

;--------------------------------------------------

paixu_out proc near

mov si,0

pxrota: mov dl,addr[si]

inc si

cmp dl,0dh

jnz pxrota

;=================================

CLEARSCREAM 0,60h,5,19,10,65

TISHI 4,15,tspx1

mov aveflag,1

mov row,5 ;//test

mov colum,20 ;//

call disPlay ;//

call Separate

lea bx,addr[si]

call paixu ;//pai xu

CLEARSCREAM 0,60h,15,19,20,65

TISHI 14,15,tspx2 ;//test paixu

mov aveflag,1

mov row,15

mov colum,20

call disPlay

ret

paixu_out endp

;-------------------------------------------------

paixu proc near

push si

push di

mov ax,rcdnum

push ax

;//bx:first record address

mov si,0

mov ax,rcdnum

add rcdnum,ax

pxrot0: mov bp,bx

cmp si,rcdnum

jnb pxrtnt0

mov ax,sum[si]

mov di,si

add di,2

pxrot1: cmp di,rcdnum

jnb pxrtnt1

;--------------

add bp,34

cmp ax,sum[di]

jnb pxrtnt2

mov cx,32

call strexchg

mov ax,sum[di]

mov dx,sum[si]

mov sum[si],ax

mov sum[di],dx

;--------------

pxrtnt2:add di,2

jmp pxrot1

pxrtnt1:

add bx,34

add si,2

jmp pxrot0

pxrtnt0:

pop ax

mov rcdnum,ax

pop di

pop si

ret

paixu endp

;--------------------------------------------------

strexchg proc near

;bx,bp

;cx

push ax

push bx

push cx

push bp

push si

mov si,0

mrot: mov al,[bx][si]

mov ah,[bp][si]

mov [bx][si],ah

mov [bp][si],al

inc si

loop mrot

pop si

pop bp

pop cx

pop bx

pop ax

ret

strexchg endp

;--------------------------------------------------

chartoint proc near

;cx=records'number

;bx=first record address

push dx

push si

mov bp,bx

mov dl,10

mov si,0

ctoirota:

;////////////////math

add bp,7

firstch:inc bp

mov dh,[bp]

cmp dh,'0'

jb firstch

cmp dh,'9'

ja firstch

sub dh,'0'

mov al,dh

fchnt: inc bp

mov dh,[bp]

cmp dh,' '

jz mathnext

mul dl

sub dh,'0'

add al,dh

jmp fchnt

mathnext:

mov math[si],al

;////////////////english

mov bp,bx

add bp,15

firstch1:

inc bp

mov dh,[bp]

cmp dh,'0'

jb firstch1

cmp dh,'9'

ja firstch1

sub dh,'0'

mov al,dh

fchnt1: inc bp

mov dh,[bp]

cmp dh,' '

jz englishnext

mul dl

sub dh,'0'

add al,dh

jmp fchnt1

englishnext:

mov english[si],al

;//////////////////yuwen

mov bp,bx

add bp,23

firstch2:

inc bp

mov dh,[bp]

cmp dh,'0'

jb firstch2

cmp dh,'9'

ja firstch2

sub dh,'0'

mov al,dh

fchnt2: inc bp

mov dh,[bp]

cmp dh,' '

jz yuwennext

mul dl

sub dh,'0'

add al,dh

jmp fchnt2

yuwennext:

mov yuwen[si],al

inc si

add bx,34

mov bp,bx

mov ax,0

;;--------///loop ctoirota

dec cx

cmp cx,0

jz ctexit

jmp ctoirota

;;---------

ctexit:

;-----------------////request sum[]

mov si,0

mov di,0

mov cx,rcdnum

ctsum: mov dx,0

mov ax,0

mov al,math[si]

cbw

mov dx,ax

mov al,english[si]

cbw

add dx,ax

mov al,yuwen[si]

cbw

add dx,ax

mov sum[di],dx

add di,2

inc si

loop ctsum

pop si

pop dx

ret

chartoint endp

;--------------------------------------------------

LoadName proc near

;bx=first record's address

push ax

push bx

push cx

push dx

push si

push di

push bp

mov bp,0

mov si,0

lnrota0:mov di,0

mov cx,8

lnrota1:

mov al,[bx][di]

mov cname[bp+di],al

inc di

loop lnrota1

add bp,9

add bx,34

inc si

cmp si,rcdnum

jb lnrota0

pop bp

pop di

pop si

pop dx

pop cx

pop bx

pop ax

ret

LoadName endp

;--------------------------------------------------

btod_out4 proc near ;num store in bx

push ax

push cx

push dx

push bp

push si

mov ax,bx

mov si,4

rota1: mov bl,10

div bl

mov temp[si],ah

and ax,00ffh

dec si

cmp si,0

jnz rota1

mov bp,1

mov si,1

rota2: mov dl,temp[si]

add dl,'0'

cmp dl,'0'

jz btodeal

mov bp,0

btrt1: mov ah,02h

int 21h

btrt2: inc si

cmp si,4

jna rota2

cmp bp,1

jnz RT

mov ah,2h

int 21h

jmp RT

btodeal: cmp bp,1

jz btrt2

jmp btrt1

RT: pop si

pop bp

pop dx

pop cx

pop ax

ret

btod_out4 endp

;--------------------------------------------------

ave_out proc near

;bp=scords

push ax

push bx

push cx

push dx

push si

push di

push bp

mov ax,bp

mov dx,0

div rcdlessons

mov bx,ax

CALL btod_out4

push dx

mov ah,02h

mov dl,'.'

int 21h

pop dx

mov cx,100

mov ax,dx

mul cx

div rcdlessons

mov bx,ax

CALL btod_out4

pop bp

pop di

pop si

pop dx

pop cx

pop bx

pop ax

ret

ave_out endp

;--------------------------------------------------

disPlay proc near

;row,colum

push ax

push bx

push cx

push dx

push si

push di

push bp

mov si,0

dpclr:mov dl,'$'

mov cname[si],dl

inc si

cmp si,150

jnz dpclr

mov si,0

dpFRProta:

mov dl,addr[si]

inc si

cmp dl,0dh

jnz dpFRProta

;-------------------

SETGB 0,row,colum

mov di,0

dptsrota:

mov ah,2h

mov dl,addr[di]

int 21h

inc di

cmp di,si

jb dptsrota

; inc row

;-------------------

lea bx,addr[si]

mov cx,rcdnum

call chartoint

lea bx,addr[si]

call LoadName

mov dl,row

mov gbtemp[0],dl

mov dl,colum

mov gbtemp[1],dl

mov gbtemp[2],dl

mov gbtemp[3],dl

mov gbtemp[4],dl

mov gbtemp[5],dl

add gbtemp[1],8

add gbtemp[2],16

add gbtemp[3],24

add gbtemp[4],32

add gbtemp[5],40

mov si,0

mov di,0

mov bp,0

; SETGB 0,row,colum

dplayrota:

TISHI gbtemp[0],colum,cname[bp]

inc gbtemp[0]

SETGB 0,gbtemp[0],gbtemp[1]

mov al,math[si]

cbw

mov bx,ax

call btod_out

SETGB 0,gbtemp[0],gbtemp[2]

mov al,english[si]

cbw

mov bx,ax

call btod_out

SETGB 0,gbtemp[0],gbtemp[3]

mov al,yuwen[si]

cbw

mov bx,ax

call btod_out

;-------------------------------

mov al,0

cmp aveflag,al

jnz dspsv

jmp aveflgnext

dspsv:

SETGB 0,gbtemp[0],gbtemp[4]

mov bx,sum[di]

call btod_out4

mov ah,2h

mov dl,' '

int 21h

SETGB 0,gbtemp[0],gbtemp[5]

push bp

mov bp,sum[di]

call ave_out

pop bp

aveflgnext:

;-----------------------------

add di,2

add bp,9

inc si

cmp si,rcdnum

jz dplayet

jmp dplayrota

dplayet:

mov aveflag,0

pop bp

pop di

pop si

pop dx

pop cx

pop bx

pop ax

ret

disPlay endp

;--------------------------------------------------

code ends

end start

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有