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

2019-08-20 21:10

jb count_others cmp al,'Z' jb count_letter cmp al,'a' jb count_others jmp count_letter

count_letter: inc bx jmp repeat

count_digit: inc cx jmp repeat

count_others: inc dx jmp repeat

exit: push cx push dx call print_crlf lea dx,letter mov ah,9 int 21h mov ax,bx call print_ax call print_crlf lea dx,others mov ah,9 int 21h pop dx ;栈,后进先出,先进后出 mov ax,dx call print_ax call print_crlf lea dx,digit mov ah,9 int 21h pop cx ;print_ax会修改cx的值,故要先把cx进栈 mov ax,cx call print_ax

jmp exit2

print_crlf proc near lea dx,crlf mov ah,9 int 21h ret

print_crlf endp

print_ax proc near

mov cl,10 mov si,0

repeat2: div cl

mov dl,ah add dl,30h

mov dh,0 push dx inc si mov ah,0

cmp al,0 jnz repeat2

l3: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l3

ret print_ax endp

exit2: mov ah,4ch int 21H

main endp s3 ends

end main

17.已定义两个整数变量A和B,试编写程序完成以下功能

(1)若两个树种有一个是奇数,则将奇数存入A中,偶数存入B中 (2)若两个数均为奇数,则将两个数加1后存回原变量 (3)若两个数均为偶数,则两个变量均不变

s1 segment stack

dw 100h dup(?) top label word s1 ends

s2 segment a dw 12,'$' b dw -13,'$' 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,0 mov dx,0 mov cx,2 mov ax,a[0] cmp ax,0 jnl next neg ax

next:div cx cmp dx,1 jnz l mov si,1

l: mov dx,0 mov ax,b[0] cmp ax,0 jnl next2

neg ax

next2: div cx cmp dx,1 jnz l2 mov di,1

l2: cmp si,0 jnz l3 cmp di,0 jnz l4 jmp exit ;都是偶数,跳转到末尾

l3: cmp di,0 jnz l5 jmp exit ;a[0]为奇数,b[0]为偶数,跳转到末尾

l5: mov ax,a[0] ;a[0],b[0]为奇数,a[0]加一存回原变量 cmp ax,0 jnl l6 neg ax dec ax neg ax jmp l7 l6: inc ax l7: mov a[0],ax mov ax,b[0] ;a[0],b[0]为奇数,b[0]加一存回原变量 cmp ax,0 jnl l8 neg ax dec ax neg ax jmp l9 l8: inc ax l9: mov b[0],ax jmp exit

l4: mov ax,a[0] ;a[0]为偶数,b[0]为奇数,互换 mov bx,b[0] mov a[0],bx mov b[0],ax

exit: mov ah,4ch

int 21H

main endp s3 ends

end main

18.写一段子程序skiplines,完成输出空行的功能。空行的行数由用户在主程序中通过键盘输入,并将行数放在ax寄存器中

s1 segment stack

dw 100h dup(?) top label word s1 ends

s2 segment

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 bx,0

l: mov ah,1 int 21h cmp al,0dh jz next cbw

sub ax,30h xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax

jmp l

next:mov ax,bx call skiplines


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

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

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

马上注册会员

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