首页 24个汇编实例小程序

24个汇编实例小程序

举报
开通vip

24个汇编实例小程序24个汇编小程序 题目列表: 逆序输出字符串“BASED ADDRESSING” 从键盘上输入两个数,分别放到x,y单元,求出它们的和 是编写一段程序,要求在长度为10h的数组中,找出大于42h的无符号数的个数并存入地址为up开始区域,找出小于42h的无符号数的个数并存入地址为down的开始区域 键盘输入一段字符串,其中小写字母以大写字母输出,其他字符不变输出 从键盘上就收一个小写字母,找出它的前导字符和后续字符,在顺序显示这三个字符 把一个包含20个数据的数组M分成两组:正整数组P和负整数组N,分别...

24个汇编实例小程序
24个汇编小程序 题目列 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf : 逆序输出字符串“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,试编写程序完成以下功能 若两个树种有一个是奇数,则将奇数存入A中,偶数存入B中 若两个数均为奇数,则将两个数加1后存回原变量 若两个数均为偶数,则两个变量均不变 写一段子程序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 ;定义栈段s1 dw 100 dup(?) ;定义栈空间为100 top label word ;top指向栈顶 s1 ends s2 segment ;定义数据段s2 s db 'BASED ADDRESSING','$' ;定义字符串s S2 ends s3 segment ;定义代码段s3 assume cs:s3,ds:s2,ss:s1 main proc far mov ax,s1 ;栈初始化—— mov ss,ax lea sp,top ;——栈初始化 mov ax,s2 ;数据段初始化—— mov ds,ax ;——数据段初始化 mov si,15 l: mov dl,s[si] ;dl获取字符串s的最后一个(从零开始的第十五个字符) mov ah,2 ;调用int 21h 2号功能输出dl上的值 int 21h dec si ;寄存器减一,准备获取下一个字符 cmp si,0 ja l mov ah,4ch ;终止 int 21h main endp s3 ends end main 2.从键盘上输入两个数,分别放到x,y单元,求出它们的和 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'Please input x:','$' ;提示输入 h2 db 'Please input y:','$' ;提示输入 h3 db 'z=x+y:','$' ;提示输出 crlf db 0dh,0ah,24h ;定义回车换行 x dw ? y dw ? s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 ;初始化—— mov ss,ax lea sp,top mov ax,s2 mov ds,ax ;——初始化 lea dx,h1 ;int 21h 9号功能输出“提示输入x”的字符串 mov ah,9 int 21h xor bx,bx ;bx清零,即把bx置零 InputX: mov ah,1 ;输入一个字符 int 21h cmp al,0dh ;判断时候为“回车”字符 jz exit1 ;如果是回车字符就跳转到exit1 cmp al,30h ;和30h(即字符0的asii值)比较 jl exit1 ;如果输入字符小于'0',跳转到exit1 cmp al,39h ;和39h(即字符9的ascii值)比较 jg exit1 ;如果输入字符大于'9',跳转到exit1 sub al,30h ;al减去30h,输入字符转化成数字(从这一行开始到后面的add bx,ax为输入字符转化为数字的处理方法) cbw ;al扩充为ax xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax ;sub al,30h开始到这一行为输入字符转化为数字的处理方法 jmp InputX exit1: mov x,bx ;把输入的存于bx的放到x中 lea dx,crlf mov ah,9 int 21h lea dx,h2 mov ah,9 int 21h xor bx,bx InputY: ;和InputX类似,输入y mov ah,1 int 21h cmp al,0dh jz exit2 cmp al,30h jl exit2 cmp al,39h jg exit2 sub al,30h cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp InputY exit2: mov y,bx ;把输入的存于bx的放到y中 mov bx,x add bx,y ;此时bx为两数加和 lea dx,crlf mov ah,9 int 21H lea dx,h3 mov ah,9 int 21h xor si,si ;si清零,用作计数 mov ax,bx ;把和放到ax上 l4: mov cl,10 ;把和连续除以10知道和变为零,余数依次进栈 div cl mov dl,ah mov dh,0 push dx inc si mov ah,0 ;重要,不能漏写 cmp al,0 jnz l4 l5: pop dx ;余数依次出栈 add dl,30h ;余数转换为显示的余数字符 mov ah,2 ;输入余数字符 int 21h dec si cmp si,0 jnz l5 mov ah,4ch int 21H main endp s3 ends end main 3.是编写一段程序,要求在长度为10的数组中,找出大于42h的无符号数的个数并存入地址为up开始区域,找出小于42h的无符号数的个数并存入地址为down的开始区域,并分别显示up、down数组的个数和数组内的数字 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 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,24h array db 0,50h,11h,61h,22h,72h,33h,73h,41h,74h,'$' ;定义数组array up db 10 dup(?) ;定义up数组 down db 10 dup(?) ;定义down数组 s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov si,0 mov di,1 mov bp,1 repeat: cmp array[si],42h ;把array数组中小于42h的值放到down数组里,大于42h的值放到up数组里面 jb downarray mov dl,array[si] mov up[bp],dl inc si cmp si,10 jz exit1 inc bp jmp repeat downarray: mov dl,array[si] mov down[di],dl inc si cmp si,10 jz exit2 inc di jmp repeat exit1: sub di,1 jmp exit exit2: sub bp,1 exit: mov dx,bp ;把分配好的up数组和down数组在其有效数字后面添加'$',便于后面的输出结束 mov up[0],dl inc bp mov up[bp],'$' mov dx,di mov down[0],dl inc di mov down[di],'$' mov cl,10 mov si,0 lea dx,h1 mov ah,9 int 21h PrintUparray: cmp up[si],'$' jz next mov al,up[si] call print inc si jmp PrintUparray next: lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h xor si,si PrintDownArray: cmp down[si],'$' jz atend mov al,down[si] call print inc si jmp PrintDownArray print proc near ;print为输出十进制输出某个数的子程序 mov di,0 rediv: mov ah,0 div cl mov dl,ah mov dh,0 push dx inc di cmp al,0 jnz rediv break: pop dx add dl,30h mov ah,2 int 21h dec di cmp di,0 jnz break mov dl,' ' mov ah,2 int 21H ret print endp atend: mov ah,4ch int 21H main endp s3 ends end main 4.键盘输入一段字符串,其中小写字母以大写字母输出,其他字符不变输出 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'Please input a string:','$' h2 db 'The changed string is:','$' crlf db 0dh,0ah,24h temp db ? s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax lea dx,h1 mov ah,9 int 21h mov si,0 l: mov ah,1 int 21h cmp al,0dh jz exit cmp al,'a' jl putin cmp al,'z' jg putin sub al,20h ;把小写字符变为大写字符 putin: mov temp[si],al ;把字符放到temp数组里 inc si jmp l exit: lea dx,crlf ;输出tmp数组 mov ah,9 int 21h lea dx,h2 mov ah,9 int 21h inc si mov temp[si],'$' lea dx,temp mov ah,9 int 21h mov ah,4ch int 21H main endp s3 ends end main 5.从键盘上就收一个小写字母,找出它的前导字符和后续字符,在顺序显示这三个字符 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'Please input a lowercase: ','$' h2 db 'The the three chars are: ','$' crlf db 0dh,0ah,24h s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax l: lea dx,h1 mov ah,9 int 21h mov ah,1 int 21h cmp al,'a' jl l cmp al,'z' jg l mov cl,al lea dx,crlf mov ah,9 int 21H lea dx,h2 mov ah,9 int 21h dec cl mov dl,cl ;输出前导字符 mov ah,2 int 21h mov dl,' ' mov ah,2 int 21h inc cl mov dl,cl ;输出该字符 mov ah,2 int 21h mov dl,' ' mov ah,2 int 21h inc cl mov dl,cl ;输出后导字符 mov ah,2 int 21h mov ah,4ch int 21H main endp s3 ends end main 6.把一个包含20个数据的数组M分成两组:正整数组P和负整数组N,分别把这两个数组中的数据的个数显示出来 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'the positive number is: ','$' h2 db 'the negative number is: ','$' crlf db 0dh,0ah,24h array dw 50h,-11h,61h,-22h,72h,-33h,73h,-41h,74h,21h,67h,-90h,73h,77h,-1h,-89h,-11h,61h,-22h,20h,'$' s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov bx,0 mov si,0 l: mov dx,array[si] cmp dx,0 jl addlow ;有符号数比较用jl add si,2 cmp si,40 jz exit jmp l addlow: inc bx add si,2 cmp si,40 jz exit jmp l exit: lea dx,h2 mov ah,9 int 21h mov ax,bx call print lea dx,crlf mov ah,9 int 21h lea dx,h1 mov ah,9 int 21h mov ax,20 sub ax,bx call print jmp atend print proc near ;打印数字字符的子程序 mov cl,10 mov si,0 repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeat l2: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l2 ret print endp atend: mov ah,4ch int 21H main endp s3 ends end main 7.打印输出首地址为data的20个字数组中的最小偶数 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'the min even number is: ','$' crlf db 0dh,0ah,24h data dw 50,-11,61,-22,72,-33,73,-41,74,21,67,-90,73,77,-1,-89,-11,61,-22,20,'$' s2 ends s3 segment assume cs:s3,ds:s2,ss:s1 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov bx,65534 ;bx存最小数,初始令最小值置为65534 mov si,0 mov cl,100 mov dl,2 l2: mov ax,data[si] cmp ax,0 jnl l4 neg ax ;如果是负数,则求补 l4: div cl mov al,ah mov ah,0 div dl cmp ah,0 jnz l1 cmp bx,data[si] ;比较最小值和数组中的每个数 jl l1 ;如果数组中的数大于最小值跳转到l1 mov bx,data[si] ;如果数组中的数小于最小值则将其赋给最小值 l1: add si,2 cmp si,40 jz exit jmp l2 exit: lea dx,h1 mov ah,9 int 21h cmp bx,0 jnl l5 neg bx mov dl,'-' mov ah,2 int 21h l5: mov ax,bx call print ;调用子程序输出最小值 jmp atend print proc near mov cl,10 mov si,0 repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeat l3: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l3 ret print endp atend: mov ah,4ch int 21H main endp s3 ends end main 8.输入两船字符串string1和string2,并比较两个字符串是否相等,相等就显示“match”,否则显示“no match” s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'Please input the first string: ','$' h2 db 'Please input the second string: ','$' h3 db 'MATCH','$' h4 db 'NO MATCH','$' crlf db 0dh,0ah,24h str1 db 50,?,50 dup('$') str2 db 50,?,50 dup('$') s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax lea dx,h1 mov ah,9 int 21h lea dx,str1 mov ah,0ah int 21h lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h lea dx,str2 mov ah,0ah int 21h lea dx,crlf mov ah,9 int 21h mov dl,str1+1 ;str1+1为str1实际的字符个数 cmp dl,str2+1 ;str2+1为str2实际的字符个数 jnz l mov si,2 l2: mov dl,str1[si] cmp dl,str2[si] jnz l inc si cmp si,50 jz l3 jmp l2 l: lea dx,h4 ;输出不匹配信息 mov ah,9 int 21h l3: lea dx,h3 ;输出匹配信息 mov ah,9 int 21h mov ah,4ch int 21H main endp s3 ends end main 9.从键盘接收一个四位的十六进制数,并在终端显示与它等值的二进制数 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'Please input a hexadecimal number: ','$' h2 db 'The number is printed in binary number: ','$' temp db 17 dup('$') crlf db 0dh,0ah,24h s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax repeat: lea dx,h1 mov ah,9 int 21h mov bx,0 mov cx,4 newchar: ;接收新字符 mov ah,1 int 21h cmp al,30h jb repeat cmp al,46h jg repeat cmp al,39h jnb l1 ;如果输入字符大于9跳到l1 sub al,30h jmp l2 l1: cmp al,41h jb repeat ;如果输入字符小于A,则输入错误,跳到repeat sub al,37h ;输入字符为A~Z,故相应地要减37h jmp l2 l2: cbw ;l2为把输入字符转化为数值 xchg ax,bx mov dx,10h mul dx xchg ax,bx add bx,ax ;loop newchar dec cx cmp cx,0 jnz newchar lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h mov si,0 mov cx,10h ;cx作计数器,即待会要循环16次 l5: rol bx,1 ;bx循环左移以为,最高位进标志位 jc l3 ;若标志位为1则跳转到l3 mov temp[si],'0' jmp l4 l3: mov temp[si],'1' l4: inc si loop l5 lea dx,temp mov ah,9 int 21h mov ah,4ch int 21H main endp s3 ends end main 10从键盘输入一系列以$为结束符的字符串,然后对其中的非数字字符计数,并显示计数结果 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'Please input a string: ','$' h2 db 'The number of the chars that is not digit:','$' crlf db 0dh,0ah,24h s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax lea dx,h1 mov ah,9 int 21h mov cx,0 l2: mov ah,1 int 21h cmp al,'$' jz exit cmp al,30h jb l cmp al,39h jnb l jmp l2 l: inc cx jmp l2 exit: lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h mov si,0 mov bl,10 mov ax,cx l4: div bl mov dl,ah mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz l4 l5: pop dx add dl,30h mov ah,2 int 21h dec si cmp si,0 jnz l5 mov ah,4ch int 21H main endp s3 ends end main 11.有一个首地址为mem的10个字的数组,试编程序删除数组中所有为零的项,并将后续项向前压缩,最后将数组的剩余部分补上零 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment mem dw 0,1,0,3,0,0,4,5,6,0,'$' crlf db 0dh,0ah,24h s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov si,0 mov di,2 repeat: cmp di,20 jz exit mov bx,mem[si] mov dx,mem[di] cmp bx,0 jnz next xchg bx,dx mov mem[si],bx mov mem[di],dx next: cmp mem[si],0 jz l add si,2 l: add di,2 jmp repeat exit: mov ah,4ch int 21H main endp s3 ends end main ;以下是该算法描述 ;定义两个指针,当前指针si和检查指针di,先把si指针指向第一个字得到的值bx, ;di指向第二个字得到的值dx。若bx为0,di自加2,否则,则交换这两字, ;若此时si指向字为0,则di, 否则,di,si都自己加2。如此循环直到di指向最后一个字。 ;这样就把所有非零字至于前面了。 12.从键盘上输入一串字符(用回车键结束,使用10号功能调用)放在string中,是编制一个程序测试字符串中是否存在数字。如有,则把cl的第五位置1,否则将该位置置0 s1 segment stack dw 100h dup(?) top label word s1 ends s2 segment h1 db 'Please input a string: ','$' h2 db 'cx: ','$' crlf db 0dh,0ah,24h string db 50,?,50 dup('$') s2 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax and cl,0dfh ;先假设无数字,置0 lea dx,h1 mov ah,9 int 21h lea dx,string mov ah,10d int 21h mov si,2 l2: cmp string[si],'$' jz exit mov dl,string[si] cmp dl,30h jb l cmp dl,39h jnb l or cl,20h ;有数字,置1 jmp exit l: inc si jmp l2 exit: le
本文档为【24个汇编实例小程序】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_937120
暂无简介~
格式:doc
大小:260KB
软件:Word
页数:47
分类:互联网
上传时间:2013-11-17
浏览量:181