《一些简单的汇编程序(共6页).doc》由会员分享,可在线阅读,更多相关《一些简单的汇编程序(共6页).doc(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上1.编制程序计算S=1+2+3+4+N直到和大于500为止,并将结果在屏幕上显示出来(N的值和最终的和的值)。DATA SEGMENT N DW ? SUM DW ? DATA ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATASTART: MOV AX,DATA MOV DS,AX MOV AX,0 MOV BL,0E1: INC BL ADD AX,BX CMP AX,500 JBE E1 MOV N,BX MOV SUM,AX E2: MOV AX,BX MOV BL,10 DIV BL ADD AL,30H MOV DL,AL MO
2、V CL,AH MOV AH,2 INT 21H ADD CL,30H MOVDL,CL MOV AH,2 INT 21H MOV AH,2 MOV DL,0AH INT 21H MOV AX,SUM CWD MOV BX,100 DIV BX MOV CX,DX ADD AL,30H MOV DL,AL MOV AH,2 INT 21H MOV BL,10 MOV AX,CX DIV BL MOV CL,AH MOV AH,2 ADD AL,30H MOV DL,AL INT 21H MOV AH,2 ADD CL,30H MOV DL,CL INT 21H MOV AH,4CH INT 2
3、1HCODE ENDSEND START2.从键盘输入学生成绩(A、B、C、D),自动汇总并显示各类分数的人数。按下$键则停止输入;若按下A、B、C、D之外的键则提示“INPUT ERROR”信息。DATA SEGMENT M1 DB Please input A,B,C,D:,13,10,$ M2 DB 13,10,Input error! ,13,10,$ M3 DB 13,10,The number of A is: $ M4 DB 13,10,The number of B is: $ M5 DB 13,10,The number of C is: $ M6 DB 13,10,The
4、number of D is: $ DATA ENDSSTACK SEGMENT STACK ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACKSTART: MOV AX,DATA MOV DS,AX MOV AH,9 MOV DX,OFFSET M1 INT 21H MOV BX,0 MOV CX,0E1: MOV AH,1 INT 21H MOV AH,41H CMP AL,AH JNZ E2 INC BL JMP E1E2: MOV AH,42H CMP AH,AL JNZ E3 INC BH JMP E1E3: MOV AH,43H CMP
5、 AH,AL JNZ E4 INC CL JMP E1E4: MOV AH,44H CMP AH,AL JNZ E5 INC CH JMP E1E5: MOV AH,24H CMP AH,AL JZ E6 MOV AH,9 MOV DX,OFFSET M2 INT 21H JMP E1E6: MOV AH,9 MOV DX,OFFSET M3 INT 21H MOV AH,2 ADC BL,30H MOV DL,BL INT 21H MOV AH,9 MOV DX,OFFSET M4 INT 21H MOV AH,2 ADC BH,30H MOV DL,BH INT 21H MOV AH,9
6、MOV DX,OFFSET M5 INT 21H MOV AH,2 ADC CL,30H MOV DL,CL INT 21H MOV AH,9 MOV DX,OFFSET M6 INT 21H MOV AH,2 ADC CH,30H MOV DL,CH INT 21H MOV AH,4CH INT 21HCODE ENDS END START3.动态输入20个二位无符号数,找出其中最大数并显示。DATAS SEGMENT M1 DB Please input 5 numbers:,13,10,$ M2 DB The biggest number is:$ M3DB ,13,10,$ MAX D
7、W ? DATAS ENDSSTACKS SEGMENT STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX MOV MAX,0 LEA DX,M1 MOV AH,9 INT 21H MOV CL,5 LP:MOV AH,1INT 21HSUB AL,30HMOV BH,ALMOV AH,1INT 21HSUB AL,30HMOV BL,ALLEA DX,M3MOV AH,9INT 21HCMP MAX,BXJNL EXITXCHG MAX,BXEXIT: LOOP L
8、P LEA DX,M2 MOV AH,9INT 21HMOV BX,MAXADD BH,30HMOV DL,BHMOV AH,2INT 21HADD BL,30HMOV DL,BLMOV AH,2INT 21H MOV AH,4CH INT 21HCODES ENDS END START4.设数据区有两个字符串,串1的长度为5,串2的长度为10。编程:若串2的最后5个字符和串1相同,则置FLAG单元为“Y”,否则置为“N”。DATAS SEGMENT S1 DB DKJFD$ S2 DB DSFGDDDJFD$ FLAG DB THE FLAF IS THE:$ DATAS ENDSCODES
9、 SEGMENT ASSUME CS:CODES,DS:DATAS,ES:DATASSTART: MOV AX,DATAS MOV DS,AX MOV ES,AX LEA DX,FLAG MOV AH,9 INT 21H LEA SI,S1 LEA DI,S2+5 MOV CX,5 REPE CMPSB JNE EXIT MOV AH,2 MOV DL,Y INT 21H JMP OVEREXIT: MOV AH,2 MOV DL,N INT 21H OVER: MOV AH,4CH INT 21HCODES ENDSEND START5.编写打印图形程序DATAS SEGMENT s db
10、,13,10,$ a dw ?DATAS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATASSTART: MOV AX,DATAS MOV DS,AX mov cx,10 mov bx,9 mov a,2loop1: mov dl,0ah mov ah,2 int 21h mov dl,0dh mov ah,2 int 21hloop2: mov dl,sbx mov ah,2 int 21h inc bx cmp bx,9 jbe loop2 sub bx,a inc a loop loop1 MOV AH,4CH INT 21HCODES ENDS END
11、 START6.用子程序结构编写程序:从键盘入一个二位十进制数的月份(0112),然后显示相应的英文缩写名。DATAS SEGMENT PARA DATA THREE DB 4 MONIN DB 4,5 DUP(?) ALFMON DB 4,?.,$ MONTAB DBJAN.,FEB.,MAR.,APR.,MAY.,JUN.,JUL.,AUG.,SEP.,OCT.,NOV.,DEC. DATAS ENDSCODES SEGMENT PARA CODE ASSUME CS:CODES,DS:DATAS,ES:DATAS MAIN PROC FAR PUSH DS SUB AX,AX PUSH
12、AX MOV AX,DATAS MOV DS,AX MOV ES,AX CALL INPUT CALL LOCATE CALL DISPLAY RET MAIN ENDP INPUT PROC NEAR PUSH DX MOV AH,0AH LEA DX,MONIN INT 21H MOV AH,MONIN+2 MOV AL,MONIN+3 XOR AX,3030H CMP AH,00 JZ RETURN SUB AH,AH ADD AL,10 RETURN: POP DX RET INPUT ENDP LOCATE PROC NEAR PUSH SI PUSH DI PUSH CX LEA
13、SI,MONTAB DEC AL MUL THREE ADD SI,AX MOV CX,03 CLD LEA DI,ALFMON+1 REP MOVSB POP CX POP DI POP SI RET LOCATE ENDP DISPLAY PROC NEAR PUSH DX LEA DX,ALFMON+1 MOV AH,09 INT 21H POP DX RET DISPLAY ENDP CODES ENDS END MAIN7.数组排序DATAS SEGMENTSTRING DB INPUT 20 NUMBERS:,0AH,0DH,$ BUF DB 20 DUP(?) DATAS END
14、SCODES SEGMENT ASSUME CS:CODES,DS:DATASSTART: MOV AX,DATAS MOV DS,AX LEA DX,STRING MOV AH,9 INT 21H MOV CX,20 MOV SI,0LOOP1: ;动态输入20个无符号的两位数 MOV AH,1 INT 21H SUB AL,30H MOV BL,10 MUL BL MOV DX,AX MOV AH,1 INT 21H SUB AL,30H ADD DL,AL MOV BL,DL MOV AH,2 MOV DL, INT 21H MOV BUFSI,BL INC SI LOOP LOOP1
15、MOV CX,19 ;比较19次E1: MOV DI,CX MOV BX,0E2: ;用冒泡法比较,前后比较 MOV AL,BUFBX CMP AL,BUFBX+1 JNG E3 XCHG AL,BUFBX+1 MOV BUFBX,ALE3: ADD BX,1 LOOP E2 MOV CX,DI LOOP E1 MOV AH,2 MOV DL,0AH INT 21H MOV AH,2 MOV DL,0DH INT 21H MOV CL,20 ;从小到大输出数组 MOV BX,0 MOV SI,0LOOP2: MOV AL,BUFSI CBW MOV BL,10 DIV BL MOV BH,AH
16、 MOV AH,2 ADD AL,30H MOV DL,AL INT 21H MOV AH,2 ADD BH,30H MOV DL,BH INT 21H MOV AH,2 MOV DL, INT 21H INC SI LOOP LOOP2 MOV AH,2 MOV DL,0AH INT 21H MOV AH,2 MOV DL,0DH INT 21H MOV AH,4CH INT 21HCODES ENDS END START8.求三个数中最大的数DATAS SEGMENT BUF1 DB 3 BUF2 DB 9 BUF3 DB 7 MAX DB ? STRING DB The max namb
17、er is:,13,10,$DATAS ENDSSTACKS SEGMENT STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX MOV BL,BUF2 CMP BUF1,BL JG NEXT MOV CL,BUF3 CMP BUF2,CL JG E3 JMP E1NEXT: MOV CL,BUF3 CMP BUF1,CL JG E2 JMP E1E1: MOV BL,BUF3 MOV MAX,BL JMP OVERE2: MOV AL,BUF1 MOV MAX,AL JMP OVERE3: MOV CL,BUF2 MOV MAX,CL JMP OVEROVER: MOV DX,OFFSET STRING MOV AH,9 INT 21H MOV AH,2 ADD MAX,30H MOV DL,MAX INT 21H MOV AH,4CH INT 21HCODES ENDS END START专心-专注-专业