第四章習地的題目解答_第1頁
第四章習地的題目解答_第2頁
第四章習地的題目解答_第3頁
已閱讀5頁,還剩7頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、and cl, 0fhgetkey:;從鍵盤輸入,出口 :al存鍵值;判鍵值是小寫字母?;是小寫字母轉換為大寫字習題4.3丨將AX存放器中的16位數連續4位分成一組,共4組,然后把這4組數分別放 在AL、BL、CL和DL存放器中。思路:設這四組從低位到高位分別放在AL、BL、CL和DL存放器中。僅列出代碼段:mov bl, al;將al中的兩組分開and al, 0fh;屏蔽高四位后送al:1101mov cl, 4;原al中的數據邏輯右移4次送blshr bl, cl;bl 內容:1111mov dl, ah;將ah中的兩組分開and dl, 0f0h;屏敝低咼四位后送 dlmov cl,

2、4;原ah中的數據邏輯右移4次送dlshr dl, cl;dl:1011mov cl, ah;屏蔽高四位后送cl:0100mov ah, 1int 21hcmp al, 'a' getkaycmp al, 'z' ja getkay sub al,20hmov dl,al mov ah, 02h int 21h習題4.5丨用于LED數碼管顯示的代碼表為:LEDtable DB 0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8hDB 80h,90h,88h,83h,0c6h,0c1h,86h,8eh它依次表示0 9、A F這16個數碼的顯示代

3、碼。現編寫一個程序實現將led num中的一個數字0 9、A F轉換成對應的 LED顯示代碼。解答.model small.stack 256.dataLEDtableDB 0c0h , 0f9h , 0a4h,0b0h,99h,92h, 82h, 0f8hDB 80h , 90h, 88h, 83h, 0c6h, 0clh、86h,8ehled numDB ?.code.startupmov bx, offset LEDtablemov al, led num對應的LED顯示代碼;al中存有xlat.exit 0end習題4.10設變量bufX為有符號16位數,請將它的符號狀態保存在sign

4、X,即:如果X大于等于0,保存0;如果X小于0,保存-1 ffh。編寫該程序。解答.model small.stack.databufXdw -7sig nXdb ?.code.startupcmp bufX,0;test bufX,80hjl next;jnz n extmov sig nX,0jmp donen ext:mov sig nX,-1done:.exit 0end習題4.11bufX、bufY和bufZ是3個有符號16進制數,編寫一個比擬相等關系的程序:1如果這3個數都不相等,如此顯示0;2如果這3個數中有兩個數相等,如此顯示1 ;3如果這3個數都相等,如此顯示2。解答.mod

5、el smallbufx.stack 256.datadw ?bufYdw ?bufzdw ?.code .startup mov ax,bufX;cmp x,y?可以嗎?mov bx,bufYmov cx,bufZnext1:mov dl, '0' cmp ax,bx jnz n ext1 inc dlcmp ax,cxjnz n ext2inc dlnext2:cmp bx,cxjnz n ext3 inc dlnext3:cmp dl, ' 3'n ext4mov dl, ' 2'n ext4:mov ah,02h;顯示int 21h.ex

6、it 0end習題4.16編程實現把鍵入的一個字符,用二進制形式0 / 1丨顯示出它的ASCII代碼值。解答.model small.stack 256.datastrildb 'please in put',Odh,Oah,'$'.code.startupmov dx,offset stri1mov ah,09hint 21hmov ah, 01hint 21hmov cx, 8aga in:xor dl,dlshlal,1adc dl, 'O':dl=dl+ ' O' +cf:如果 cf=0,那么 dl=30h;如果 cf=1

7、,那么 dl=0+30h+1=31hmov ah,02hint 21hloop aga in.exit 0end.model small.stack.datastri1db 'please in put number:1-9',0dh,0ah,'$'.code.startupaga in:mov dx,offset stri1;顯示mov ah,09hint 21hstri1 ,提示輸入mov ah,01h;調用輸入一個字符int21h;輸入一個字符存在al中cmp al, '1'判該字符,女口不在1'-'9'agai n

8、 cmp al, 9 jaaga in;重新輸入and al,0fh;將31h和39h轉換為1和9在 T - '9屏蔽高4位mov cl, alxor ch,ch;振鈴次數送cxabc:mov dl, 07hmov ah, 02hint 21hloop abc.exit 0end;調用一次振鈴習題4.19編寫計算100個正整數之和的程序。如果和不超過16位字的X圍65535,如此保存其和到 wordsum,如超過如此顯示overflow '。解答.model small.stack.datanumequ 100wlistdw num dup( ?)wordsumdw ?erro

9、rdb 'overflow. $'.code.startupmov bx,offset wlistmov cx,numxor ax,axaga in:add ax,bxjc n extinc bxinc bxloop aga inmov bx,axn ext:jmp done mov dx,offset errordone:mov ah,9int 21h.exit 0end習題4.22丨過程定義的一般格式是怎樣的?子程序入口為什么常有PUSH旨令、出口為什么有POP指令?下面的程序段有什么不妥嗎?假如有,請改正:crazyPROCagain:push axxor ax,axxo

10、r dx,dx add ax,bx解答crazyadc dx,0inc bxinc bxloop aga inretENDP crazyPROC;crazy PROCpush axpush bxxor ax,ax;xor ax,axxor dx,dx;xor dx,dxagain:add ax,bx; again:add ax,bxadc dx,0;adc dx,0inc bx;inc bxinc bx;inc bxloop aga in;loop aga inret;retpop bxpop axENDP crazy;crazyENDP習題4.23丨子程序的參數傳遞有哪些方法,請簡單比擬。解

11、答存放器、共享變量公共存儲單元、堆棧用存放器傳遞參數是把參數存于約定的存放器中,這種方法簡單易行,經常采用;用變量傳遞參數是主程序與被調用過程直接用同一個變量名訪問傳遞的參數,就是利用變量傳遞參數。如果調用程序與被調用程序在同一個源程序文件中,只要設置好數據段存放器DS如此子程序與主程序訪問變量的形式一樣,也就是它們共享數據段的變量,調用程序與被調用程序不在同一個源文件中,必須利用public/extern進展聲明,才能用變量傳遞參數,利用變量傳遞參數, 過程的通用性比擬差,然而,在多個程序段間,尤其在不同程序的模塊間,利用全局變量共享數據也是一種常見的參數傳遞方法;用堆棧傳遞參數是主程序將子

12、程序的入口參數壓入堆棧,子程序從堆棧中取出參數; 子程序將出口壓入堆棧,主程序彈出堆棧取得它們。解答astobprocand dh, Ofhmov al, dhmul 10and dl, 0fhadd al, dlret astobendp習題4.28寫一個子程序,根據入口參數;十位數的ASCII碼轉為二進制數;al= 10*dh;個位數的ASCII碼轉為二進制數;al= 10*dh + dlAL=0/1/2,分別實現對大寫字母轉換成小寫、小寫轉換成大寫或大小寫字母互換。欲轉換的字符串在解答ChangeprocPush bx;保護bxstring 中,用0表示完畢。bxbx,al,0AL=0/

13、1/2,;根據入cmp參數分別處理jzjzcha n_0 dec alcha n_1dec alcha n_2 jmp done mov al,stri ngbxjzchan_0:對大寫字母轉換成小寫cmp al,0 jz do necmp al, ' A n ext0cmp al, ' Z' ja n ext0add;是大寫字母;是大寫字母實現xor;位移量清零6 / 11mov stri ngbx, al n extO:inc bx字母jmp cha n_0 cha n_1:mov al,stri ngbx對小寫字母轉換成大寫cmp al,0jz do necmp

14、al, ' a'n ext1cmp al, ' z'ja n ext1sub al, 20hmov stri ngbx, aln ext0:inc bx字母jmp cha n_1cha n_2:mov al,stri ngbx對大寫字母轉換成小寫cmp al,0jz do necmp al, ' An ext2cmp al, ' Zja next20add al, 20hjmp n ext2 next20:cmp al, ' a'n ext2cmp al, ' z'ja n ext2sub al, 20hmov s

15、tri ngbx, aln ext2:inc bx字母jmp cha n_2 done:pop bxbxret;位移量加1,指向下一;實現;是大寫字母;是大寫字母;轉換;位移量加1,指向下一;實現;是大寫字母;是大寫字母;轉換;是大寫字母;是大寫字母;轉換;位移量加1,指向下一; 恢 復changeendp1采用AX存放器傳遞這個16位二進制數.model small .stack .data wdatadw 34abh.code.startup mov ax,wdata call dispa .exit 05dispaprocpush cx push dx mov cl,4 mov dl,a

16、h shr dl,cl call dldisp mov dl,ah and dl,0fh call dldisp mov dl,al shr dl,cl call dldisp mov dl,al and dl,0fh call dldisp pop dx pop cx ret dispaendp5dldispprocpush ax or dl,30h cmp dl,39h e dldisp1add dl,7 dldisp1:mov ah,2int 21hpop axretdldispen dpend2采用wordTEMP變量傳遞這個16位二進制數.model small.stack.data

17、wdata wordtempdw 34abhdw ?.code.startupmov ax,wdatamov wordtemp,ax call dispa.exit 0dispa5procpush expush dxmov cl,4mov dl,byte ptr wordtemp+1 shr dl,clcall dldispmov dl,byte ptr wordtemp+1and dl,0fhcall dldispmov dl,byte ptr wordtempshr dl,clcall dldispmov dl,byte ptr wordtempand dl,0fhcall dldisppop dxpop cxretdispaen dpdldisp5procpush ax or dl,30h cmp dl,39h e dldisp1 add dl,7dldispl:mov ah,2int 21hpop axretdldispendpend3采用堆棧方法傳遞這個16位二進制數.model small.stack.datawdatadw 34abh.code.startuppush wdatacall dispapop ax.exit 0;add sp,2dispadispadldispprocpush bp mov bp,sp push ax push cx push dx

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論