汇编经典小程序.docx
《汇编经典小程序.docx》由会员分享,可在线阅读,更多相关《汇编经典小程序.docx(7页珍藏版)》请在冰豆网上搜索。
![汇编经典小程序.docx](https://file1.bdocx.com/fileroot1/2023-2/1/2fdd0435-2f7a-4120-9507-07452bfadd37/2fdd0435-2f7a-4120-9507-07452bfadd371.gif)
汇编经典小程序
实验一:
判断一个数X的正,负数,还是零。
(假设是正数,输出+,是负数,输出-,是零,输出Thisisazore!
)
DATASEGMENT
XDB10
CREQU0DH
LFEQU0AH
WDB'Thisisazore!
',CR,LF,'$'
ZHENGDB'+',CR,LF,'$'
FUDB'-',CR,LF,'$'
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVAL,X
ANDAL,AL
JZL1
SHLAL,1
JCL3
JMPL2
L1:
MOVDX,OFFSETW
MOVAH,9
INT21H
JMPL4
L2:
MOVDX,OFFSETZHENG
MOVAH,9
INT21H
JMPL4
L3:
MOVDX,OFFSETFU
MOVAH,9
INT21H
JMPL4
L4:
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
实验二:
求十个数中的最小数,并以十进制输出。
(若要求最大的,只要把JC改为JNC即可)(仅局限于0---16间的数比较,因为ADDAL,30H只是针对一位的十六进制转换十进制的算法)
DATASEGMENT
XDATDB0AH,1FH,02H,03H,04H,05H,06H,07H,08H,09H
MINDB?
CREQU0DH
LFEQU0AH
WDB'ismin',CR,LF,'$'
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVCX,9
MOVSI,OFFSETXDAT
MOVAL,[SI]
L2:
CMPAL,[SI+1]
JCL1
MOVAL,[SI+1]
L1:
INCSI
LOOPL2
ADDAL,30H
MOVDL,AL
MOVAH,2
INT21H
MOVDX,OFFSETW
MOVAH,9
INT21H
CODEENDS
ENDSTART
实验三:
设有3个单字节无符号数存放在BUF开始的缓冲区中,编写一个能将它们从大到小从新排列的程序。
DATASEGMENT
BUFDB87,234,123
DATAENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVSI,OFFSETBUF
MOVAL,[SI];把3个数取到寄存器中
MOVBL,[SI+1]
MOVCL,[SI+2]
CMPAL,BL;排序,将最大数送AL寄存器
JAENEXT1
XCHGAL,BL
NEXT1:
CMPAL,CL
JAENEXT2
XCHGAL,CL
NEXT2:
CMPBL,CL;将最小输送CL寄存器
JAENEXT3
XCHGBL,CL
NEXT3:
MOV[SI],AL;从大到小依次存回缓冲区,AL,BL,CL
MOV[SI+1],BL
MOV[SI+2],CL
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
实验三
(2):
设某一数组的长度为N,个元素均为字数据,试编制一个程序使该数组中的数据按照从小到大的次序排列。
(要从大到小排序,只需把JBE改为JAE即可)
ADATASEGMENT
NEQU10
DATADW87,54,78,45,35,23,04H,12H,03H,21H
ADATAENDS
ACODESEGMENT
ASSUMECS:
ACODE,DS:
ADATA
START:
MOVAX,ADATA
MOVDS,AX
MOVDS,AX
MOVBX,0
MOVCX,N
DECCX
LOP1:
MOVDX,CX
LOP2:
MOVAX,DATA[BX]
CMPAX,DATA[BX+2]
JBECONTI
XCHGAX,DATA[BX+2]
MOVDATA[BX],AX
CONTI:
ADDBX,2
LOOPLOP2
MOVCX,DX
MOVBX,0
LOOPLOP1
MOVAH,4CH
INT21H
ACODEENDS
ENDSTART
实验四:
求十个数中的最小数,并以十六进制输出。
(若要求最大的,只需把JC改为JNC即可)
DATASEGMENT
XDATDB0AH,1FH,0FH,0FH,0EH,0BH,0CH,0DH,0EH,0CH
TABDB30H,31H,32H,33H,34H,35H,36H,37H,38H,39H,41H,42H,43H,44H,45H,46H
MINDB?
CREQU0DH
LFEQU0AH
WDB'ismin',CR,LF,'$'
DATAENDS
SSEGSEGMENTSTACK
DW100DUP(?
)
SSEGENDS
CODESEGMENT
ASSUMECS:
CODE,DS:
DATA
START:
MOVAX,DATA
MOVDS,AX
MOVCX,9
MOVSI,OFFSETXDAT
MOVAL,[SI]
L2:
CMPAL,[SI+1]
JCL1
MOVAL,[SI+1]
L1:
INCSI
LOOPL2
CALLDISPP
MOVDX,OFFSETW
MOVAH,9
INT21H
MOVAH,4CH
INT21H
DISPPPROCNEAR
PUSHDX
PUSHCX
MOVDL,AL
MOVCL,4
ROLDL,CL
ANDDL,0FH
CALLDISP1
MOVDL,AL
ANDDL,0FH
CALLDISP1
POPCX
POPDX
RET
DISPPENDP
DISP1PROCNEAR
PUSHAX
PUSHBX
PUSHCX
PUSHDX
MOVAL,DL
MOVBX,OFFSETTAB
MOVAH,0
ADDBX,AX
MOVDL,[BX]
MOVAH,2
INT21H
POPDX
POPCX
POPBX
POPAX
RET
DISP1ENDP
CODEENDS
ENDSTART
WelcomeTo
Download!
!
!
欢迎您的下载,资料仅供参考!