微机原理与接口技术(第四版)课后习题答案(佳木斯大学) 联系客服

发布时间 : 星期六 文章微机原理与接口技术(第四版)课后习题答案(佳木斯大学)更新完毕开始阅读

nextl:

nextr: done:

〔习题4.11〕编写一个程序,先提示输入数字“Input Number:0~9”,然后在下一行显示输入的数字,结束;如果不是键入了0~9数字,就提示错误“Error!”,继续等待输入数字。 〔解答〕

inmsg ermsg

again:

erdisp:

done:

〔习题4.12〕有一个首地址为ARRAY的20个双字的数组,说明下列程序段的功能。

sumlp:

mov ecx,20 mov eax,0 mov esi,eax

add eax,array[esi] add esi,4 loop sumlp mov total,eax

; 数据段

byte 'Input number(0~9): ',0

byte 0dh,0ah,'Error! Input again: ',0 ; 代码段

mov eax,offset inmsg ; 提示输入数字 call dispmsg call readc ; 等待按键 cmp al,'0' ; 数字 < 0? jb erdisp cmp al,'9' ; 数字 > 9? ja erdisp

call dispcrlf call dispc jmp done

mov eax,offset ermsg call dispmsg jmp again

jnz nextr mov al,'M' jmp done mov al,'L' jmp done mov al,'R' call dispc

〔解答〕

求这20个双字的和,保存在TOTAL变量,不关进心进位和溢出。

〔习题4.13〕编程中经常要记录某个字符出现的次数。现编程记录某个字符串中空格出现的次数,结果保存在SPACE单元。

〔解答〕 ; 数据段

string byte 'Do you have fun with Assembly ?',0 ;以0结尾的字符串 space dword ?

- -25

again:

next:

done:

〔习题4.14〕编写计算100个16位正整数之和的程序。如果和不超过16位字的范围(65535),则保存其和到WORDSUM,如超过则显示‘Overflow !’。 〔解答〕

array wordsum error

again:

over:

〔习题4.15〕在一个已知长度的字符串中查找是否包含“BUG”子字符串。如果存在,显示“Y”,否则显示“N”。 〔解答〕

string count bug L1: LN:

; 数据段

byte 'If you find any error in the program, you can DEBUG it.' = sizeof string byte 'BUG' ; 代码段

mov ecx,count

mov edi,offset string mov esi,offset bug push edi

mov edx,sizeof bug mov al,[esi] cmp [edi],al jne L2

; 数据段

word 2005,2008,98 dup (1394) word ?

byte 'Overflow !',0 ; 代码段 and ebx,0 mov ecx,100 xor ax,ax

add ax,array[ebx*2] jc over inc ebx loop again

mov wordsum,ax

mov eax,offset error call dispmsg

; 代码段

mov esi,offset string xor ebx,ebx ;EBX用于记录空格数 mov al,[esi] cmp al,0 jz done cmp al,20h ;空格的ASCII码是20H jne next ;不相等、不是空格,转移 inc bx ;相等、是空格,空格个数加1 inc esi jmp again ;继续循环 mov space,ebx ;保存结果

; 假设100个16位正整数

- -26

L2: L3:

〔习题4.16〕主存中有一个8位压缩BCD码数据,保存在一个双字变量中。现在需要进行显示,但要求不显示前导0。由于位数较多,需要利用循环实现,但如何处理前导0和数据中间的0呢?不妨设置一个标记。编程实现。 〔解答〕 bcd

goon:

again:

disp:

next: done:

〔习题4.17〕已知一个字符串的长度,剔除其中所有的空格字符。请从字符串最后一个字符开始逐个向前判断、并进行处理。 〔解答〕

string

; 数据段

byte 'Let us have a try !',0dh,0ah,0 ; 代码段

mov ecx,sizeof string ; 数据段

dword 00371002h ; 代码段 mov esi,bcd cmp esi,0 jnz goon mov al,'0' call dispc jmp done mov ecx,8 xor ebx,ebx rol esi,4 mov eax,esi and eax,0fh cmp ebx,0 jnz disp cmp eax,0 jz next mov ebx,1 add al,30h call dispc loop again

inc esi inc edi dec edx jne LN pop edi mov al,'Y' jmp L3 pop edi inc edi loop L1 mov al,'N' call dispc

; EBX=0,表示可能是前导0

; EAX低4位保存当前要显示的BCD码 ; EBX≠0,说明不是前导0,要显示 ; EBX=0,说明可能是前导0

; EAX=0,说明是前导0,不显示

; EAX≠0,没有前导0了,令EBX=1≠0

- -27

outlp:

inlp:

next:

done:

〔习题4.18〕第3章习题3.14在屏幕上显示ASCII表,现仅在数据段设置表格缓冲区,编程将ASCII代码值填入留出位置的表格,然后调用显示功能实现(需要利用双重循环)。 〔解答〕

table

tab1

start:

again0:

again1:

include io32.inc .data

byte ' |0 1 2 3 4 5 6 7 8 9 A B C D E F',13,10 byte '---+-------------------------------',13,10 byte 6 dup(36 dup(?),13,10) byte 0 .code

mov ebx,offset tab1 mov edx,'| 02' mov ax,2020h mov esi,6

mov [ebx],edx add ebx,4 mov ecx,16

mov word ptr [ebx],ax add ebx,2 inc al

loop again1 add ebx,2 add edx,1 dec esi

cmp ecx,2 jb done

lea eax,string call dispmsg mov esi,ecx dec esi

cmp string[esi],' ' jnz next mov edi,esi dec ecx inc edi

mov al,string[edi] mov string[edi-1],al cmp edi,ecx jb inlp dec esi cmp esi,0 jnz outlp

lea eax,string call dispmsg

; 显示处理前的字符串

; 检测是否是空格 ; 不是空格继续循环

; 是空格,进入剔除空格分支

; 前移一个位置

; 继续进行

; 为0结束

; 显示处理后的字符串

- -28