24个汇编实例小程序(4)

2019-08-20 21:10

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 cmp dl,str2+1 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

;str1+1为str1实际的字符个数 ;str2+1为str2实际的字符个数 ;输出不匹配信息 ;输出匹配信息

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


24个汇编实例小程序(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:人行横洞施工方案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: