《微机原理:顺序、分支、循环、子程序设计(15页).docx》由会员分享,可在线阅读,更多相关《微机原理:顺序、分支、循环、子程序设计(15页).docx(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-微机原理:顺序、分支、循环、子程序设计实验二 顺序、分支、循环、子程序设计微机原理上机实验作者姓名日期预习报告零、相关知识1,LEA指令和MOV指令的区别一、顺序结构计算m*n-w,最终结果保存在AX其中m=12, n=12, w=4最终结果为AX=008CH=140Dname sequence strctureorg 100hMOV AX, 1000HMOV DS, AXMOV SI, 1000H MOV SI, 12MOV SI+1, 12MOV SI+2, 4MOV AL, SIMOV BL, SI+1MUL BLMOV BX, 0MOV BL, SI+2SUB AX, BX HLT二
2、、分支结构在DS数据段偏移地址为DATA开始的顺序80个单元中,存放着某班80个同学的微机原理考试成绩。现欲编程序统计=90、8970、6960和60分的人数,并将统计的结果存放在当前数据段偏移地址为BUFFER的顺序单元中name “branch structure”START:MOV DX, 0000HMOV BX, 0000HMOV CX, 80LEA SI, DATALEA DI, BUFFERGOON:MOV AL, SICMP AL, 90JC NEXT3INC DHJMP STORNEXT3:CMP AL, 70JC NEXT5INC DLJMP STORNEXT5:CMP AL
3、, 60JC NEXT7INC BHJMP STORNEXT7:INC BLSTOR:INC SILOOP GOONMOV DI, DHMOV DI+1, DLMOV DI+2, BHMOV DI+3, BLHLT三、循环结构在DS所决定的数据段,从偏移地址BUFFER开始顺序存放100个无符号16位数。现欲编程序将这100个数按大小顺序排序(以下程序使用的是快速排序算法,也可以使用冒泡排序,嵌套两层循环)name “circle structure”LEA DI, BUFFERMOV BL, 99NEXT0:MOV SI, DIMOV CL, BLNEXT3:MOV AX, SIADD, S
4、I, 2CMP AX, SIJNC NEXT 5MOV DX, SIMOV SI-2, DXMOV SI, AXNEXT5:DEC CLJNZ NEXT3DEC BLJNZ NEXT0HLT四、子程序编写程序,完成将一组BCD数转换成16位二进制数。(BCD数转换成16位二进制数用子程序实现)下面提供三种方案,分别用寄存器、储存器和堆栈传递参数使用寄存器传递参数name text subprogram using registerSTACK SEGMENT STACK DB 256 DUP(?)STACK ENDSDATA SEGMENT BCD1 DB 07H, 06H, 07H, 02H,
5、 03H LENG1 DB 5 RESULT DW ?DATA ENDSCODEM SEGMENT ASSUME CS:CODEM, DS:DATA, SS:STACK START: MOV AX, DATA MOV DS, AX LEA SI, BCD1 MOV CX, LENG1 CALL FAR PTR BCD-16B MOV RESULT, DX MOV AH, 4CH INT 21HCODEM ENDSCODES SEGMENT ASSUME CS:CODES ;the part of subprogram BCD-16B PROC FAR PUSH BX PUSH AX ADD S
6、I, CX MOV DX, 0 BCDL: DEC SI PUSH CX MOV AL, SI AND AL, 0FH CBW MOV BX, AX MOV AX, DX MOV CX, 10 MUL CX MOV DX, AX ADD DX, BX POP CX LOOP BCDL POP AX POP BX RET BCD-16B ENDPCODES ENDSEND START使用储存器传递参数name text subprogram using storeSTACK SEGMENT STACK DB 256 DUP(?)STACK ENDSDATA SEGMENT BCD1 DB 07H
7、, 06H, 07H, 02H, 03H ADSEG DW ? ADOFST DW ? LENG1 DW ? RESULT DW ?DATA ENDSCODEM SEGMENT ASSUME CS:CODEM, DS:DATA, SS:STACK START: MOV AX, DATA MOV DS, AX ;entrance parameter MOV AX, SEG BCD1 MOV ADSEG, AX MOV AX, OFFSET BCD1 MOV ADOFST, AX MOV LENG1, 5 CALL FAR PTR BCD-16B MOV AH, 4CH INT 21HCODEM
8、ENDSCODES SEGMENT ASSUME CS:CODES ;the part of subprogram BCD-16B PROC FAR PUSH BX PUSH AX PUSH SI PUSH DS MOV DS, ADSEG MOV SI, ADOFST MOV CX, LENG1 XOR DX, DX ADD SI, CX BCDL: DEC SI PUSH CX MOV AL, SI AND AL, 0FH CBW MOV BX, AX MOV AX, DX MOV CX, 10 MUL CX MOV DX, AX ADD DX, BX POP CX LOOP BCDL P
9、OP AX POP BX POP DS POP SI RET BCD-16B ENDPCODES ENDSEND START使用堆栈传递参数name text subprogram using stackSTACK SEGMENT STACK DB 256 DUP(?)STACK ENDSDATA SEGMENT BCD1 DB 07H, 06H, 07H, 02H, 03H LENG1 DW ? RESULT DW ?DATA ENDSCODEM SEGMENT ASSUME CS:CODEM, DS:DATA, SS:STACK START: MOV AX, DATA MOV DS, AX
10、 ;push PUSH DS LEA SI, BCD1 PUSH SI MOV CX, LENG1 PUSH CX CALL FAR PTR BCD-16B POP DX MOV RESULT, DX MOV AH, 4CH INT 21HCODEM ENDSCODES SEGMENT ASSUME CS:CODES ;the part of subprogram BCD-16B PROC FAR PUSH BP MOV BP, SP PUSH DS PUSH SI PUSH CX PUSH BX PUSH AX MOV CX, BP+6 MOV SI, BP+8 MOV DS, BP+10
11、ADD SI, CX MOV DX, 0 BCDL: DEC SI PUSH CX MOV AL, SI AND AL, 0FH CBW MOV BX, AX MOV AX, DX MOV CX, 10 MUL CX MOV DX, AX ADD DX, BX POP CX LOOP BCDL POP AX POP BX POP CX POP DS POP SI POP BP RET A BCD-16B ENDPCODES ENDSEND START正式实验报告一、实验要求1教材P74例1。m=6,n=4,w=7。结果Q也放在内存中。2教材P75例3。3从键盘上输入1个数,判断其奇偶性,如果是
12、奇数,屏幕上显示”It is odd”,否则显示”It is even”。4从键盘上输入N个字符(NALMOV BX, 0MOV BL, SI+2SUB AX, BX HLT3.2 textbook page75-3用0,1,C,D,E,O,P,Q,R,S,$的ASCII值代表10位学生的分数,分别为48/49/67/68/69/79/80/81/82/83分name textbook page75-3data segment SCORES DB 0,1,C,D,E,O,P,Q,R,S,$ ;48/49/67/68/69/79/80/81/82/83ends code segmentstart
13、: ASSUME DS:DATA, CS:CODE MOV AX, DATA MOV DS, AX MOV CX, 10 MOV SI, OFFSET SCORES; MOV SI, OFFSET SCORES MOV DI, 0000H GOON:MOV AL, SICMP AL, 90JC NEXT3INC DHJMP STORNEXT3:CMP AL, 70JC NEXT5INC DLJMP STORNEXT5:CMP AL, 60JC NEXT7INC BHJMP STORNEXT7:INC BLSTOR:INC SILOOP GOONMOV DI, DHMOV DI+1, DLMOV
14、 DI+2, BHMOV DI+3, BLendsend start由结果可知:DH=0,DL=5,BH=3,BL=2说明90以上0人,8970有5人,6960有3人,小于60有2人3.3 experiment 2-3name experiment 2-3 data segment HEX1 DB 0AH,0DH,It is even$ HEX2 DB 0AH,0DH,It is odd$;0AH,0DH换行+回车 endscode segment start: ASSUME DS:DATA MOV AX, DATA MOV DS, AX ;read from the keyboard MOV
15、 CX, 16 DO: MOV AH, 01H INT 21H CMP AL, 13 JZ NEXT0 MOV BL, AL LOOP DO NEXT0: SUB BL, 48 MOV AL, BL MOV BL, 2 DIV BL CMP AH, 1 JNZ NEXT1 JZ NEXT2 NEXT1: LEA DX, HEX1 MOV AH, 09H INT 21H HLT NEXT2: LEA DX, HEX2 MOV AH, 09H INT 21H endsend start若输入的为偶数若输入的为奇数3.4 experiment 2-4name experiment 2-4data s
16、egment HEX DB 16 DUP(0) endscode segmentstart: ASSUME DS:DATA MOV AX, DATA MOV DS, AX MOV CX, 16;read from keyboardread: CMP CX, 1 JZ STOP MOV AH, 01H INT 21H CMP AL, 65 JZ count CMP AL, 13 JZ STOP LOOP read ;count A characterscount: INC BL LOOP readSTOP: MOV AH, 02H MOV DL, 0AH INT 21H; 打印换行 MOV DL
17、, 0DH INT 21H;打印回车 ADD BL, 48 MOV DL, BL INT 21Hendsend start3.5 experiment 2-5冒泡排序,没有在BUF3中除去重复的字符此题设两个字符串为BUF1 = ”ACEGIK”BUF2 = ”BDFJLHMN”name experiment 2-5;此程序不需要压入堆栈保护的数据data segment BUF1 DB ACEGIK$ BUF2 DB BDFJLHMN$ BUF3 DB 14 DUP(0) ends stack segment DB 256 DUP(0)endscode segmentstart: ASSUM
18、E DS:DATA, CS:CODEL, SS:STACK MOV AX, DATA MOV DS, AX LEA BX, BUF1 LEA SI, BUF2 LEA DI, BUF3 CALL remove CALL reorder;段内转移,若段间转移,测试一下格式 ;print on the screen LEA DX, BUF3 MOV AH, 09H INT 21H HLT remove proc near MOV CX, 6 DO1: MOV AX, BX MOV DI, AX INC BX INC DI LOOP DO1 MOV CX, 8 DO2: MOV AX, SI MOV
19、 DI, AX INC SI INC DI LOOP DO2 RET remove endp reorder proc near MOV CX, 13;注意是13,思考清楚 JUDGE1: LEA DI, BUF3 PUSH CX MOV CX, 13 JUDGE2: MOV AL, DI MOV BL, DI+1 CMP AL, BL JC NEXT1 MOV DI+1, AL MOV DI, BL NEXT1: INC DI LOOP JUDGE2 POP CX LOOP JUDGE1 RET reorder endpend start采用串的合并的算法,可以除去BUF3中重复的字符nam
20、e experiment 2-5plusdata segment BUF1 DB ACEGIK$ BUF2 DB BCFHILMN$ BUF3 DB 14 DUP(0) ends stack segment DB 256 DUP(0)endscode segmentstart: ASSUME DS:DATA, CS:CODEL, SS:STACK MOV AX, DATA MOV DS, AX LEA BX, BUF1 LEA SI, BUF2 LEA DI, BUF3 NEXT0: MOV AX, BX MOV DX, SI CMP AL, DL; 写成CMP AX, DX会出错 JC NE
21、XT1 JZ NEXT1_5 JA NEXT2 NEXT1: MOV DI, AX INC DI INC BX JMP NEXT3 NEXT1_5: MOV DI, AX INC BX INC SI INC DI JMP NEXT3 NEXT2: MOV DI, DX INC DI INC SI JMP NEXT3 NEXT3: CMP BX+1, 36 JZ NEXT5 CMP SI+1, 36 JZ NEXT6 LOOP NEXT0 NEXT5: INC SI CMP SI, 36 JZ PRINT MOV DX, SI MOV DI, DX INC DI LOOP NEXT5 NEXT6: INC BX CMP BX, 36 JZ PRINT MOV AX, BX MOV DI, AX INC DI LOOP NEXT6-第 13 页公司名称