微机原理期末编程.docx
- 文档编号:7759711
- 上传时间:2023-01-26
- 格式:DOCX
- 页数:12
- 大小:40.47KB
微机原理期末编程.docx
《微机原理期末编程.docx》由会员分享,可在线阅读,更多相关《微机原理期末编程.docx(12页珍藏版)》请在冰豆网上搜索。
微机原理期末编程
《微机原理》课程设计
课程号:
B0901270课堂号:
学号:
1209030313姓名:
万佳成绩:
设计内容:
1.从键盘输入一个十进制数,范围在-128~127,编程将其转换为二进制数,以十六进制数形式在显示器上显示。
2.已知字节变量buf1的内容是:
320,210,160,120,36,10,字节变量buf2的内容是:
813,260,180,93,22,11,2,编写程序将两个变量中的数据合并到字节变量buf3中,且要求buf3中的数据为降序排列。
3.从键盘输入十个任意正整数,范围在0~127之间,按降序排序后在屏幕输出。
编程实现该要求。
4.使用二重循环,在屏幕输出下述图形:
*****
***
*
第一题
stacksegmentstack'stack'
dw32dup(0)
stackends
datasegment
IBUFDB7,0,7DUP(0)
OBUFDB6DUP(0)
dataends
codesegment
beginprocfar
assumess:
stack,cs:
code,ds:
data
pushds
subax,ax
pushax
movax,data
movds,ax
MOVDX,OFFSETIBUF
MOVAH,10
INT21H
MOVDL,0AH
MOVAH,2
MOVCL,IBUF+1
MOVCH,0
MOVSI,OFFSETIBUF+2
CMPBYTEPTR[SI],'-'
PUSHF
JNESININC
INCSI
DECCX
SININC:
MOVAX,0
AGAIN:
MOVDX,10
MULDX
ANDBYTEPTR[SI],0FH
ADDAL,[SI]
ADCAH,0
INCSI
LOOPAGAIN
POPF
JNZNNEG
NEGAX
NNEG:
MOVCX,404H
MOVSI,4
MOVWORDPTROBUF[SI],'$H'
AG:
MOVDL,0FH
ANDDL,AL
ADDDL,30H
CMPDL,3AH
JCNOAD7
ADDDL,7
NOAD7:
DECSI
MOVOBUF[SI],DL
SHRAX,CL
DECCH
JNZAG
callcrlf;回车换行
MOVBX,OFFSETOBUF-1
COUNT:
INCBX
CMPBYTEPTR[BX],'0'
JECOUNT
MOVDX,BX
MOVDX,BX
MOVAH,9
INT21H
Ret
beginendp
crlfprocnear
movdl,0dh
movah,2
int21h
movdl,0ah
movah,2
int21h
ret
crlfendp
codeends
endbegin
第二题
datasegment
buf1dw320,210,160,120,36,10
buf2dw813,260,180,93,22,11,2
buf3db100dup(?
),'$'
tmpdb100dup(?
),'$'
dataends
codesegment
assumecs:
code,ds:
data
START:
movax,data
movds,ax
movdi,0
movsi,0
movbx,0
STEP:
cmpsi,14
jeSTEPA
cmpdi,12
jeSTEPB
movax,buf1[di]
cmpax,buf2[si]
jaSTEPA
movax,buf2[si]
cmpax,buf1[di]
jaSTEPB
STEPA:
cmpdi,12
jeexit
movax,0
movax,buf1[di]
movbp,0
chgA:
movcx,10
movdx,0
divcx
adddx,30h
movcx,dx
movtmp[bp],cl
incbp
cmpax,0
jeexitA
jmpchgA
exitA:
decbp
movcl,tmp[bp]
movbuf3[bx],cl
incbx
cmpbp,0
jelastA
jmpexitA
lastA:
movbuf3[bx],','
incbx
adddi,2
jmpSTEP
STEPB:
cmpsi,14
jeexit
movax,0
movax,buf2[si]
movbp,0
chgB:
movcx,10
movdx,0
divcx
adddx,30h
movcx,dx
movtmp[bp],cl
incbp
cmpax,0
jeexitB
jmpchgB
exitB:
decbp
movcl,tmp[bp]
movbuf3[bx],cl
incbx
cmpbp,0
jelastB
jmpexitB
lastB:
movbuf3[bx],','
incbx
addsi,2
jmpSTEP
exit:
leadx,buf3
movah,9
int21h
MOVAH,4CH
INT21H
codeends
ENDSTART
第三题
datasegment
arraydb10dup(?
)
Buf1db4,?
4dup(?
)
flagdb0
dataends
stacksegmentstack
dw32dup(?
)
stackends
codesegment
assumeds:
data,cs:
code,ss:
stack
BEGIN:
movax,data
movds,ax
movcx,10
leabx,array
Input:
leadx,Buf1
movah,0ah
int21h
movdl,0ah
movah,2
int21h
callbint
mov[bx],al
incbx
loopInput
;排序
movcx,9
OuterSort:
pushcx
leasi,array
InterSort:
moval,[si]
cmpal,[si+1]
jaeNext
xchgal,[si+1]
mov[si],al
Next:
incsi
loopInterSort
popcx
loopOuterSort
;输出
movcx,10
leabx,array
Output:
xorah,ah
moval,[bx]
callstart
incbx
loopOutput
movah,04ch
int21h
bintproc
movax,0
pushcx
pushbx
movcl,10
leasi,Buf1+2
Loop1:
movbl,[si]
cmpbl,0dh
jeCalcDone
subbl,'0'
mulcl
addal,bl
incsi
jmpLoop1
CalcDone:
popbx
popcx
ret
bintendp
startproc
pushcx
movflag,0
leasi,Buf1
movdl,100
movcl,10
Loop2:
xorah,ah
divdl
cmpal,0
jneNext2
cmpflag,0
jeNext3
Next2:
movflag,1
mov[si],al
addbyteptr[si],'0'
incsi
Next3:
pushax
movax,0
moval,dl
divcl
movdl,al
popax
moval,ah
cmpdl,0
jneLoop2
movbyteptr[si],''
movbyteptr[si+1],'$'
leadx,Buf1
movah,9
int21h
popcx
ret
startendp
codeends
endBEGIN
第四题
CODESEGMENT
ASSUMECS:
CODE
START:
MOVCX,3;控制外循环
MOVBX,5;控制*号个数
S:
PUSHBX
SYM:
MOVAH,02H
MOVDL,'*'
INT21H
DECBX
JNZSYM
POPBX
SUBBX,2;每行*号之间相差两个
CALLCRLF;回车换行
LOOPS
MOVAX,4C00H
INT21H
CRLF:
MOVAH,02H
MOVDL,0DH
INT21H
MOVDL,0AH
INT21H
RET
CODEENDS
ENDSTART
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 微机 原理 期末 编程