第一范文网 - 专业文章范例文档资料分享平台

2019年整理IBM-PC汇编语言程序设计第二版课后习题答案清华大学出版社

来源:用户分享 时间:2025/5/24 7:14:38 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

mov cl,string1+1 mov si,2 mov di,2 re:

mov al,string1[di] cmp al,string2[si] jnz no inc di inc si dec cx jnz re

mov dx ,offset string5 call info jmp exit no:

mov dx,offset string6 call info exit:

pop di pop si pop cx pop ax ret CHECK ENDP code ends end start

5.程序實現:(經DEBUG調試通過) data segment

info1 db 'PLEASE INPUT A NUMBER','$' ;提示信息,下同

info2 db 'WRONG NUMBER! PLEASE INPUT ANOTHER NUMBER!','$' ;如果鍵入非數字值,報錯,並提示輸入新的數字 data

ends code segment MAIN PROC FAR

assume cs:code,ds:data start:

mov ax,data mov ds,ax

mov dx,offset info1

call info ;提示輸入一個數字

call input ;輸入過程

call check ;檢查是否非數字字符

call bell ;響鈴N次,N為鍵入數字

ret MAIN ENDP

;在屏幕上輸出提示信息的過程 INFO PROC NEAR

INFO ENDP

;回車換行的過程 CRLF PROC NEAR

CRLF ENDP ;輸入的過程 INPUT PROC NEAR

INPUT ENDP

;檢查是否非數字字符的過程~ CHECK PROC NEAR

push dx

cmp al,30h 30H,

jb WRONG cmp al,39h push ax mov ah,9h int 21h call crlf pop ax ret push ax push dx mov dl,0dh mov ah,2h int 21h mov dl,0ah mov ah,2h int 21h pop dx pop ax ret mov ah,1 int 21h ret ;如果鍵入的字符ASCII值小於0的ASCII值 ;剛轉入WRONG,作錯誤處理 ;如果鍵入的字符ASCII值大於9的ASCII值39H,

ja WRONG ;則轉入WRONG,作錯誤處理 mov cl,al ;把合法的數字ASCII值放入CL中 jmp next

;錯誤處理過程,提示,並等待用戶鍵入新值 WRONG:

mov dx,offset info2 call info call input call check next:

pop dx ret CHECK ENDP

;根據用戶鍵入的數字,響鈴相應的次數 BELL PROC NEAR

push dx

sub cl,30h ;鍵入數字的ASCII值減去30,才能成為次數 mov dl,7h mov ah,2 re:

int 21h dec cx jnz re pop dx ret BELL ENDP CODE ENDS END START

6.程序實現。(末经调试) .model small .data

m db dup (20個數)

n db 20,0,20 dup (?) ;用于存放负数的最大容量为20的数组 p db 20,0,20 dup (?) ;同上,用于存放正数 .code

main proc far start:

mov ax,@data mov ds,ax

call check_store ;判斷數的正負並存入相應數組

call display ;在屏幕上顯示 main endp

check_store proc near

push ax push bx push cx

mov cx,20 ;循環次數放入CX

cld ;使SI向增加的方向移動

lea si,m ;M的偏移地址放入SI

again:

放入AL中

0比較

則存入負數組

剛存入正數組

store_in_n : push bx

mov bl,n[1] mov n[bl+1],al pop bx jmp again

store_in_p STORE—IN—P

exit:

check_store endp display proc near

mov al,[si] ;M中的數依次 cmp al,0 ;並且依次和 jl store_in_n ;如果小於0, jg store_in_p ;如果大於0, dec cx

jnz again jz exit ;N中已有數的個數放入BL中,

;把AL中負數存入數組N的最後一個數字的下一字節 push bx mov bl,p[1] mov p[bl+1],al pop bx jmp again pop cx pop bx pop ax ret push cx

2019年整理IBM-PC汇编语言程序设计第二版课后习题答案清华大学出版社.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c15duw77rwd7u3cm9b9nu86wqu5roq7003ap_5.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top