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

发布时间 : 星期日 文章2019年整理IBM-PC汇编语言程序设计第二版课后习题答案清华大学出版社更新完毕开始阅读1d7668b8effdc8d376eeaeaad1f34693daef10b1

lea si,n[2]

mov cl,n[1] ;數組N中數的個數放入CL

cld mov ah 2

re_display_n: ;依次顯示各個負數 mov dl,[si] int 21h

mov dl,20h ;各個數之間用空格間隔

;下面四行用來回車和換行

;同上面負數的顯示,

re_display_p:

display endp end start 7.程序實現。(未調試) .model small .data

.code start:

八位無符號正數

int 21h dec cl

jnz re_display_n mov dl,0dh int 21h mov dl,0ah int 21h lea si,p[2] mov ch,p[1] cld mov dl,[si] int 21h mov dl,20h int 21h dec ch

jnz re_display_p pop cx ret data db 100d dup (100個數). mov ds,ax

;循環次數 bl,0feh ;初始化BX為最大的 mov ax,@data mov cx,101d mov mov si,offset data cld again:

dec cx

jz finish ;全部判斷完成 mov al,[si] cbw

div 2 ;每個數除以2

cmp al,0 ;佘數不為0的,不是偶數

jne again

cmp bl,[si] ;每次比較,

jl again ;較小的數, mov bl,[si] ;代替BX中原來的數

jmp again finish:

mov ax,0

mov al,bl ;把最小偶數放到AX中

end start

8.程序實現。(未調試) .model samll .code start:

mov ch,9 ;比較次數放入CH

mov cl,2 ;每次AX循左移的次數放入CL

mov dl,0 ;初始化DL,DL,中存放“四分之一字節”為三的個數 again:

dec ch ;如果AX最後兩個字節循環結束, jz display ;則在屏幕上輸出為“3”的個數 rol ax,cl mov bl,al and bl,3

cmp bl,3 ;如果“四分之一字節”不為3, jnz again ;則判斷下一個“四分之一字節” inc dl ;否則,DL增加一 jmp again

display: ;在屏幕上輸出DL內容 mov ah,2 int 21h end start 9.程序實現:

.model small .data

info1 db ' PLEASE INPUT A NUMBER!',0DH,0AH,'$' ;提示信息,下同 info2 db 'ILLEGAL CHAR,PLEASE TYPE IT AGAIN!',0DH,0AH,'$' .code

main proc far start:

PUSH ax push bx push cx push dx

mov ax,@data mov ds,ax

mov dx,offset info1 call dis_str 上顯示提示信息

call input_num 進制數

call dis_num 上輸出二進制數

pop dx pop cx pop bx pop ax RET

main endp

;在屏幕上顯示提示信息的過程 dis_str proc near

push ax mov ah,9 int 21h pop ax ret dis_str endp

;輸入一個四位十六進制數,並保存在BX中的過程

input_num proc near

push ax

;在屏幕輸入十六 ;在屏幕 ; push cx

mov bx,0 ;初始化BX mov ch,4 ;循環次數(十六進制數的位數!)

new_char: mov ah,1 int 21h

sub al,30h ;把ASCII值轉換成為二進制數

cmp al,0 ;和0相比, jl wrong ;如果比0小,說明不是數字,,,轉往非法字符處理過程, cmp al,9 ;是否A--F? jle add_to ;如果是0--9,直接放入BX中

sub al,7 ;如果是A--F,減去7,

cmp al,16 ;再和16D(10H)相比,

jg wrong ;如果大於16D,說明不是數字,轉入非法字符處理過程

add_to:

mov cl,4 ;BX每次左移四位

shl bx,cl mov ah,0 add bx,ax dec ch jz exit

jmp new_char ;輸入新的數字 wrong:

push dx

mov dx,offset info2 call dis_str pop dx

jmp new_char exit:

pop cx pop ax ret input_num endp