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
assume cs:code,ds:data main proc far
mov ax, data mov ds, ax mov cx, array lea bx, array+1 call near ptr getmax mov ah,4ch