微机原理习题4参考答案(2)

2020-04-16 12:51

的低4位分别放在AL、BL、CL和DL中。

参考程序: code segment assume cs:code start:

MOV BX,AX MOV DX,AX MOV CL,4 SHR AH,CL MOV AL,AH MOV BL,BH AND BL,0FH MOV DH,DL SHR DH,CL MOV CL,DH mov ah,4ch int 21h code ends end start

4.15设有两个16位整数变量A和B,试编写完成下述操作的程序: (1)若两个数中有一个是奇数,则将奇数存入A中,偶数存入B中。 (2)若两个数均为奇数,则两数分别减1,并存回原变量中。 (3)若两个数均为偶数,则两变量不变。 参考程序:

DATA SEGMENT a dw ? b dw ? DATA ENDS code segment

assume cs:code,ds:data start:

mov ax,data mov ds,ax lop: mov ax,a mov bx,b xor ax,bx test ax,0001H jz next test bx,0001H jz exit xchg bx,a

·6·

mov b,bx jmp exit next:test bx,0001h jz exit dec b dec a exit:mov ah,4ch int 21h code ends end start

4.16 设有一段英文,其字符变量名为ENG,并以$字符结束。试编写一程序,查找单词“is”在该文中的出现次数,并将次数显示出来。(英文内容由用户自己定义)

参考程序:

DATA SEGMENT

ENG db 'this is an program example$' n1 equ $-eng str db 'is' n2 equ $-str DATA ENDS code segment

assume cs:code,ds:data,es:data start:

mov ax,data mov ds,ax mov es,ax xor dx,dx mov cl,n1 xor ch,ch cmp cx,n2 jbe disp mov al,str lea di,eng cld search:

repne scasb jne disp mov bl,str+1 cmp es:[di],bl je exist jcxz disp lop: jmp search

·7·

exist:inc dl cmp cx,1 jz disp jmp lop disp: or dl,30h mov ah,2 int 21h mov ah,4ch int 21h code ends end start

4.17 请编写程序实现以下功能:设在A、B和C单元中分别存放着一个8位带符号数。试比较这3个数,若3个数都不是0,则求出3数之和并存放于D单元中;若其中有一个数为0,则把其它两个单元也清零。

参考程序:

DATA SEGMENT a Db 10 b db -10 c db 30 d db ?

DATA ENDS code segment

assume cs:code,ds:data start:

mov ax,data mov ds,ax xor dx,dx cmp a,0 jz next mov dl,a cmp b,0 jnz lop1 next:mov b,0 mov c,0 mov a,0 jmp exit lop1:add dl,b cmp c,0 jz next add dl,c mov d,dl

·8·

exit:mov ah,4ch int 21h code ends end start

4.18 从键盘输入一系列字符(以回车符结束),并按字母、数字及其它字符分类计数,最后显示出这三类的计数结果。

参考程序: data segment

s db ? ;统计字符 d db ? ;统计数字 o db ? ;统计其它字符 code segment

assume cs:code,ds:data start:

mov ax,data mov ds,ax lop: mov ah,1 int 21h cmp al,0dh jz disp cmp al,30h jb other cmp al,39h jbe shu cmp al,41h jb other cmp al,5ah jbe str cmp al,61h jb other cmp al,7ah jbe str jmp lop other:inc o jmp lop shu: inc d jmp lop str: inc s jmp lop disp:

mov dl,0ah

· mov ah,2 int 21h mov dl,0dh mov ah,2 int 21h mov dl,s or dl,30h mov ah,2 int 21h mov dl,d or dl,30h int 21h mov dl,o or dl,30h int 21h mov ah,4ch int 21h code ends end start

10··


微机原理习题4参考答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:贵州省房屋建筑工程竣工验收备案表 - 图文

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

马上注册会员

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