24个汇编实例小程序

上传人:d**** 文档编号:51498883 上传时间:2022-01-26 格式:DOCX 页数:43 大小:55.07KB
返回 下载 相关 举报
24个汇编实例小程序_第1页
第1页 / 共43页
24个汇编实例小程序_第2页
第2页 / 共43页
24个汇编实例小程序_第3页
第3页 / 共43页
亲,该文档总共43页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
24 个汇编小程序题目列表:逆序输出字符串“ BASED ADDRESSIN”G从键盘上输入两个数,分别放到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盘根目录建立一个文件, 第一次向文件写入 “123456”六个字符, 第二次增加 “abcdefg 几个字符从键盘上输入文本文件: “ ”的容后,然后新建一个文件“ ”,把前一个文件的所有容 复制到后一个文件中从键盘上输入一个十进制数,以十六进制数显示出来。要求子程序用寄存器参数传送方法试编制一个程序,把 bx 寄存器中的二进制数用十六进制数的形式在屏幕上显示出来代码:1.逆序输出字符串“ BASED ADDRESSIN”Gs1segment stack dw 100 dup()定义栈段 s1tops1label word ;top ends定义栈空间为 100指向栈顶s2S2segment ; db BASED ADDRESSING,$ ends定义数据段 s2定义字符串 ss3 segment ; 定义代码段 s3 assume cs:s3,ds:s2,ss:s1main proc far栈初始化; 栈初始化mov mov leaax,s1 ;ss,axsp,topmovax,s2 ;数据段初始化movds,ax; 数据段初始化movsi,15l: movdl,ssi;dl 获取字符串 s 的最后一个(从零开始的第十movah,2; 调用 int 21h 2 号功能输出 dl 上的值int21hdecsi ;寄存器减一,准备获取下一个字符cmpsi,0jalmovah,4ch ;终止int21hmain endp五个字符)s3 endsend main s1 segment stack dw 100h dup() top label word s1 ends2. 从键盘上输入两个数,分别放到x,y 单元,求出它们的和s2segmenth1dbPlease input x:,$ ;提示输入h2dbPlease input y:,$ ;提示输入h3dbz=x+y:,$ ;提示输出crlfdb0dh,0ah,24h ;定义回车换行xdwydws2endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1 ; 初始化 mov ss,ax lea 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;cmp al,30h ;jl exit1cmp al,39h ; jg exit1;sub al,30h ;al输入一个字符判断时候为“回车”字符如果是回车字符就跳转到 exit1和 30h (即字符 0 的 asii 值)比较; 如果输入字符小于 0 ,跳转到 exit1和 39h( 即字符 9 的 ascii 值 ) 比较 如果输入字符大于 9 ,跳转到 exit1 减去 30h,输入字符转化成数字 (从这一行开始到后面的 add bx,ax 为输入字符转化为数字的处理方法)扩充为 ax开始到这一行为输入字符转化为数字的处理cbw ;al xchg ax,bx mov cx,10 mul cxxchg ax,bxadd bx,ax ;sub al,30h 方法jmp InputXexit1: mov x,bx ; 把输入的存于 bx 的放到 x 中 lea dx,crlf mov ah,9 int 21h lea dx,h2 mov ah,9 int 21h xor bx,bxInputY: ; 和 InputX 类似,输入 y mov ah,1 int 21h cmp al,0dhjz exit2 cmp al,30h jl exit2cmp al,39h jg exit2sub al,30hcbwxchg ax,bxmov cx,10mul cxxchg ax,bx add bx,ax jmp InputYexit2: mov y,bx把输入的存于 bx 的放到 y 中mov bx,x addbx,y此时 bx 为两数加和leamov int leadx,crlfah,921Hdx,h3mov ah,9int 21hxor si,si ;si清零,用作计数mov ax,bx把和放到 ax 上l4: mov cl,10 div cl mov dl,ah mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz l4把和连续除以 10 知道和变为零,余数依次进栈重要,不能漏写l5: pop dx add dl,30h mov ah,2 int 21h dec si cmp si,0 jnz l5余数依次出栈 余数转换为显示的余数字符 输入余数字符mov ah,4chint 21Hmain endps3 endsend main3. 是编写一段程序,要求在长度为 10的数组中,找出大于 42h 的无符号数的个数并存入地 址为 up 开始区域, 找出小于 42h 的无符号数的个数并存入地址为 down 的开始区域, 并分别 显示 up、down 数组的个数和数组的数字s1 segment stack dw 100h dup() top label word s1 ends s2 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 ends s3 segment assume cs:s3,ds:s2,ss:s3 main proc farmovax,s1movss,axleasp,topmovax,s2movds,axmovsi,0movdi,1movbp,1把 array 数组中小于 42h 的值放到 down 数组里, 大repeat: cmp arraysi,42h 于 42h 的值放到 up 数组里面 jb downarray mov dl,arraysi mov upbp,dl inc sicmp si,10jz exit1 inc bp jmp repeatdownarray:mov dl,arraysi mov downdi,dl inc sicmp si,10 jz exit2 inc di jmp repeatexit1: sub di,1 jmp exit把分配好的 up 数组和 down 数组在其有效数字后面添加exit2: sub bp,1 exit: mov dx,bp ; $ ,便于后面的输出结束 mov up0,dl inc bp mov upbp,$ mov dx,di mov down0,dl inc di mov downdi,$mov cl,10 mov si,0lea dx,h1 mov ah,9 int 21hPrintUparray: cmp upsi,$ jz next mov al,upsi call print inc si jmp PrintUparraynext: lea dx,crlf mov ah,9int 21hlea dx,h2int 21h xor si,siPrintDownArray: cmp downsi,$ jz atend mov al,downsi call print inc si jmp PrintDownArrayprint proc near ;print 为输出十进制输出某个数的子程序 mov di,0rediv: mov ah,0 div cl mov dl,ah mov dh,0 push dx inc di cmp al,0 jnz redivbreak: pop dx add dl,30h mov ah,2 int 21h dec di cmp di,0 jnz breakmov dl, mov ah,2 int 21H retprint endpatend:mov ah,4chint21Hmain endp s3 endsend main4. 键盘输入一段字符串,其中小写字母以大写字母输出,其他字符不变输出s1 segment stackdw100h dup()toplabelwords1endss2segmenth1dbPlease input a string:,$h2dbThe changed string is:,$crlfdb0dh,0ah,24htempdbs2endss3 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,axlea dx,h1 mov ah,9 int 21hmov si,0l: 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 tempsi,al ; 把字符放到 temp 数组里 inc si jmp l输出 tmp 数组exit: lea dx,crlf mov ah,9 int 21h lea dx,h2 mov ah,9 int 21hinc si mov tempsi,$ lea dx,temp mov ah,9 int 21hmov ah,4ch int 21H main endp s3 endsend main5. 从键盘上就收一个小写字母,找出它的前导字符和后续字符,在顺序显示这三个字符s1 segment stack dw 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 far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axl: lea dx,h1 mov ah,9 int 21hmov ah,1 int 21h cmp al,a jl l cmp al,z jg lmovcl,alleadx,crlfmovah,9int21Hlea dx,h2mov ah,9int 21hdecclmovdl,clmovah,2int21hmovdl, movah,2int21hincclmovdl,clmov ah,2int 21hmovdl, movah,2int21hincclmovdl,clmovah,2int 21hmovah,4chint21H输出前导字符输出该字符输出后导字符main endps3 endsend main6. 把一个包含 20 个数据的数组 M分成两组:正整数组 P和负整数组 N,分别把这两个数组 中的数据的个数显示出来dws1 segment stack dw 100h dup() top label word s1 endss2segmenth1dbthe positive number is: ,$h2dbthe negative number is: ,$crlfdb0dh,0ah,24harray50h,-11h,61h,-22h,72h,-33h,73h,-41h,74h,21h,67h,-90h,73h,77h,-1h,-89h,-11h,61h, -22h,20h,$s2 ends s3 segmentassume cs:s3,ds:s2,ss:s3 main proc farmov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov bx,0 mov si,0有符号数比较用 jll: mov dx,arraysi cmp dx,0 jl addlow ; add si,2 cmp si,40 jz exit jmp laddlow: inc bx add si,2 cmp si,40 jz exit jmp lexit: lea dx,h2 mov ah,9 int 21hmov callax,bxprintleadx,crlfmovah,9int21hleadx,h1movah,9int21hmov ax,20 sub ax,bx call print jmp atend打印数字字符的子程序print proc nearmov cl,10mov si,0repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeatl2: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l2ret print endpatend: mov ah,4chint 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,24hdwdata50,-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,datasicmp ax,0jnl l4neg ax ; 如果是负数,则求补l4: div clmov al,ahmov ah,0div dl cmp ah,0 jnz l1cmp bx,datasi ; jl l1 ;mov bx,datasi ;比较最小值和数组中的每个数如果数组中的数大于最小值跳转到 l1 如果数组中的数小于最小值则将其赋给最小值l1: add si,2 cmp si,40 jz exit jmp 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 cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeatl3: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l3retprint endpatend: mov ah,4ch int 21Hmain endps3 endsend main8. 输入两船字符串 string1 和 string2 ,并比较两个字符串是否相等, 相等就显示 “ match”, 否则显示“ no match ”s1 segment stack dw 100h dup() top label word s1 endss2 segmenth1 db Please input the first string: ,$h2 db Please input the second string: ,$h3dbMATCH,$h4dbNO MATCH,$crlfdb0dh,0ah,24hstr1db50,50 dup($)str2db50,50 dup($)s2endss3segmentassume cs:s3,ds:s2,ss:s3 main proc farmov ax,s1mov ss,ax lea sp,top mov ax,s2 mov ds,axlea dx,h1 mov ah,9 int 21hlea dx,str1 mov ah,0ahint 21hlea dx,crlfmov ah,9int 21h lea dx,h2int 21hlea dx,str2 mov ah,0ahint 21hlea dx,crlfmov ah,9int 21hmov dl,str1+1 ;str1+1 cmp dl,str2+1 ;str2+1 jnz lmov si,2l2: mov dl,str1si cmp dl,str2si jnz l inc si cmp si,50 jz l3 jmp l2l: lea dx,h4 ;mov ah,9 int 21hl3: lea dx,h3 ; mov ah,9 int 21h为 str1 实际的字符个数为 str2 实际的字符个数输出不匹配信息输出匹配信息mov ah,4chint 21H main endp s3 endsend main9. 从键盘接收一个四位的十六进制数,并在终端显示与它等值的二进制数s1 segment stackdw 100h dup() top label word s1 ends s2 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 ends s3 segmentassume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axrepeat: lea dx,h1 mov ah,9 int 21hmovbx,0movcx,4newchar:接收新字符movah,1int21hcmpal,30hjbrepeatcmpal,46hjg repeat cmp al,39h jnb l1 ; sub al,30h jmp l2l1: cmp al,41h jb repeat sub al,37h jmp l2如果输入字符大于 9 跳到 l1如果输入字符小于 A,则输入错误,跳到 输入字符为 AZ,故相应地要减 37hrepeat为把输入字符转化为数值作计数器,即待会要循环 16 次循环左移以为,最高位进标志位 若标志位为 1 则跳转到 l3l2: cbw ;l2 xchg ax,bx mov dx,10h mul dx xchg ax,bx add bx,ax ;loop newchar dec cx cmp cx,0 jnz newcharleadx,crlfmovah,9int21hleadx,h2int21hmov si,0mov cx,10h ;cxl5: rol bx,1 ;bx jc l3 ;mov tempsi,0 jmp l4 l3: mov tempsi,1 l4: inc siloop l5lea dx,temp mov ah,9 int 21hmov ah,4chint 21H main endps3 endsend main 10 从键盘输入一系列以 $为结束符的字符串,然后对其中的非数字字符计数,并显示计数结 果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 main并将后续项11. 有一个首地址为 mem的 10个字的数组, 试编程序删除数组中所有为零的项, 向前压缩,最后将数组的剩余部分补上零s1 segment stackdw 100h dup()top label words1 ends s2 segmentmem dw 0,1,0,3,0,0,4,5,6,0,$ crlf db 0dh,0ah,24hs2 ends s3 segmentassume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov si,0 mov di,2repeat: cmp di,20 jz exit mov bx,memsi mov dx,memdi cmp bx,0 jnz next xchg bx,dx mov memsi,bx mov memdi,dxnext: cmp memsi,0 jz l add si,2l: add di,2 jmp repeatexit: mov ah,4ch int 21Hmain endps3 ends end main; 以下是该算法描述bx,; 定义两个指针,当前指针 si 和检查指针 di ,先把 si 指针指向第一个字得到的值 ;di 指向第二个字得到的值 dx。若 bx 为 0, di 自加 2,否则,则交换这两字,; 若此时 si 指向字为 0,则 di, 否则, di , si 都自己加 2。如此循环直到 di 指向最后一个 字。; 这样就把所有非零字至于前面了。12. 从键盘上输入一串字符(用回车键结束,使用 一个程序测试字符串中是否存在数字。如有,则把10 号功能调用)放在 string 中,是编制 cl 的第五位置 1,否则将该位置置 0s1 segment stackdw 100h dup() top label word s1 endss2segmenth1dbPlease input a string: ,$h2dbcx: ,$crlfdb0dh,0ah,24hstring db50,50 dup($)s2endss3 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,axand cl,0dfh ; 先假设无数字,置 0 lea dx,h1mov ah,9 int 21h lea dx,string mov ah,10d int 21hmov si,2l2: cmp stringsi,$ jz exit mov dl,stringsi cmp dl,30h jb lcmp dl,39h jnb l or cl,20h ; 有数字,置 1 jmp exitl: inc si jmp l2exit: lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h mov ax,cx call print jmp atendprint proc nearmov cl,10 mov si,0repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeatl3: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l3retprint endpatend: mov ah,4ch int 21Hmain endp s3 endsend main个程序, 求出平均值bx 寄存器中 (f 分13. 在首地址为 data 的字数组中, 存放了 10 个 16 位字数据, 试编写 放在 ax 寄存器中,并求出数组中有多少个数小于此平均值,将结果放在 别考虑有符号数、无符号数情况 )s1segment stackdw 100h dup()toplabel words1endss2segmentdatadw -1,0,1,-2,2,3,-3,-4,4,15,$crlfdb 0dh,0ah,24hs2endss3segmentassume cs:s3,ds:s2,ss:s3mainproc farmov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov si,0 mov ax,0l3: cmp datasi,$ jz exit mov dx,datasi cmp dx,0 jnl l1 neg dx sub ax,dx jmp l2l1: add ax,dx l2: add si,2 jmp l3exit: mov cl,10平均值放到 ax 中div cl mov ah,0mov si,0mov bx,0小于平均值的数的个数放到 bx 中l5: cmp datasi,$ jz exit2cmp ax,datasi jz l6 jl l6 inc bxl6: add si,2 jmp l5exit2: mov ah,4ch int 21Hmain endps3 endsend main14. 一直数组 A包含 15个互不相等的整数,数组 B包含 20个互不相等的整数。试编制一个 程序,把既在 A 中又在 B中出现的整数存放于数组 C中并显示 C中的数值; 两层循环比较得出两个数组中相同的数值s1 segment stackdw 100h dup()top label words1 endss2 segmenta dw 1h,2h,3h,4h,5h,6h,7h,8h,9h,10h,11h,12h,13h,14h,15h,$dwb21h,22h,23h,24h,25h,6h,18h,19h,10h,11h,12h,34h,14h,53h,31h,32h,33h,36h,7h,67h,$cdw 16 dup($)crlfdb 0dh,0ah,24hs2endss3segmentassume cs:s3,ds:s2,ss:s3mainproc farmovax,s1movss,axleasp,topmovax,s2movds,axmov si,0mov di,0mov bp,0l4: cmp di,40 jz l2 jmp l3l2: add si,2 cmp si,30 jz exit mov di,0l3: mov ax,asi mov bx,bdi cmp ax,bx jnz l mov cbp,ax add bp,2l: add di,2 jmp l4exit: mov bp,0l6: cmp cbp,$ jz atend mov ax,cbp call print add bp,2 mov dl, mov ah,2 int 21h jmp l6print proc nearmov cl,10mov si,0repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeatl5: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l5retprint endpatend: mov ah,4ch int 21Hmain endps3 endsend main15. 设在 A、B和 D单元中分别存放着三个数。若三个数都不是0,则求出三个数的和并存放在 S 单元,若其中有一个数为 0,则把其它两个单元也清零。请编写此程序 s1 segment stackdw 100h dup() top label word s1 endss2 segment a dw 1h,$ b dw -11h,$ d dw 0h,$ s dw 2 dup($) crlf db 0dh,0ah,24h s2 endss3 segmentassume cs:s3,ds:s2,ss:s3 main proc farmov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov ax,a0 mov bx,b0 mov dx,d0 cmp ax,0 jz l cmp bx,0 jz l cmp dx,0 jz lmov cx,0 cmp ax,0 jnl add_ax neg ax ; 减法需先求补 sub cx,ax jmp l2add_ax: add cx,axl2: cmp bx,0 jnl add_bx neg bx sub cx,bx jmp l3add_bx: add cx,bxl3: cmp dx,0 jnl add_dx neg dx sub cx,dx jmp l4 add_dx: add cx,dxl4: mov s0,cx jmp exitl: mov a0,0 mov b0,0mov d0,0 exit: mov ah,4chint 21Hmain endps3 endsend main最后显16. 从键盘输入一系列字符 (以回车键结束) ,并按字母、数字和其他字符分类计数, 示这三类的计数结果s1segment stackdw 100h dup()toplabel words1endss2segmentletterdb the number of letter: ,$digitdbthe number of digit: ,$others dbthe number of other chars: ,$crlf db 0dh,0ah,24hs2 ends s3 segmentassume cs:s3,ds:s2,ss:s3 main proc farmov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov bx,0mov cx,0 mov dx,0repeat: mov ah,1 int 21h cmp al,0dh jz exitcmp al,30h jb count_otherscmp al,z jnb count_others cmp al,39h jb count_digit cmp al,A jb count_others cmp al,Z jb count_letter cmp al,a jb count_others jmp count_lettercount_letter:inc bx jmp repeatcount_digit:inc cx jmp repeatcount_others:inc dx jmp repeatexit: push cx push dxcall print_crlf lea dx,letter mov ah,9 int 21h mov ax,bx callprint_axcallprint_crlflea dx,others mov ah,9 int 21h pop dx ; 栈,后进先出,先进后出 mov ax,dx callprint_axcallprint_crlflea dx,digitmov ah,9int 21hpop cx ;print_ax 会修改 cx 的值 , 故要先把 cx 进栈 mov ax,cxcall print_axjmp exit2print_crlf proc nearlea dx,crlfmov ah,9int 21hretprint_crlf endpprint_ax proc nearmov cl,10 mov si,0repeat2: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeat2l3: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l3retprint_ax endpexit2:mov ah,4chint 21H main endps3 endsend main17. 已定义两个整数变量 A和 B,试编写程序完成以下功能(1)若两个树种有一个是奇数,则将奇数存入A 中,偶数存入 B中(2)若两个数均为奇数,则将两个数加1 后存回原变量(3)若两个数均为偶数,则两个变量均不变s1 segment stackdw 100h dup()top label words1 endss2 segmenta dw 12,$b dw -13,$s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axmov si,0mov di,0mov dx,0 mov cx,2 mov ax,a0 cmp ax,0 jnl next neg axnext: div cx cmp dx,1 jnz l mov si,1l: mov dx,0 mov ax,b0 cmp ax,0 jnl next2 neg axnext2: div cx cmp dx,1 jnz l2 mov di,1l2: cmp si,0jnz l3cmp di,0jnz l4jmp exit ; 都是偶数,跳转到末尾;a0 为奇数, b0 为偶数,跳转到末尾, b0 为奇数, a0 加一存回原变量l3: cmp di,0 jnz l5 jmp exitl5: mov ax,a0 ;a0 cmp ax,0 jnl l6 neg ax dec ax neg ax jmp l7l6: inc ax l7: mov a0,axmov ax,b0 ;a0, b0 为奇数, b0 加一存回原变量cmp ax,0 jnl l8 neg ax dec ax neg ax jmp l9 l8: inc ax l9: mov b0,axjmp exitl4: mov ax,a0 ;a0为偶数, b0 为奇数,互换mov bx,b0mov a0,bxmov b0,axexit: mov ah,4ch int 21Hmain endps3 endsend main18. 写一段子程序 skiplines ,完成输出空行的功能。空行的行数由用户在主程序过键盘输 入,并将行数放在 ax 寄存器中s1segment stackdw 100h dup()toplabel words1endss2segmentcrlfdb 0dh,0ah,24h,$s2endss3segmentassume cs:s3,ds:s2,ss:s3mainproc farmov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov bx,0 l: mov ah,1int 21h cmp al,0dh jz next cbw sub ax,30h xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,axjmp l next: mov ax,bxcall skiplinesmov ah,4chint 21Hmain endpskiplines procnearmov bx,ax repeat: cmp bx,0jz exitlea dx,crlf mov ah,9 int 21h dec bx jmp repeatexit: ret skiplines endps3 endsend main19. 设有 10个学生成绩分别是 76, 69 ,84,73,88,99,63,100 和 80。试编写一个子程 序统计 60-69 分,70-79 分, 80-89 分, 90-99 分和 100 分的人数,并分别放到 S6,S7,S8,S9, S10 单元中s1segment stackdw 100h dup()toplabel words1endss2segmentscore dw 76,69,84,90,73,88,99,63,100,80,$s6 dw 0,$s7 dw 0,$s8 dw 0,$s9 dw 0
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!