当前位置:文档之家› 24个汇编实例小程序文件

24个汇编实例小程序文件

24个汇编小程序题目列表:逆序输出字符串“BASED ADDRESSING”从键盘上输入两个数,分别放到x,y单元,求出它们的和试编写一段程序,要求在长度为10h的数组中,找出大于42h的无符号数的个数并存入地址为up开始区域,找出小于42h的无符号数的个数并存入地址为down的开始区域键盘输入一段字符串,其中小写字母以大写字母输出,其他字符不变输出从键盘上就收一个小写字母,找出它的前导字符和后续字符,在顺序显示这三个字符把一个包含20个数据的数组M分成两组:正整数组P和负整数组N,分别把这两个数组中的数据的个数显示出来求出首地址为data的100个字数组中的最小偶数,并把它放在ax中输入两船字符串string1和string2,并比较两个字符串是否相等,相等就显示“match”,否则显示“no match”从键盘接收一个四位的十六进制数,并在终端显示与它等值的二进制数从键盘输入一系列以$为结束符的字符串,然后对其中的非数字字符计数,并显示计数结果有一个首地址为mem的100个字的数组,试编程序删除数组中所有为零的项,并将后续项向前压缩,最后将数组的剩余部分补上零从键盘上输入一串字符(用回车键结束,使用10号功能调用)放在string中,是编制一个程序测试字符串中是否存在数字。

如有,则把cl的第五位置1,否则将该位置置0在首地址为data的字数组中,存放了100h的16位字数据,试编写一个程序,求出平均值放在ax寄存器中,并求出数组中有多少个数小于此平均值,将结果放在bx寄存器中(f分别考虑有符号数、无符号数情况)一直数组A包含15个互不相等的整数,数组B包含20个互不相等的整数。

试编制一个程序,把既在A中又在B中出现的整数存放于数组C中设在A、B和D单元中分别存放着三个数。

若三个数都不是0,则求出三个数的和并存放在S 单元,若其中有一个数为0,则把其它两个单元也清零。

请编写此程序从键盘输入一系列字符(以回车键结束),并按字母、数字和其他字符分类计数,最后显示这三类的计数结果已定义两个整数变量A和B,试编写程序完成以下功能(1)若两个树种有一个是奇数,则将奇数存入A中,偶数存入B中(2)若两个数均为奇数,则将两个数加1后存回原变量(3)若两个数均为偶数,则两个变量均不变写一段子程序skiplines,完成输出空行的功能。

空行的行数由用户在主程序过键盘输入,并将行数放在ax寄存器中设有10个学生成绩分别是76, 69,84,73,88,99,63,100和80。

试编写一个子程序统计60-69分,70-79分,80-89分,90-99分和100分的人数,并分别放到S6,S7,S8,S9,S10单元中编写子程序嵌套结构的程序,把整数分别用二进制和八进制显示出来在D盘根目录建立一个文件abc.txt,第一次向文件写入“123456”六个字符,第二次增加“abcdefg”几个字符从键盘上输入文本文件:“d:\temp.txt”的容后,然后新建一个文件“d:\temp2.txt”,把前一个文件的所有容复制到后一个文件中从键盘上输入一个十进制数,以十六进制数显示出来。

要求子程序用寄存器参数传送方法试编制一个程序,把bx寄存器中的二进制数用十六进制数的形式在屏幕上显示出来代码:1.逆序输出字符串“BASED ADDRESSING”s1 segment stack ;定义栈段s1dw 100 dup(?) ;定义栈空间为100top label word ;top指向栈顶s1 endss2 segment ;定义数据段s2s db 'BASED ADDRESSING','$' ;定义字符串sS2 endss3 segment ;定义代码段s3assume cs:s3,ds:s2,ss:s1main proc farmov ax,s1 ;栈初始化——mov ss,axlea sp,top ;——栈初始化mov ax,s2 ;数据段初始化——mov ds,ax ;——数据段初始化mov si,15l: mov dl,s[si] ;dl获取字符串s的最后一个(从零开始的第十五个字符) mov ah,2 ;调用int 21h 2号功能输出dl上的值int 21hdec si ;寄存器减一,准备获取下一个字符cmp si,0ja lmov ah,4ch ;终止int 21hmain endps3 endsend main2.从键盘上输入两个数,分别放到x,y单元,求出它们的和s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'Please input x:','$' ;提示输入h2 db 'Please input y:','$' ;提示输入h3 db 'z=x+y:','$' ;提示输出crlf db 0dh,0ah,24h ;定义回车换行x dw ?y dw ?s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1 ;初始化——mov ss,axlea sp,topmov ax,s2mov ds,ax ;——初始化lea dx,h1 ;int 21h 9号功能输出“提示输入x”的字符串mov ah,9int 21hxor bx,bx ;bx清零,即把bx置零InputX:mov ah,1 ;输入一个字符int 21hcmp al,0dh ;判断时候为“回车”字符jz exit1 ;如果是回车字符就跳转到exit1cmp al,30h ;和30h(即字符0的asii值)比较jl exit1 ;如果输入字符小于'0',跳转到exit1cmp al,39h ;和39h(即字符9的ascii值)比较jg exit1 ;如果输入字符大于'9',跳转到exit1sub al,30h ;al减去30h,输入字符转化成数字(从这一行开始到后面的add bx,ax为输入字符转化为数字的处理方法)cbw ;al扩充为axxchg ax,bxmov cx,10mul cxxchg ax,bxadd bx,ax ;sub al,30h开始到这一行为输入字符转化为数字的处理方法jmp InputXexit1: mov x,bx ;把输入的存于bx的放到x中lea dx,crlfmov ah,9int 21hlea dx,h2mov ah,9int 21hxor bx,bxInputY: ;和InputX类似,输入ymov ah,1int 21hcmp al,0dhjz exit2cmp al,30hjl exit2cmp al,39hjg exit2sub al,30hcbwxchg ax,bxmov cx,10mul cxxchg ax,bxadd bx,axjmp InputYexit2: mov y,bx ;把输入的存于bx的放到y中mov bx,xadd bx,y ;此时bx为两数加和lea dx,crlfmov ah,9int 21Hlea dx,h3mov ah,9int 21hxor si,si ;si清零,用作计数mov ax,bx ;把和放到ax上l4: mov cl,10 ;把和连续除以10知道和变为零,余数依次进栈 div clmov dl,ahmov dh,0push dxinc simov ah,0 ;重要,不能漏写cmp al,0jnz l4l5: pop dx ;余数依次出栈add dl,30h ;余数转换为显示的余数字符mov ah,2 ;输入余数字符int 21hdec sicmp si,0jnz l5mov ah,4chmain endps3 endsend main3.是编写一段程序,要求在长度为10的数组中,找出大于42h的无符号数的个数并存入地址为up开始区域,找出小于42h的无符号数的个数并存入地址为down的开始区域,并分别显示up、down数组的个数和数组的数字s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'the num of up array and the up array are(prints in decimalism) :','$' h2 db 'the num of down array and the down array are(prints in decimalism) :','$' crlf db 0dh,0ah,24harray db 0,50h,11h,61h,22h,72h,33h,73h,41h,74h,'$' ;定义数组arrayup db 10 dup(?) ;定义up数组down db 10 dup(?) ;定义down数组s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axmov si,0mov di,1mov bp,1repeat: cmp array[si],42h ;把array数组中小于42h的值放到down数组里,大于42h的值放到up数组里面jb downarraymov dl,array[si]mov up[bp],dlinc sicmp si,10inc bpjmp repeatdownarray:mov dl,array[si]mov down[di],dlinc sicmp si,10jz exit2inc dijmp repeatexit1: sub di,1jmp exitexit2: sub bp,1exit: mov dx,bp ;把分配好的up数组和down数组在其有效数字后面添加'$',便于后面的输出结束mov up[0],dlinc bpmov up[bp],'$'mov dx,dimov down[0],dlinc dimov down[di],'$'mov cl,10mov si,0lea dx,h1mov ah,9int 21hPrintUparray:cmp up[si],'$'jz nextmov al,up[si]call printinc sijmp PrintUparraynext:lea dx,crlfmov ah,9int 21hlea dx,h2int 21hxor si,siPrintDownArray:cmp down[si],'$'jz atendmov al,down[si]call printinc sijmp PrintDownArrayprint proc near ;print为输出十进制输出某个数的子程序 mov di,0rediv: mov ah,0div clmov dl,ahmov dh,0push dxinc dicmp al,0jnz redivbreak: pop dxadd dl,30hmov ah,2int 21hdec dicmp di,0jnz breakmov dl,' 'mov ah,2int 21Hretprint endpatend: mov ah,4chint 21Hmain endps3 endsend main4.键盘输入一段字符串,其中小写字母以大写字母输出,其他字符不变输出s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'Please input a string:','$'h2 db 'The changed string is:','$'crlf db 0dh,0ah,24htemp db ?s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axlea dx,h1mov ah,9int 21hmov si,0l: mov ah,1int 21hcmp al,0dhjz exitcmp al,'a'jl putincmp al,'z'jg putinsub al,20h ;把小写字符变为大写字符putin: mov temp[si],al ;把字符放到temp数组里inc sijmp lexit: lea dx,crlf ;输出tmp数组mov ah,9int 21hlea dx,h2mov ah,9int 21hinc simov temp[si],'$'lea dx,tempmov ah,9int 21hmov ah,4chint 21Hmain endps3 endsend main5.从键盘上就收一个小写字母,找出它的前导字符和后续字符,在顺序显示这三个字符s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'Please input a lowercase: ','$'h2 db 'The the three chars are: ','$'crlf db 0dh,0ah,24hs2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axl: lea dx,h1mov ah,9int 21hmov ah,1int 21hcmp al,'a'jl lcmp al,'z'jg lmov cl,allea dx,crlfmov ah,9int 21Hlea dx,h2mov ah,9int 21hdec clmov dl,cl ;输出前导字符 mov ah,2int 21hmov dl,' 'mov ah,2int 21hinc clmov dl,cl ;输出该字符mov ah,2int 21hmov dl,' 'mov ah,2int 21hinc clmov dl,cl ;输出后导字符 mov ah,2int 21hmov ah,4chint 21Hmain endps3 endsend main6.把一个包含20个数据的数组M分成两组:正整数组P和负整数组N,分别把这两个数组中的数据的个数显示出来s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'the positive number is: ','$'h2 db 'the negative number is: ','$'crlf db 0dh,0ah,24harray dw 50h,-11h,61h,-22h,72h,-33h,73h,-41h,74h,21h,67h,-90h,73h,77h,-1h,-89h,-11h,61h,-22h,20h,'$'s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axmov bx,0mov si,0l: mov dx,array[si]cmp dx,0jl addlow ;有符号数比较用jladd si,2cmp si,40jz exitjmp laddlow: inc bxadd si,2cmp si,40jz exitjmp lmov ah,9int 21hmov ax,bxcall printlea dx,crlfmov ah,9int 21hlea dx,h1mov ah,9int 21hmov ax,20sub ax,bxcall printjmp atendprint proc near ;打印数字字符的子程序mov cl,10mov si,0repeat: div clmov dl,ahadd dl,30hmov dh,0push dxinc simov ah,0cmp al,0jnz repeatl2: pop dxmov ah,2int 21hdec sicmp si,0jnz l2retprint endpint 21Hmain endps3 endsend main7.打印输出首地址为data的20个字数组中的最小偶数s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'the min even number is: ','$'crlf db 0dh,0ah,24hdata dw 50,-11,61,-22,72,-33,73,-41,74,21,67,-90,73,77,-1,-89,-11,61,-22,20,'$'s2 endss3 segmentassume cs:s3,ds:s2,ss:s1main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axmov bx,65534 ;bx存最小数,初始令最小值置为65534mov si,0mov cl,100mov dl,2l2: mov ax,data[si]cmp ax,0jnl l4neg ax ;如果是负数,则求补l4: div clmov al,ahmov ah,0div dlcmp ah,0jnz l1cmp bx,data[si] ;比较最小值和数组中的每个数jl l1 ;如果数组中的数大于最小值跳转到l1mov bx,data[si] ;如果数组中的数小于最小值则将其赋给最小值l1: add si,2cmp si,40jz exitjmp l2exit: lea dx,h1mov ah,9int 21hcmp bx,0jnl l5neg bxmov dl,'-'mov ah,2int 21hl5: mov ax,bxcall print ;调用子程序输出最小值jmp atendprint proc nearmov cl,10mov si,0repeat: div clmov dl,ahadd dl,30hmov dh,0push dxinc simov ah,0cmp al,0jnz repeatl3: pop dxmov ah,2int 21hdec sicmp si,0jnz l3retprint endpatend: mov ah,4chint 21Hmain endps3 endsend main8.输入两船字符串string1和string2,并比较两个字符串是否相等,相等就显示“match”,否则显示“no match”s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'Please input the first string: ','$'h2 db 'Please input the second string: ','$'h3 db 'MATCH','$'h4 db 'NO MATCH','$'crlf db 0dh,0ah,24hstr1 db 50,?,50 dup('$')str2 db 50,?,50 dup('$')s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axlea dx,h1mov ah,9int 21hlea dx,str1mov ah,0ahint 21hlea dx,crlfmov ah,9int 21hlea dx,h2int 21hlea dx,str2mov ah,0ahint 21hlea dx,crlfmov ah,9int 21hmov dl,str1+1 ;str1+1为str1实际的字符个数 cmp dl,str2+1 ;str2+1为str2实际的字符个数 jnz lmov si,2l2: mov dl,str1[si]cmp dl,str2[si]jnz linc sicmp si,50jz l3jmp l2l: lea dx,h4 ;输出不匹配信息mov ah,9int 21hl3: lea dx,h3 ;输出匹配信息mov ah,9int 21hmov ah,4chint 21Hmain endps3 endsend main9.从键盘接收一个四位的十六进制数,并在终端显示与它等值的二进制数s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'Please input a hexadecimal number: ','$'h2 db 'The number is printed in binary number: ','$' temp db 17 dup('$')crlf db 0dh,0ah,24hs2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axrepeat: lea dx,h1mov ah,9int 21hmov bx,0mov cx,4newchar: ;接收新字符mov ah,1int 21hcmp al,30hjb repeatcmp al,46hjg repeatcmp al,39hjnb l1 ;如果输入字符大于9跳到l1sub al,30hjmp l2l1: cmp al,41hjb repeat ;如果输入字符小于A,则输入错误,跳到repeat sub al,37h ;输入字符为A~Z,故相应地要减37hjmp l2l2: cbw ;l2为把输入字符转化为数值xchg ax,bxmov dx,10hmul dxxchg ax,bxadd bx,ax;loop newchardec cxcmp cx,0jnz newcharlea dx,crlfmov ah,9int 21hlea dx,h2int 21hmov si,0mov cx,10h ;cx作计数器,即待会要循环16次l5: rol bx,1 ;bx循环左移以为,最高位进标志位jc l3 ;若标志位为1则跳转到l3mov temp[si],'0'jmp l4l3: mov temp[si],'1'l4: inc siloop l5lea dx,tempmov ah,9int 21hmov ah,4chint 21Hmain endps3 endsend main10从键盘输入一系列以$为结束符的字符串,然后对其中的非数字字符计数,并显示计数结果s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db 'Please input a string: ','$'h2 db 'The number of the chars that is not digit:','$'crlf db 0dh,0ah,24hs2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axlea dx,h1mov ah,9int 21hmov cx,0l2: mov ah,1int 21hcmp al,'$'jz exitcmp al,30hjb lcmp al,39hjnb ljmp l2l: inc cxjmp l2exit: lea dx,crlfmov ah,9int 21hlea dx,h2int 21hmov si,0mov bl,10mov ax,cxl4: div blmov dl,ahmov dh,0push dxinc simov ah,0cmp al,0jnz l4l5: pop dxadd dl,30hmov ah,2int 21hdec sicmp si,0jnz l5mov ah,4chint 21Hmain endps3 endsend main11.有一个首地址为mem的10个字的数组,试编程序删除数组中所有为零的项,并将后续项向前压缩,最后将数组的剩余部分补上零s1 segment stackdw 100h dup(?)top label words1 endss2 segmentmem dw 0,1,0,3,0,0,4,5,6,0,'$'crlf db 0dh,0ah,24hs2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axmov si,0mov di,2repeat: cmp di,20jz exitmov bx,mem[si]mov dx,mem[di]cmp bx,0jnz nextxchg bx,dxmov mem[si],bxmov mem[di],dxnext: cmp mem[si],0jz ladd si,2l: add di,2jmp repeatexit: mov ah,4chint 21Hmain endps3 endsend main;以下是该算法描述;定义两个指针,当前指针si和检查指针di,先把si指针指向第一个字得到的值bx,;di指向第二个字得到的值dx。

相关主题