微机实验.docx
《微机实验.docx》由会员分享,可在线阅读,更多相关《微机实验.docx(20页珍藏版)》请在冰豆网上搜索。
微机实验
1.编写完整汇编程序完成从键盘接受一个包含大、小写字母、长度不超过255字节的字符串,统计出其中的大写字母的个数存入UPPER单元。
DATASEGMENT
UPPERDB0;大写字母个数
BUFFERDB255;最大缓冲区
DB?
;输入字母个数
STRINGDB255DUP(?
);输入字母缓冲区
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
LEADX,BUFFER
MOVAH,0AH;调用DOS功能
INT21H
MOVCH,00H
MOVCL,DS:
[BUFFER+1];设置循环次数
LEASI,STRING
CHECK:
MOVAL,[SI];取字母,并判断
CMPAL,'A'
JBNEXT;小于A,next
CMPAL,'Z'
JNBENEXT;大于Z,next
CMPAL,'a';小于a
CAP:
INCUPPER;大写个数加1
NEXT:
INCSI
LOOPCHECK
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
2.设X为有符号数,如果X的绝对值大于5,则变量Y=0,如果X的绝对值不大于5,则变量Y=1-X。
编写程序片段。
DATASEGMENT
XDB?
YDB?
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
CHECK:
MOVAL,DS:
[X];取X的值,并判断X大小
CMPAL,-5
JLY0;X<-5,Y=0
CMPAL,5
JNLEY0;X>5,Y=0
MOVAH,1
SUBAH,AL;|X|<=5,Y=1-X
MOVBYTEPTRY,AH
JMPED
Y0:
MOVBYTEPTRY,0
ED:
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
1.调用DOS功能输入长度不超过255的字符串,如果字符串中包含字串“A1”则在屏幕上打印“Found”,否则打印“Notfound”。
画出流程图并依此编写出完整程序完成上述功能。
STACKSEGMENTSTACK
DW64DUP(?
)
STACKENDS
DATASEGMENT
XLDW?
XHDW?
YLDW?
YHDW?
ZLDW?
ZHDW?
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVAX,XL
ADDAX,YL
MOVZL,AX
MOVAX,XH
ADCAX,YH
MOVZH,AX
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
加:
STACKSEGMENTSTACK
DW64(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
MOVBL,AL
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
ANDAH,00H
ADDAL,BL
AAA
MOVBX,AX
ORBX,3030H
MOVDL,BH
MOVAH,2
INT21H
MOVDL,BL
MOVAH,2
INT21H
INT3
CODEENDS
ENDSTART
STACKSEGMENTSTACK
DW64DUP(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
MOVBL,AL;AL->BL
MOVDL,'+'
MOVAH,2
INT21H
MOVAH,1
INT21H
ANDAH,00H
ADDAL,BL
AAA
MOVCX,AX
ORCX,3030H
TESTAH,01H
MOVDL,'='
MOVAH,2
INT21H
JZA1
MOVDL,CH
MOVAH,2
INT21H
A1:
MOVDL,CL
MOVAH,2
INT21H
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
减:
STACKSEGMENTSTACK
DW64(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
MOVBL,AL
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
CMPBL,AL
JBA0
SUBBL,AL;ALORBL,30H
AAS
MOVDL,BL
MOVAH,2
INT21H
JMPA1
A0:
SUBAL,BL;AL>BL
ORAL,30H
MOVBL,AL;把AL给BL
AAS
MOVDL,'-'
MOVAH,2
INT21H
MOVDL,BL
MOVAH,2
INT21H
A1:
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
STACKSEGMENTSTACK
DW64DUP(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
MOVCL,AL
MOVDL,'-'
MOVAH,2
INT21H
MOVAH,1
INT21H
MOVBL,AL
CMPCL,BL
JBA0
SUBCL,BL
MOVDL,'='
MOVAH,2
INT21H
ORCL,30H
MOVDL,CL
MOVAH,2
INT21H
JMPA1
A0:
MOVDL,'='
MOVAH,2
INT21H
MOVDL,'-'
MOVAH,2
INT21H
SUBBL,CL
MOVAL,BL
AAS
MOVCL,AL
ORCL,30H
MOVDL,CL
MOVAH,2
INT21H
A1:
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTARTS
乘:
STACKSEGMENTSTACK
DW64(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
MOVBL,AL
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
MULBL
AAM;调十进制数
MOVBX,AX
ORBX,3030H;将二进制换为十进制
MOVDL,BH
MOVAH,2
INT21H
JMPA1
A1:
MOVDL,BL
MOVAH,2
INT21H
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
STACKSEGMENTSTACK
DW64DUP(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
MOVBL,AL
MOVDL,'*'
MOVAH,2
INT21H
MOVAH,1
INT21H
MOVCL,AL
ANDCL,0FH
ANDBL,0FH
ANDAL,0FH
MOVAL,BL
MULCL
AAM
MOVCX,AX
ORCX,3030H
MOVDL,'='
MOVAH,2
INT21H
TESTCH,0FH
JZA1
MOVDL,CH
MOVAH,2
INT21H
A1:
MOVDL,CL
MOVAH,2
INT21H
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
除:
STACKSEGMENTSTACK
DW64(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
MOVBL,AL
MOVAH,1
INT21H
ANDAL,0FH;确定输入的数为十以内的
MOVCL,AL
MOVAL,BL
ANDAX,00FFH;AH位上清零,防止未用到AH位,商为零,而它又有数
DIVCL
MOVBX,AX
ORBX,3030H;将二进制换为十进制
MOVDL,BL
MOVAH,2
INT21H
MOVDL,BH
MOVAH,2
INT21H
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
STACKSEGMENTSTACK
DW64DUP(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
MOVBH,AL
MOVAH,1
INT21H
MOVBL,AL
MOVDL,'/'
MOVAH,2
INT21H
MOVAH,1
INT21H
MOVCL,AL
ANDCL,0FH
ANDCH,00H
MOVAX,BX
ANDAX,0F0FH
AAD
DIVCL
MOVCX,AX
ORCX,3030H
MOVDL,'='
MOVAH,2
INT21H
MOVDL,CL
MOVAH,2
INT21H
TESTCH,0FH
JZA1
MOVDL,'.'
MOVAH,2
INT21H
MOVDL,'.'
MOVAH,2
INT21H
MOVDL,'.'
MOVAH,2
INT21H
MOVDL,CH
MOVAH,2
INT21H
A1:
INT3
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
字符串:
STACKSEGMENTSTACK
DB32DUP(?
)
STACKENDS
DATASEGMENT
MESSDB'HELLO,HOWAREYOU?
','$'
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVDX,OFFSETMESS
MOVAH,09H
INT21H
INT3
MOVAH,4CH
CODEENDS
ENDSTART
排序:
STACKSEGMENTSTACK
DW64(?
)
STACKENDS
CODESEGMENT
ASSUMECS:
CODE
START:
MOVAH,1
INT21H
MOVBL,AL
MOVAH,1
INT21H
MOVCL,AL
MOVAH,1
INT21H
CMPAL,BL;AL>BL
JBA0
MOVDL,BL
MOVBL,AL
MOVAL,DL
JMPA0
A0:
CMPAL,CL;AL>CL
JBA1
MOVDL,CL
MOVCL,AL
MOVAL,DL
JMPA1
A1:
CMPBL,CL;BL>CL
JBA2
MOVDL,CL
MOVCL,BL
MOVBL,DL
JMPA2
A2:
MO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