微机原理与接口技术(钱晓捷版)课后习题答案 下载本文

内容发布更新时间 : 2024/5/12 1:32:53星期一 下面是文章的全部内容请认真阅读。

array word 2005,2008,98 dup (1394) ; 假设100个16位正整数 wordsum word ?

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

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

over: mov eax,offset error call dispmsg 〔习题4.15〕

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

string byte 'If you find any error in the program, you can DEBUG it.' count = sizeof string bug byte 'BUG' ; 代码段 mov ecx,count mov edi,offset string L1: mov esi,offset bug push edi mov edx,sizeof bug LN: mov al,[esi] cmp [edi],al jne L2 inc esi inc edi dec edx jne LN pop edi mov al,'Y' jmp L3 L2: pop edi inc edi loop L1 mov al,'N' L3: call dispc 〔习题4.16〕

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

bcd dword 00371002h ; 代码段 mov esi,bcd cmp esi,0 jnz goon mov al,'0' call dispc jmp done

goon: mov ecx,8 xor ebx,ebx ; EBX=0,表示可能是前导0 again: rol esi,4 mov eax,esi and eax,0fh ; EAX低4位保存当前要显示的BCD码 cmp ebx,0 ; EBX≠0,说明不是前导0,要显示 jnz disp ; EBX=0,说明可能是前导0 cmp eax,0 jz next ; EAX=0,说明是前导0,不显示 mov ebx,1 ; EAX≠0,没有前导0了,令EBX=1≠0 disp: add al,30h call dispc

next: loop again done:

〔习题4.17〕

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

string byte 'Let us have a try !',0dh,0ah,0 ; 代码段 mov ecx,sizeof string cmp ecx,2 jb done lea eax,string ; 显示处理前的字符串 call dispmsg mov esi,ecx dec esi

outlp: cmp string[esi],' ' ; 检测是否是空格 jnz next ; 不是空格继续循环 mov edi,esi ; 是空格,进入剔除空格分支 dec ecx inlp: inc edi mov al,string[edi] ; 前移一个位置 mov string[edi-1],al cmp edi,ecx jb inlp

next: dec esi ; 继续进行 cmp esi,0 jnz outlp ; 为0结束

lea eax,string ; 显示处理后的字符串 call dispmsg done:

〔习题4.18〕

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

table byte ' |0 1 2 3 4 5 6 7 8 9 A B C D E F',13,10 byte '---+-------------------------------',13,10 tab1byte 6 dup(36 dup(?),13,10) byte 0 .code start: mov ebx,offset tab1 mov edx,'| 02' mov ax,2020h mov esi,6

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

again1: mov word ptr [ebx],ax add ebx,2 inc al loop again1 add ebx,2 add edx,1 dec esi jnz again0 mov eax,offset table call dispmsg exit 0 end start 〔习题4.19〕

请按如下说明编写子程序:

子程序功能:把用ASCII码表示的两位十进制数转换为压缩BCD码 入口参数:DH=十位数的ASCII码,DL=个位数的ASCII码 出口参数:AL=对应BCD码 〔解答〕 asctob proc shl dh,4 mov al,dh and dl,0fh or al,dl

ret

asctob endp 〔习题4.20〕

乘法的非压缩BCD码调整指令AAM执行的操作是:AH←AL÷10的商,AL←AL÷10的余数。利用AAM可以实现将AL中的100内数据转换为ASCII码,程序如下: xor ah,ah aam add ax,3030h

利用这段程序,编写一个显示AL中数值(0~99)的子程序。 〔解答〕 disp99 proc xor ah,ah aam add ax,3030h push ax mov al,ah call dispc pop ax call dispc ret

disp99 endp 〔习题4.21〕

编写一个源程序,在键盘上按一个键,将其返回的ASCII码值显示出来,如果按下ESC键(对应ASCII码是1BH)则程序退出。请调用书中的HTOASC子程序。 〔解答〕 ; 代码段,主程序 again: call readc cmp al,1bh jz done mov bl,al mov al,':' call dispc mov al,bl rol al,4 call htoasc ; 调用子程序 call dispc ; 显示一个字符 mov al,bl call htoasc ; 调用子程序 call dispc ; 显示一个字符 call dispcrlf jmp again done:

〔习题4.22〕

编写一个子程序,它以二进制形式显示EAX中32位数据,并设计一个主程序验证。 〔解答〕 ; 代码段,主程序 mov eax,8F98FF00H call dispbd ; 调用子程序