1、深职院asm课程考试资料/求负 .model small .386 .codestart: mov ax,17eh neg ax mov ax,0 neg ax .exit end start/*while循环* .model small .386 .data kdbbuf byte 33h,38h,32h,0dh temp word ? .stack 20h .code start: mov ax,data mov DS,ax push bx push cx push di ; lea di,kdbbuf mov cx,10 mov bx,0 ;readn: mov al,di .repea
2、t inc di sub al,30h push ax mov ax,bx mul cx mov bx,ax pop ax mov ah,0 add bx,ax mov al,di .until al39h ;readend: mov temp,bx pop di pop cx pop bx nop .exit end start /二进制转换ASCII .model small .386 .data ShuChu byte 10h dup (0) Temp word 17Eh .stack 20h .codeStart: mov ax,data mov DS,ax; mov ax,Temp
3、lea di,ShuChu mov cx,0 mov bx,10 Loop1: mov dx,0 div bx push dx inc cx or ax,ax jnz Loop1; Loop2: pop dx add dl,30h mov di,dl inc di loop Loop2 ; .exit end Start/*显示hello word!按回车退出* .model small .386 .data .stack 10hkeybuf byte h,e,l,l,o,20h,w,o,r,d,! .codestart: mov ax,data mov ds,ax lea di,keybuf
4、WaitInput: mov al,di inc di/显示字符 mov ah,06h mov dl,al int 21h/ cmp al,! jne WaitInputWaitInput2:/读按键 mov ah,06h mov dl,0ffhWaitInput3: int 21h jz WaitInput3/ mov ah,06h mov dl,al int 21h cmp al,0dh je xxx jmp WaitInput2xxx: .exit end start/*声音*880Hz=54B。987.76Hz=4b7。1046.5Hz=474。1174.66Hz=3f7。1318.5
5、1Hz=388。1396.92Hz=356。1567.98Hz=2f8。1760Hz=2a5 .model small .386 .data .stack 10h .codestart: mov al,0b6h out 43h,al mov cx,54bh;/传送 mov al,cl out 42h,al mov al,ch out 42h,al;/打开扬声器 in al,61h or al,3 out 61h,al;/延时 mov ecx,0fffffffhdelay: loopd delay;/关闭扬声器 in al,61h and al,0fch out 61h,al jmp start
6、finished: nop .exit end Start/*从键盘输入两个数,输出相加结果* .model small .386 .stack 10h .datamsg1 byte A,=,0dhmsg2 byte B,=,0dhkeybuf1 byte 10h dup(0)keybuf2 byte 10h dup(0)printbuf byte 10h dup(0)temp1 word ?temp2 word ? .codestart: mov ax,data mov ds,ax;=显示msg1 A= lea si,msg1shownext: mov dl,si cmp dl,0dh je
7、 inputdata mov ah,06h int 21h inc si jmp shownext;=输入数据,显示数据,保存=inputdata: lea di,keybuf1inputnext:;输入; mov ah,06h mov dl,0ffhwaitinput: int 21h jz waitinput cmp al,0dh je inputend;显示; mov dl,al int 21h;保存; mov di,al inc di jmp inputnextinputend: mov di,al;=转换二进制= lea di,keybuf1 mov cx,10 mov bx,0 r
8、eadn: mov al,di inc di cmp al,30h jb readend cmp al,39h ja readend sub al,30h push ax mov ax,bx mul cx mov bx,ax pop ax mov ah,0 add bx,ax jmp readn ;readend: mov temp1,bx ;=回车换行= mov ah,06h mov dl,0dh int 21h mov dl,0ah int 21h;=显示msg2 B= lea si,msg2shownext2: mov dl,si cmp dl,0dh je inputdata2 mov
9、 ah,06h int 21h inc si jmp shownext2;=输入数据,显示数据,保存=inputdata2: lea di,keybuf2inputnext2:;输入; mov ah,06h mov dl,0ffhwaitinput2: int 21h jz waitinput2 cmp al,0dh je inputend2;显示; mov dl,al int 21h;保存; mov di,al inc di jmp inputnext2inputend2: mov di,al;=转换二进制= lea di,keybuf2 mov cx,10 mov bx,0 readn2:
10、 mov al,di inc di cmp al,30h jb readend2 cmp al,39h ja readend2 sub al,30h push ax mov ax,bx mul cx mov bx,ax pop ax mov ah,0 add bx,ax jmp readn2 ;readend2: mov temp2,bx ;=回车换行= mov ah,06h mov dl,0dh int 21h mov dl,0ah int 21h ;=相加= mov ax,temp1 mov bx,temp2 add ax,bx ;=二进制转十六进制= lea di,printbuf mo
11、v cx,0 mov bx,10 ;writen1: mov dx,0 div bx push dx inc cx or ax,ax jnz writen1 ;writen2: pop dx add dl,30h mov di,dl inc di loop writen2 mov byte ptrdi,0dh;=显示结果 lea si,printbufshownext3: mov dl,si cmp dl,0dh je Jieshu mov ah,06h int 21h inc si jmp shownext3;Jieshu: nop .exit end Start/*从CMOS读 年 月 日
12、,显示* .model small .386 .stack 10haddrport equ 70hdataport equ 71h .datadate byte 00h,00h,00hdatebuf byte 00h,00h,-,00h,00h,-,00h,00h,0dh .codestart: mov ax,data mov ds,ax;=将年月日读到date= mov cx,3 lea si,date in al,addrport and al,80h add al,9readcoms: out addrport,al;=延时= push cx mov cx,0ffhdelay: loop
13、 delay pop cx;=从dataport读数据到al= push ax in al,dataport mov si,al pop ax dec al inc si loop readcoms;=将date的BCD码转为ASCII码,存入datebuf= mov cx,3 lea si,date lea di,datebufbcd2asc:;=BCD转ASCII= mov al,si mov ah,si shr al,4 and al,0fh and ah,0fh add al,30h add ah,30h mov di,al inc di mov di,ah inc si inc di
14、 inc di loop bcd2asc;=显示datebuf= lea si,datebufshownext: mov dl,si cmp dl,0dh je jieshu mov ah,06h int 21h inc si jmp shownext;=等待按键结束= mov dl,0ffh mov ah,06hwaitinput: int 21h jz waitinputjieshu: .exit end start /*连加*从1加到10= .model small .386 .datatemp word ? .stack 10h .codemain proc far mov ax,da
15、ta mov ds,ax mov cx,10 mov ax,0 call lianjia .exitmain endplianjia proc near add ax,cx loop lianjia mov temp,bx retlianjia endp end main/*IF语句*;判断键盘输入为1.2.3.4分别传送A,B,C,D.用高级语言 .model small .386 .stack 10h .codestart: mov ax,data mov ds,ax mov dl,0ffh mov ah,06hwaitinput: int 21h jz waitinput.IF al=1
16、 mov ah,A.ELSEIF al=2 mov ah,B.ELSEIF al=3 mov ah,C.ELSEIF al=4 mov ah,D.ELSE mov ah,E.ENDIF .exit end start /*子程序调用IF HELLO WORD*;子程序调用 .IF .ELSEIF .ELSE .ENDIF 显示shownext .model small .386 .stack 10h .datamsg1 byte H,E,L,L,O, ,W,O,R,L,D,0dh .codemain proc far mov ax,data mov ds,ax lea si,msg1 call
17、 showmsg nop .exitmain endpshowmsg proc near uses si dx axshownext: mov dl,si.IF dl!=0dh mov ah,06h int 21h inc si jmp shownext.ELSE ret.ENDIFshowmsg endp .exit end main/*.IF.ELSEIF .ELSE ENDIF 转换2bin;1-8用子函数,.IF .ELSEIF .ELSE .ENDIF ASCII转换2bin .model small .386 .datakeybuf byte 33h,38h,32h,0dhtemp
18、 word ? .stack 30h .codemain proc far mov ax,data mov ds,ax lea di,keybuf call bin2asciimain endpbin2ascii proc near uses ax bx cx mov bx,0 mov cx,10DuShu: mov al,di ;di放入ax低8位 inc di.IF al=39h mov temp,bx ret.ELSEIF al=30h mov temp,bx ret.ENDIF sub al,30h push ax mov ax,bx mul cx ;ax=ax*cx mov bx,a
19、x pop ax mov ah,0 add bx,ax jmp DuShu retbin2ascii endp end main;*从1加到10* .model small .386 .datatemp word ? .stack 10h .codestart: mov ax,data mov ds,ax mov cx,0 mov ax,0 .while cx=10 add ax,cx inc cx .endw .exitend start*.break .continue* .model small .386 .data databuf byte 13h,12h,#,02h,#,19h,0d
20、h .stack 20h .code start: mov ax,data mov DS,ax lea di,databuf mov bx,0 .while 1 mov al,di inc di .break .if al=0dh .continue .if al=# mov ah,0 add bx,ax .endw nop .exit end start /*模块汇编*/c+#include stdafx.h#include iostreamusing namespace std;extern C void decitohexa(int,char *);char buffer35 = Ent
21、er a number between 0 and 9999:;char hexanum5;int decinum=0;void main(void) coutbufferdecinum; coutendl; decitohexa(decinum,hexanum); coutthe hexadecimal value of decinum is ; couthexanum; coutnendl;/asm文件 .386 .model flat,c .stack 1024 .code public decitohexa decitohexa proc c uses eax edi ecx edx
22、decidata,hexadata:ptr xor eax,eax mov eax,decidata shl eax,16 mov edi,hexadata mov ecx,4next: mov edx,eax shl eax,4 rol edx,4 and dl,0fh add dl,30h cmp dl,39h jbe storeasc add dl,7storeasc: mov edi,dl inc edi loop next mov byte ptr edi,0 retdecitohexa endp end/*内嵌汇编*/ xm12_4.cpp : Defines the entry
23、point for the console application./#include stdafx.h#include iostreamusing namespace std;char buffer35 = Enter a number between 0 and 9999:;char hexanum5;int decinum=0;void decitohexa(int decidata,char *hexadata) _asm xor eax,eax mov eax,decidata shl eax,16 mov edi,hexadata mov ecx,4next: mov edx,ea
24、x shl eax,4 rol edx,4 and dl,0fh add dl,30h cmp dl,39h jbe storeasc add dl,7storeasc: mov edi,dl inc edi loop next mov byte ptr edi,0 void main(void) coutbufferdecinum; coutendl; decitohexa(decinum,hexanum); coutthe hexadecimal value of decinum is ; couthexanum; coutnendl;/*模块汇编*加法* .model small .38
25、6 .stack 20h .data msg1 byte A,=,0dh msg2 byte B,=,0dh msg3 byte A,+,B,=,0dh data1ascii byte 6 dup(0) data2ascii byte 6 dup(0) data1 word 0 data2 word 0 data3 word 0 sum byte 6 dup(0) .codeMain proc far mov ax,data mov ds,axnext: call return ;调用回车换行子过程 lea si,msg1 call showmsg ;调用显示信息的子过程showmsg显示“A=” lea di,data1ascii call input ;调用键盘输
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1