《2022年8086汇编经典例程 .pdf》由会员分享,可在线阅读,更多相关《2022年8086汇编经典例程 .pdf(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、= 5. 编写一个数组排序(从小到大 )的小程序, 数组在程序中定义,程序先将原数组显示一遍,然后排序,再将排好序的数组显示一遍。= AAA SEGMENT BUF DB 6455412345$ L = $ - BUF ary 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,9999 len dw ($-ary)/2 ASSUME CS:AAA, DS:AAA MAIN PR
2、OC FAR PUSH CS POP DS LEA SI,ARY MOV CX,LEN NEXT3: MOV BX,SI CALL DISP CALL SPACE ADD SI,2 LOOP NEXT3 CALL CRLF CALL CRLF LEA SI,ARY MOV CX,LEN CALL SORT LEA SI,ARY MOV CX,LEN NEXT5: MOV BX,SI CALL DISP CALL SPACE ADD SI,2 LOOP NEXT5 MOV AH,4CH INT 21H MAIN ENDP DISP PROC PUSH SI PUSH AX PUSH BX PUS
3、H DX PUSH CX MOV CX,0 CMP BX,0 JNL NEXT1 NEG BX MOV CX,1 NEXT1: LEA SI,BUF+l-1 MOV AX,BX MOV BX,10 NEXT: MOV DX,0 DIV BX ADD DL,30H DEC SI MOV SI,DL CMP AX,0 JNE NEXT CMP CX,0 JE NEXT2 DEC SI MOV BYTE PTR SI,- NEXT2: MOV DX,SI MOV AH,9 INT 21H POP CX POP DX POP BX POP AX POP SI RET DISP ENDP SORT PR
4、OC NEXTT: PUSH CX MOV DI,SI MOV AX,SI NEXT0: CMP AX,DI JL NEXTQ MOV BX,AX MOV AX,DI MOV DI,BX NEXTQ: ADD DI,2 LOOP NEXT0 MOV SI,AX ADD SI,2 POP CX LOOP NEXTT RET SORT ENDP CRLF PROC PUSH AX PUSH DX MOV DL,13 MOV AH,2 INT 21H MOV DL,10 INT 21H POP DX POP AX RET CRLF ENDP SPACE PROC PUSH AX PUSH DX MO
5、V DL, MOV AH,2 INT 21H POP DX POP AX RET SPACE ENDP AAA ENDS END MAIN 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 1 页,共 6 页 - - - - - - - - - = 6. 编写一个程序, 从键盘输入 10个十进制数字字符,然后将这些数字加密存储在缓冲区BUFFER 中。加解密表如下:= qqq segment TAB1 DB QWERTYUIOPASDFGHJKLZXCVBNM TAB
6、2 DB qazwsxedcrfvtgbyhnujmikolp TAB3 DB )(*&%/#! LEN = $-tab1 MSS1 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 key!$ MM1 DB Your input is: BUF1 DB 255 DUP(?) MM2 DB My output is: BUF2 DB 255 DUP(?) qqq ends ccc segm
7、ent assume cs:ccc,ds:qqq main proc far start: mov ax,qqq mov ds,ax rep1: 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,加密je jiami cmp al,2 ;输入 2,解密je jiemi mov mss2+25,al ; 其他字符 ,错误 ,重输入lea dx,mss2 mov ah,9 int 21h
8、 jmp rep1 quit: mov ah,4ch int 21h jiami: call crlf next1: 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 next10 next3: cmp al,a jnae next4 cmp al,z ja next4 sub al,a lea bx,tab2 jmp next10 next4: cmp al,0 jb next13 cmp al,9 ja next13 le
9、a bx,tab3 sub al,0 next10: xlat next13: MOV DI,AL INC SI INC DI jmp next1 next14: 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 REP1 jiemi: call crlf next18: mov ah,1 int 21h cmp al,27 je NEXT14 MOV SI,AL mov bx,0 next20: cmp al,tab1bx
10、 je next22 inc bx cmp bx,62 jb next20 jmp next40 next22: cmp bx,26 jae next23 mov al,A add al,bl jmp next40 next23: cmp bx,52 jae next24 sub bl,26 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 2 页,共 6 页 - - - - - - - - - mov al,a add al,bl jmp next40 next24
11、: sub bl,52 mov al,0 add al,bl next40: MOV DI,AL INC SI INC DI jmp next18 main endp crlf proc push ax push dx mov ah,2 mov dl,13 int 21h mov dl,10 int 21h pop dx pop ax ret crlf endp ccc ends end start = 7. 编写一个发声的小程序,通过程序使 PC喇叭发出声音= PROG SEGMENT MAIN PROC FAR ASSUME CS:PROG,DS:PROG START: MOV DX,00
12、00 ;计产生 1,0 次数IN AL,61H ;取得设备控制字AND AL,0FCH ;使 AL 最低两位为 0 CHANG: XOR AL,3 ;改变输出值OUT 61H,AL; 输出到 61H端口 ,扬声器发声MOV CX,00H ;延时计数器WAIT1: LOOP WAIT1 ;延时DEC DX JNE CHANG MOV AH,4CH INT 21H ;返回系统PROG ENDS END START = 8. 编写一个唱歌的小程序,通过程序使 PC喇叭发出声音演奏歌曲= ;这是一个音乐程序,按大写字母“A” ,唱乐曲“玛丽有只小羔羊” ;;按大写字母“B” ,唱乐曲“太湖船”;按大写
13、字母“C” ,唱乐曲“祝福歌”;按Q 鍵,退出DATA SEGMENT PARA DATA INFO1 DB 0DH,0AH, WELCOME TO COME HERE!$ 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
14、DB 0DH,0AH,Q EXIT DB 0DH,0AH,$ MUS_FREG1 DW 330,294,262,294,3 DUP (330) DW 3 DUP (294),330,392,392 DW 330,294,262,294,4 DUP (330) DW 294,294,330,294,262,-1 MUS_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
15、,294,262, 294,330,392,294 DW 262,262,220,196,196, 220,262,294,332,262,-1 MUS_TIME2 DW 3 DUP(50),25,25,50,25,25,100 DW 2 DUP(50,50,25,25),100 DW 3 DUP(50,25,25),100 MUS_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,-1 MUS_TIME
16、3 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,50 DW 50,100,100,100,100,100 DATA ENDS STACK SEGMENT PARA STACK STACK DB 200 DUP (STACK) STACK ENDS ;*定义一个宏 * SHOW MACRO b LEA DX,b MOV AH,9 INT 21H ENDM ;* CODE SEGMENT ASSUME DS:DATA, SS:STACK, CS:CODE
17、MAIN PROC FAR MOV AX,DATA 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 3 页,共 6 页 - - - - - - - - - MOV DS,AX MOV AH, 0 ;0号功能MOV AL,4 ;显示方式号 4放在;AL 中320*200 四色图形INT 10H ;显示器输出控制中断调用MOV AH,0BH ;置彩色调色板MOV BH,0 MOV BL,1 ;BH=0,BL=4, 背景色为红色INT 10H ;显示器输出控制中断调用MO
18、V AH,0BH MOV BH,01H MOV BL,00 INT 10H ;显示器输出控制中断调用show INFO1 show INFO2 show INFO3 show MUSLIST INPUT: 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 EXIT1 B0: CMP AL,B JNZ C0 LEA SI,MUS_FREG2 LEA BP,DS:MUS_TIME2 CALL MUSIC JMP EXIT1 C0: CMP A
19、L,C JNZ exit LEA SI,MUS_FREG2 LEA BP,DS:MUS_TIME2 CALL MUSIC EXIT1: show INFO5 JMP INPUT EXIT: call clear show INFO4 show INFO5 show INFO1 show INFO2 show INFO3 show MUSLIST jmp input RETU: MOV AH,4CH INT 21H MAIN ENDP MUSIC PROC NEAR FREG1: MOV DI,SI CMP DI,-1 JE END_MUS1 MOV DX,DS:BP MOV BX,1400 C
20、ALL GENSOUND ADD SI,2 ADD BP,2 JMP FREG1 END_MUS1: RET MUSIC ENDP GENSOUND 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 AL,3 OUT 61H,AL WAIT1: MOV CX,8FF0H DELAY1: LOOP DELAY1 DEC BX
21、JNZ WAIT1 MOV AL,AH OUT 61H,AL POP DI POP DX POP CX POP BX POP AX RET GENSOUND ENDP clear 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 ret clear endp CODE ENDS END MAIN = 名师归纳总结 精品学习资料 - - - - - - - - -
22、 - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 4 页,共 6 页 - - - - - - - - - 9. 编写一个通过键盘输入你的名字,然后在屏幕上显示, “hello, 你的名字!”的程序。= DATA SEGMENT BUF DB 30 ACTL DB ? STR DB 30 DUP(?) MESS DB what is your name?,0dh,0ah,$ DMESS DB 0DH,0AH,Hello, $ DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DA TA MAIN P
23、ROC FAR PUSH DS MOV AX,0 PUSH AX MOV AX,DATA MOV DS,AX LEA DX,MESS MOV AH,9 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 RET MAIN ENDP CODE ENDS END MAIN = 11.设在变量 SHUJU
24、 为起始地址的字节存储单元中存放有N个带符号数,编写程序分别统计:(1)正数的个数;(2 ) 负数的个数;(3)零的个数。并显示在屏幕上。= data segment shuju 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,-3 geshu dW $-shuju zheng db 0 fushu db 0 ling db 0 haokan1 db zheng de ge shu:,$ haokan2 db fushu de ge shu:,$ haokan3 db ling de g
25、e shu:,$ huanhang db 0dh,0ah,$ BUF DB 6455412345$ l = $-buf data ends code segment assume cs:code,ds:data KONG PROC PUSH AX PUSH DX mov ah,9 lea dx,HUANHANG int 21h POP DX POP AX RET KONG ENDP start: mov ax,data mov ds,ax lea si,shuju mov cX,geshu NET1: mov al,si test al,0ffh jz zero cmp al,0 jl plu
26、s inc zheng jmp net2 plus: inc fushu jmp net2 zero: inc ling net2: INC SI LOOP NET1 lea dx,haokan1 mov 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 名师归纳总结 精品学习资料 - - - -
27、- - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 5 页,共 6 页 - - - - - - - - - mov ax,4c00h int 21h DISP PROC PUSH SI PUSH AX PUSH BX PUSH DX PUSH CX MOV CX,0 MOV BH,0 CMP BX,0 JNL NEXT1 NEG BX MOV CX,1 NEXT1: LEA SI,BUF+l-1 MOV AX,BX MOV BX,10 NEXT: MOV DX,0 DIV BX ADD DL,30H DEC SI MOV SI,DL CMP AX,0 JNE NEXT CMP CX,0 JE NEXT2 DEC SI MOV BYTE PTR SI,- NEXT2: MOV DX,SI MOV AH,9 INT 21H POP CX POP DX POP BX POP AX POP SI RET DISP ENDP code ends end start 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 6 页,共 6 页 - - - - - - - - -