《8086汇编经典例程.doc》由会员分享,可在线阅读,更多相关《8086汇编经典例程.doc(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、关于做好全日制研究生入学考试考试科目大纲编制工作的通知=5. 编写一个数组排序(从小到大)的小程序,数组在程序中定义,程序先将原数组显示一遍,然后排序,再将排好序的数组显示一遍。=AAA SEGMENTBUF DB 6455412345$ L = $ - BUFary dw -897,345,6789,8654,-1234,-3456,-99,-678,987,567,32762,-12121,0,3434,4645,-234,23455,-100,100,1000,-1000 dw 572,-2345,-6543,-1234,9999len dw ($-ary)/2ASSUME CS:AAA
2、,DS:AAAMAIN PROC FARPUSH CSPOP DSLEA SI,ARYMOV CX,LENNEXT3:MOV BX,SICALL DISPCALL SPACEADD SI,2LOOP NEXT3CALL CRLFCALL CRLFLEA SI,ARY MOV CX,LENCALL SORTLEA SI,ARYMOV CX,LENNEXT5:MOV BX,SICALL DISPCALL SPACEADD SI,2 LOOP NEXT5MOV AH,4CHINT 21HMAINENDPDISP PROC PUSH SIPUSH AXPUSH BXPUSH DXPUSH CXMOV
3、CX,0CMP BX,0JNL NEXT1NEG BXMOV CX,1NEXT1:LEA SI,BUF+l-1MOV AX,BXMOV BX,10NEXT:MOV DX,0DIV BXADD DL,30HDEC SIMOV SI,DLCMP AX,0JNE NEXTCMP CX,0JE NEXT2DEC SIMOV BYTE PTR SI,-NEXT2:MOV DX,SIMOV AH,9INT 21HPOP CXPOP DXPOP BXPOP AXPOP SIRETDISPENDPSORT PROC NEXTT: PUSH CX MOV DI,SI MOV AX,SINEXT0: CMP AX
4、,DI JL NEXTQ MOV BX,AX MOV AX,DI MOV DI,BXNEXTQ: ADD DI,2 LOOP NEXT0 MOV SI,AX ADD SI,2 POP CX LOOP NEXTTRETSORT ENDPCRLF PROCPUSH AX PUSH DX MOV DL,13 MOV AH,2 INT 21H MOV DL,10 INT 21H POP DX POP AX RETCRLF ENDPSPACE PROCPUSH AXPUSH DXMOV DL, MOV AH,2INT 21HPOP DXPOP AXRETSPACE ENDPAAA ENDSEND MAI
5、N=6. 编写一个程序,从键盘输入10个十进制数字字符,然后将这些数字加密存储在缓冲区BUFFER中。加解密表如下:=qqq segmentTAB1 DB QWERTYUIOPASDFGHJKLZXCVBNMTAB2 DB qazwsxedcrfvtgbyhnujmikolpTAB3 DB )(*&%/#!LEN = $-tab1MSS1 DB 13,10,Please chose a functioc:,0DH,0AH DB 1-jiami ,0DH,0AH DB 2-jiemi ,13,10 DB 0-exit$MSS2 DB 0dh,0ah,Error! You have press k
6、ey!$MM1 DB Your input is:BUF1 DB 255 DUP(?)MM2 DB My output is:BUF2 DB 255 DUP(?)qqq endsccc segmentassume cs:ccc,ds:qqqmain proc farstart: mov ax,qqqmov ds,axrep1: call crlf LEA SI,BUF1 LEA DI,BUF2 lea dx,mss1;显示菜单 mov ah,9 int 21h mov ah,1 ;输入你的选项 int 21h cmp al,0 ;输入0,结束 je quit cmp al,1 ;输入1,加密
7、je jiamicmp al,2 ;输入2,解密 je jiemimov mss2+25,al ;其他字符,错误,重输入 lea dx,mss2 mov ah,9 int 21h jmp rep1quit: mov ah,4ch int 21hjiami: call crlfnext1: mov ah,1 int 21h cmp al,27 je NEXT14 MOV SI,AL cmp al,A jnae next3 cmp al,Z ja next3 sub al,A lea bx,tab1 jmp next10next3: cmp al,a jnae next4 cmp al,z ja
8、next4 sub al,a lea bx,tab2 jmp next10next4: cmp al,0 jb next13 cmp al,9 ja next13 lea bx,tab3 sub al,0next10: xlatnext13: MOV DI,AL INC SI INC DI jmp next1next14: MOV BYTE PTR SI,24H MOV BYTE PTR DI,24H CALL CRLF LEA DX,MM1 MOV AH,9 INT 21H CALL CRLF LEA DX,MM2 INT 21H JMP REP1jiemi: call crlfnext18
9、: mov ah,1 int 21h cmp al,27 je NEXT14 MOV SI,AL mov bx,0next20: cmp al,tab1bx je next22 inc bx cmp bx,62 jb next20 jmp next40next22: cmp bx,26 jae next23 mov al,A add al,bl jmp next40next23: cmp bx,52 jae next24 sub bl,26 mov al,a add al,bl jmp next40next24: sub bl,52 mov al,0 add al,blnext40: MOV
10、DI,AL INC SI INC DI jmp next18main endpcrlf proc push ax push dx mov ah,2 mov dl,13 int 21h mov dl,10 int 21h pop dx pop ax retcrlf endpccc ends end start=7. 编写一个发声的小程序,通过程序使PC喇叭发出声音=PROG SEGMENTMAIN PROC FAR ASSUME CS:PROG,DS:PROGSTART:MOV DX,0000;计产生1,0次数IN AL,61H ;取得设备控制字AND AL,0FCH;使AL最低两位为0CHAN
11、G:XOR AL,3 ;改变输出值OUT 61H,AL;输出到61H端口,扬声器发声MOV CX,00H ;延时计数器WAIT1:LOOP WAIT1;延时DEC DX JNE CHANGMOV AH,4CHINT 21H;返回系统PROG ENDSEND START=8. 编写一个唱歌的小程序,通过程序使PC喇叭发出声音演奏歌曲=;这是一个音乐程序,按大写字母“A”,唱乐曲“玛丽有只小羔羊”;;按大写字母“B”,唱乐曲“太湖船”;按大写字母“C”,唱乐曲“祝福歌”;按Q鍵,退出DATA SEGMENT PARA DATAINFO1 DB 0DH,0AH, WELCOME TO COME HE
12、RE!$INFO2 DB 0DH,0AH,this is a music program!$INFO3 DB 0DH,0AH,please select!$INFO4 DB 0DH,0AH,INPUT ERROR!$INFO5 DB 0DH,0AH,PLEASE INPUT AGAIN!$MUSLIST DB 0DH,0AH,A MUSIC1 DB 0DH,0AH,B MUSIC2 DB 0DH,0AH,C MUSIC3 DB 0DH,0AH,Q EXIT DB 0DH,0AH,$MUS_FREG1 DW 330,294,262,294,3 DUP (330) DW 3 DUP (294),3
13、30,392,392 DW 330,294,262,294,4 DUP (330) DW 294,294,330,294,262,-1MUS_TIME1 DW 6 DUP (25*8),50*8 DW 2 DUP (25*8,25*8,50*8) DW 12 DUP (25*8),100*8 MUS_FREG2 DW 330,392,330,294,330,392,330,294,330 DW 330,392,330,294,262,294,330,392,294 DW 262,262,220,196,196,220,262,294,332,262,-1MUS_TIME2 DW 3 DUP(5
14、0),25,25,50,25,25,100 DW 2 DUP(50,50,25,25),100 DW 3 DUP(50,25,25),100MUS_FREG3 DW 262,262,294,262,349 DW 330,262,262,294,262 DW 392,349,262,262,523 DW 440,349,262,262,466 DW 466,440,262,392,349,-1MUS_TIME3 DW 50,50,100,100,100 DW 100,100,50,50,100,100 DW 100,100,100,50,50,100 DW 100,100,100,100,100
15、,50 DW 50,100,100,100,100,100DATAENDSSTACKSEGMENT PARA STACK STACKDB 200 DUP (STACK)STACKENDS;*定义一个宏*SHOW MACRO bLEA DX,bMOV AH,9INT 21HENDM;*CODE SEGMENT ASSUME DS:DATA, SS:STACK, CS:CODEMAIN PROC FAR MOV AX,DATA MOV DS,AX MOV AH, 0 ;0号功能 MOV AL,4 ;显示方式号4放在 ;AL中320*200四色图形 INT 10H ;显示器输出控制中断调用 MOV
16、AH,0BH ;置彩色调色板 MOV BH,0 MOV BL,1 ;BH=0,BL=4,背景色为红色 INT 10H ;显示器输出控制中断调用 MOV AH,0BH MOV BH,01H MOV BL,00 INT 10H ;显示器输出控制中断调用 show INFO1 show INFO2 show INFO3 show MUSLISTINPUT: MOV AH,01H INT 21H CMP AL,Q JZ retu CMP AL,A JNZ B0 LEA SI,MUS_FREG1 LEA BP,DS:MUS_TIME1 CALL MUSIC JMP EXIT1B0: CMP AL,B J
17、NZ C0 LEA SI,MUS_FREG2 LEA BP,DS:MUS_TIME2 CALL MUSIC JMP EXIT1C0: CMP AL,C JNZ exit LEA SI,MUS_FREG2 LEA BP,DS:MUS_TIME2 CALL MUSICEXIT1: show INFO5 JMP INPUTEXIT: call clear show INFO4 show INFO5 show INFO1 show INFO2 show INFO3 show MUSLIST jmp inputRETU: MOV AH,4CH INT 21HMAIN ENDPMUSIC PROC NEA
18、RFREG1: MOV DI,SI CMP DI,-1 JE END_MUS1 MOV DX,DS:BP MOV BX,1400 CALL GENSOUND ADD SI,2 ADD BP,2 JMP FREG1END_MUS1: RETMUSIC ENDPGENSOUND PROC NEAR PUSH AX PUSH BX PUSH CX PUSH DX PUSH DI MOV AL,0B6H OUT 43H,AL MOV DX,12H MOV AX,533H*896 DIV DI OUT 42H,AL MOV AL,AH OUT 42H,AL IN AL,61H MOV AH,AL OR
19、AL,3 OUT 61H,ALWAIT1: MOV CX,8FF0HDELAY1: LOOP DELAY1 DEC BX JNZ WAIT1 MOV AL,AH OUT 61H,AL POP DI POP DX POP CX POP BX POP AX RETGENSOUND ENDPclear proc near push ax push bx push cx push dx mov ah,6 mov al,0 mov ch,0 mov cl,0 mov dh,24 mov dl,79 mov bh,7 int 10h pop dx pop cx pop bx pop ax retclear
20、 endpCODE ENDSEND MAIN=9. 编写一个通过键盘输入你的名字,然后在屏幕上显示,“hello, 你的名字!”的程序。=DATA SEGMENTBUF DB 30ACTL DB ?STR DB 30 DUP(?)MESS DB what is your name?,0dh,0ah,$DMESS DB 0DH,0AH,Hello, $DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATAMAIN PROC FAR PUSH DS MOV AX,0 PUSH AX MOV AX,DATA MOV DS,AX LEA DX,MESS MOV AH,9
21、 INT 21H LEA DX,BUF MOV AH,10 INT 21H MOV AL,ACTL CBW MOV SI,AX LEA BX,STR MOV BX+SI,BYTE PTR ! MOV BX+SI+1,BYTE PTR $ LEA DX,DMESS MOV AH,9 INT 21H LEA DX,STR MOV AH,9 INT 21H RETMAIN ENDPCODE ENDS END MAIN=11.设在变量SHUJU为起始地址的字节存储单元中存放有N个带符号数,编写程序分别统计: (1)正数的个数; (2 ) 负数的个数; (3)零的个数。 并显示在屏幕上。=data se
22、gmentshuju db 3,-23,-45,-12,-1,1,2,3,4,5,6,7,8,9 db 2,30,0,0,0,4,0,-9,44,-33,-22,-44,-99,-3geshu dW $-shujuzheng db 0fushu db 0ling db 0haokan1 db zheng de ge shu:,$haokan2 db fushu de ge shu:,$haokan3 db ling de ge shu:,$huanhang db 0dh,0ah,$BUF DB 6455412345$ l = $-bufdata endscode segmentassume c
23、s:code,ds:dataKONG PROCPUSH AX PUSH DX mov ah,9 lea dx,HUANHANG int 21h POP DX POP AX RETKONG ENDPstart:mov ax,data mov ds,ax lea si,shuju mov cX,geshuNET1:mov al,si test al,0ffh jz zero cmp al,0 jl plus inc zheng jmp net2plus: inc fushu jmp net2zero: inc lingnet2: INC SI LOOP NET1 lea dx,haokan1 mo
24、v ah,9 int 21h mov Bl,zheng call DISP CALL kong lea dx,haokan2 mov ah,9 int 21h mov Bl,fushu call DISP CALL kong lea dx,haokan1 mov ah,9 int 21h mov Bl,ling call DISP CALL kong mov ax,4c00h int 21hDISP PROC PUSH SIPUSH AXPUSH BXPUSH DXPUSH CXMOV CX,0 MOV BH,0CMP BX,0JNL NEXT1NEG BXMOV CX,1NEXT1:LEA SI,BUF+l-1MOV AX,BXMOV BX,10NEXT:MOV DX,0DIV BXADD DL,30HDEC SIMOV SI,DLCMP AX,0JNE NEXTCMP CX,0JE NEXT2DEC SIMOV BYTE PTR SI,-NEXT2:MOV DX,SIMOV AH,9INT 21HPOP CXPOP DXPOP BXPOP AXPOP SIRETDISPENDP code ends end start页脚内容7