内容发布更新时间 : 2024/12/23 13:09:48星期一 下面是文章的全部内容请认真阅读。
code ends
end main
6.6 编写程序,从键盘输入一个字符串到BUFF,用子程序统计各字符出现的次数。 错误!
;numbers of every char to be found ;ababc ;0b0bc ;0000c ;00000
data segment
mess1 db 13,10, 'input string:$' mess2 db 13,10, 'input a char:$' mess3 db 13,10, 'not found! $' mess4 db 13,10, 'found at: $'
org 40h
buff label byte max1 db 9 act1 db ?
stok1 db 9 dup(?) data ends
code segment
assume cs:code, ds:data main proc far push ds sub ax,ax push ax
mov ax,data mov ds,ax lea dx,mess1 mov ah,09
int 21h ;qust1? lea dx,buff mov ah,0ah
int 21h ;ans1 call near ptr scan ret main endp
scan proc near mov cl,act1 mov ch,0 mov dl,30h send: lea di,stok1
k1: cmp byte ptr[di],20h je kong
cmp byte ptr[di],13 je ones mov bl,[di]
mov byte ptr[di],20h k2:
inc dl inc di
cmp bl,[di] je cnum cnum:
mov byte ptr[di],0 ones:
mov ah,2 int 21h loop send kong: inc di jmp k1
mov si,di mov al,[si] cmp al,20h je next cmp al,[di] jne next inc dl next: inc di loop
next cmp repne scasb je found
nofd: lea dx,mess3 mov ah,9 int 21h jmp exit found:
lea dx,mess4 mov ah,9 int 21h
sub act1, cl mov dl,act1
add dl,30h mov ah,2 int 21h
exit: ret scan endp code ends
end main
6.7 主程序从键盘输入一个八位的二进制数,对其作求补操作,用子程序对求补后的值以二进制形式显示。 code segment
assume cs:code main proc far start:
mov bx,0 mov cx,8 next: mov ah, 1 int 21h cmp al,30h jb exit cmp al,31h ja exit sub al,30h shl bl,1 add bl,al loop next neg bl call outp exit: mov ah,4ch int 21h main endp
outp proc near mov ah,2 mov dl,10 int 21h mov cx,8 kp: shl bl,1 jc k1
mov dl,30h jmp kk
k1: mov dl,31h kk: mov ah,2 int 21h
loop kp ret outp endp code ends end start
6.8 主程序从键盘输入两个四位的十六进制数A和B,用子程序作十六进制计算A+B,并显示计算结果。
;only accept print char: 0~9,A~F code segment
assume cs:code main proc far start:
mov ax,cs mov ds,ax lea dx,mess mov ah,9 int 21h mov si,2 inone: mov dx,0 mov bx,0 mov ch,4 mov cl,4 next: mov ah, 1 int 21h sub al,30h cmp al,0 jb exit cmp al,9 ja char jmp k1 char: sub al,7 cmp al,0ah jb exit cmp al,0fh ja exit k1: mov dl,al shl bx,cl add bx,dx dec ch jnz next push bx mov ah,2 mov dl,13
int 21h mov ah,2 mov dl,10 int 21h dec si jnz inone call outp exit: mov ah,4ch int 21h main endp
outp proc near mov bp,sp
mov ax,[bp+2] mov bx,[bp+4] add bx,ax mov ch,4 mov cl,4 out1: rol bx,cl mov dx,bx and dl,0fh add dl,30h cmp dl,39h ja ad7 jmp kp ad7: add dl,7 kp: mov ah,2 int 21h dec ch jnz out1 ret outp endp
mess db 'only accept 0-9,A-F,input:',13,10,'$' code ends end start
6.9 某字数组为有符号数,第一个单元为元素个数N,后面为N个元素,编写通 用子程序,求数组元素中的最大值,并把它放入MAX单元。 ;put the big to max location data segment
array dw 5,9,4,5,15,3 max dw ? data ends code segment