比赛计算器.docx
《比赛计算器.docx》由会员分享,可在线阅读,更多相关《比赛计算器.docx(16页珍藏版)》请在冰豆网上搜索。
比赛计算器
;--------------------------------------------------------------------
;Filename:
calc.asm
;Version:
V1.0
;Writer:
LiuCong,CuiYang
;Organization:
TianjinUniversity
;Object:
Thisisademofortheheaderofassemblylanguagesourcefile.
;CompilationOptions:
None
;History:
09/20/2011Initversion
;--------------------------------------------------------------------
imr0equ0f7h
imr1equ00h
cnt0equ280h
cnt1equ281h
cntcmdequ283h
p85aequ290h
p85bequ291h
p85cequ292h
p85cmdequ293h
stackedsegmentstack
stadw100dup(?
)
topequlengthsta
stackedends
datasegment
mes1db'pleaseinputthequestion.',0ah,0dh,'$'
mes2db'cannotholdthenumber!
',0ah,0dh,'$'
mes3db'incorrectinput!
',0ah,0dh,'$'
mes4db'two-operandsupportonly!
',0ah,0dh,'$'
mes5db'overflow!
',0ah,0dh,'$'
tabdb3fh,06h,5bh,4fh,66h,6dh,7dh,07h
db7fh,67h,77h,7ch,39h,2eh,79h,71h,73h
tab1db88h,48h,28h,18h,84h,44h,24h,14h
db82h,42h,22h,12h,81h,41h,21h,11h
int_segdw?
int_offdw?
fmimrdb0
fmimr1db0
mdispdb4dup(?
)
operand1dw0000h
operand2dw0000h
operatordb00h
resultdw0000h
numsysdw10h
tfordb60d
tempdw?
tmpdw?
time0dw?
time1dw?
flag0db00h
flag1db00h
flag2db01h
flag3db00h
flag4db00h
timedw0000h
dataends
codesegment
assumecs:
code,ds:
data,ss:
stacked
start:
movax,data
movds,ax
movax,stacked
movss,ax
movsp,top
movdx,cntcmd;initialize8253,setinterruptfrequencyto1sonce
moval,37h
outdx,al
movdx,cnt0
moval,00h
outdx,al
moval,10h
outdx,al
movdx,cntcmd
moval,77h
outdx,al
movdx,cnt1
moval,00h
outdx,al
moval,10h
outdx,al
movdx,p85cmd
moval,88h
outdx,al
movax,350bh
int21h
movax,es
movint_seg,ax
movint_off,bx
pushds
movax,segint_pr
movds,ax
movdx,offsetint_pr
movax,250bh
int21h
popds
inal,21h
movfmimr,al
andal,0f7h
out21h,al
inal,0a1h
movfmimr1,al
andal,00h
out0a1h,al
begin:
orflag0,08h
xorax,ax
calldisp
xordx,dx
moval,operator
cmpal,0ah
jeoadd
cmpal,0bh
jeosub
cmpal,0ch
jeomul
cmpal,0dh
jeodiv
oadd:
movax,operand1
addax,operand2
movresult,ax
jmpover0
osub:
movax,operand1
subax,operand2
movresult,ax
jmpover0
omul:
movax,operand1
muloperand2
movresult,ax
jmpover0
odiv:
movax,operand1
divoperand2
movresult,ax
over0:
movah,0
int16h
movtime,0000h
movflag3,01h
sti
lop:
hlt
movah,0bh
int21h
addal,1
jnzlop
movflag3,00h
cli
movax,time
divtfor
xchgah,al
andflag0,0f7h
movsi,200h
movcx,2
movnumsys,10d
output:
movax,result
calldisp
movdx,9999h
delay2:
decdx
cmpdx,0
jnzdelay2
movflag4,1
movax,time
calldisp
movflag4,0
movdx,9999h
delay1:
decdx
cmpdx,0
jnzdelay1
loopoutput
movoperand1,0
movoperand2,0
movoperator,0
movflag0,0
movflag1,0
movflag2,1
movflag3,0
movflag4,0
jmpbegin
hlt
movdx,int_seg
movax,int_off
movds,ax
movax,250bh
int21h
moval,fmimr
out21h,al
moval,fmimr1
out0a1h,al
dispproc
pushax
pushbx
pushcx
pushdx
pushdi
pushsi
pushf
newn:
movbx,offsetmdisp
xorcx,cx
sep:
xordx,dx
divnumsys
movdi,cx
mov[bx][di],dl
inccx
cmpax,0
jnzsep
lc:
incdi
xordl,dl
mov[bx][di],dl
cmpdi,3
jnelc
moval,flag4
cmpal,0
jzxlt
movcx,4
xlt:
movtemp,cx
refh:
movcx,temp
movdi,cx
decdi
movah,01h
shlah,cl
op:
shrah,1
moval,ah
movdx,p85c
outdx,al
moval,[bx][di]
movtmp,bx
movbx,offsettab
xlat
cmpdi,2
jneno
cmpflag4,0
jzno
addal,80h
no:
movbx,tmp
decdi
movdx,p85b
outdx,al
moval,flag0
andal,08h
cmpal,0
jnziping
movcx,9999h
ag:
loopag
jmptst
iping:
movcx,20h
delay0:
moval,flag0
andal,04h
cmpal,0
jnzover
pushax
callreadnum
callstore
movdl,flag0
anddl,02h
cmpdl,0
jzgoon
andflag0,0fdh
popdi
jmpnewn
lim:
jmprefh
goon:
popax
loopdelay0
tst:
cmpah,01h
jnzop
movdl,flag0
anddl,08h
cmpdl,0
jnzlim
decsi
cmpsi,0
jnzlim
movdx,p85c
moval,00h
outdx,al
over:
popf
popsi
popdi
popdx
popcx
popbx
popax
ret
dispendp
storeproc
pushbx
pushcx
pushdx
movbl,flag0
andbl,02h
cmpbl,0
jzjp0
movbl,flag2
andbl,01h
jzinopd2
cmpal,09h
jastopt
movnumsys,10d
movbx,ax
movax,operand1
mulnumsys
addax,bx
movoperand1,ax
jp0:
jmprtn
inopd2:
movbl,flag2
andbl,04h
jzerror0
cmpal,09h
jastopt
movnumsys,10d
movbx,ax
movax,operand2
mulnumsys
addax,bx
movoperand2,ax
jmprtn
error0:
movdx,offsetmes3
movah,09h
int21h
jmprtn
stopt:
andflag2,11111110b
orflag2,04h
cmpal,0ah
jnzchk1
movoperator,0ah
orflag2,04h
movnumsys,10h
jmprtn
chk1:
cmpal,0bh
jnzchk2
movoperator,0bh
orflag2,04h
movnumsys,10h
jmprtn
chk2:
cmpal,0ch
jnzchk3
movoperator,0ch
orflag2,04h
movnumsys,10h
jmprtn
chk3:
cmpal,0dh
jnzchk4
movoperator,0dh
orflag2,04h
movnumsys,10h
jmprtn
chk4:
cmpal,0fh
jnzerror0
orflag0,04h
movnumsys,10h
jmprtn
rtn:
popdx
popcx
popbx
ret
storeendp
readnumproc
pushbx
pushcx
pushdx
pushdi
moval,flag0
andal,01h
jzini0
moval,flag1
notal
oral,0f0h
movdx,p85a
outdx,al
movdx,p85c
inal,dx
notal
andal,0f0h
cmpal,0
jnzrtn1
andflag0,0feh
movflag1,00h
jmprtn1
ini0:
movah,01111111b
movcx,04h
conr0:
movdx,p85a
rolah,1
moval,ah
outdx,al
movdx,p85c
inal,dx
oral,0fh
notal
cmpal,0
loopzconr0
jzrtn1
notah
addal,ah
xorah,ah
movflag1,al
orflag0,03h
movbx,data
moves,bx
movdi,offsettab1
cld
movcx,10h
repnzscasb
movsi,500d
movax,di
subax,offsettab1
decax
rtn1:
popdi
popdx
popcx
popbx
ret
readnumendp
int_prproc
cli
pushax
pushf
moval,flag3
cmpal,0
jznocount
movax,time
incax
movtime,ax
nocount:
moval,20h
out20h,al
sti
popf
popax
iret
int_prendp
codeends
endstart