诚信考试沉着应考杜绝违纪浙江大学2008–2009学年秋冬学期《汇编与接口》课程期末考试试卷开课学院:计算机学院,考试形式:开卷,允许带__1本书___入场考试时间: 09 年 1 月 11 日,所需时间: 120 分钟,任课教师 ________考生姓名: _____学号:专业: ______请把第1-5题的答案写在本页的答题纸上,第1-5题的评分以答题纸上的答案为准。
一.(10 points)Mark T for correct instruction or description, mark F foe incorrect instruction or description. (每题1分)三.(10 points) The following program runs under 32-bit Visual C++ environment,Please choose the best四.(10 points) The following program is developed under 32-bit Visual C++ environment, each integer takes 32五.(10 points) In protected mode, a Pentium 4 descriptor describes a segment, and the content of the descriptor一.(10 points)Mark T for correct instruction or description, mark F foe incorrect instruction or description. ()1. POP CS()2. IMUL DH()3. INSB()4. MOV AX,[ESI][EDI]()5. MOV AX,[SI][DI]()6. JMP WORD PTR [BP]()7. MOV [EBX], [ESI]()8. IMUL 125()9. ADD CX,[EAX]()10. In Mode 2, the 8254 usually generates a continuous square-wave.【答案】:(每题1分)(F)1. POP CS(T)2. IMUL DH(T)3. INSB(T)4. MOV AX,[ESI][EDI](F)5. MOV AX,[SI][DI](T)6. JMP WORD PTR [BP](F)7. MOV [EBX], [ESI](F)8. IMUL 125(T)9. ADD CX,[EAX](F)10. In Mode 2, the 8254 usually generates a continuous square-wave.二.(20 points)Please select your best choice for the following questions. (每题2分)1.In real mode, according to the following memory data, the entry address of INT 13H should be (____).0000:0030 72 10 A7 00 7C 10 A7 00-4F 03 80 05 8A 03 80 050000:0040 AD 06 14 02 A4 F0 00 F0-37 05 14 02 11 6D 00 C0A:6D11:C000 B:116D:00C0C:00C0:116D D:C000:6D11【答案】:D2.MOV EAX, 3A4C0002HMOV EBX, -2MUL BL then AX= (____)A:-4 B:508 C:-304H D:74980004H【答案】:B3.MOV EAX,1007MOV EDX,100DIV DL then AX= (____)A:070AH B:-532H C:10 D:7【答案】:A4.In real mode , variable X is defined in data segment, its segment address is 2345H, its offset is 2222H, then its20-bit physical address will be ____ .A:04567H B:45670H C:25672H D:23452H【答案】:C5.Which instruction will do “EBX -- ECX + 8*EAX –400H” ?A:MOV ECX, [ECX + 8*EAX – 400H] B:LEA ECX, [ECX + 8*EAX – 400H]C:MOV EBX, OFFSET [ECX + 8*EAX – 400H] D:ADD ECX , 8*EAX – 400H【答案】:B6.CF and OF are always set to 0 after instruction.A:SUB B:AND C:ADD D:MUL【答案】:B7.Suppose that DS=3200H, BX=0300H, SI=0240H, offset of myarray=0120H, determine the physical addressaccessed by instruction: “MOV myarray [SI], ECX” , assuming real mode operation.A:32240H B:32120H C:3560H D:32360H【答案】:D8.What is the purpose of interrupt vector type number 0?A:to detect and respond to divide eror. B:to report hardware errorC:to do a single-step trap D:to process double fault【答案】:A9.Suppose that the 8254’s control word is 10110110B, which description is correct?A:it sets counter 2 to read/write least-significant byte only.B:it sets counter 1 to read/write least-significant byte only.C:it sets counter 2 to read/write least-significant byte first, followed by the most significant byte.D:it sets counter 2 to read/write least-significant byte only.【答案】:C10.Suppose t hat the 8254’s control word is 10110110B, which description is correct?A:it selects mode 2.B:it selects BCD counting.C:it selects mode 3 and binary counting..D:it selects counter 1 and binary counting.【答案】:C三.(10 points) The following program runs under 32-bit Visual C++ environment.#include "stdafx.h"#include "stdio.h"char STRING[512]="27 hosts,120 disks and 3 printers#";int main(int argc, char* argv[]){_asm {MOV DH,'0'XOR ECX,ECXLEA EBX,STRINGCONT: MOV DL,[EBX]CMP DL,'#'JE EXITINC EBXCMP DL,30HJB CONTCMP DL,39HJA CONTINC ECXCMP DL,DHJBE CONTMOV DH,DLJMP CONTEXIT:}return 0;}Please choose the best answer.1. When this program runs to the label “EXIT”, the register CX= .A. 5B. 6C. 7D. 82. When this program runs to the label “EXIT”, the register DH= .A. 34HB. 35HC. 36HD. 37H(每题5分)1.【答案】:B2.【答案】:D四.(10 points) The following program is developed under 32-bit Visual C++ environment, each integer takes 32bits. The integer array “weight” holds many element, each element is the weight of an elephant; The integer “count” holds the total number of array elements; The integer “avg_w” holds the average weight of all elephants. The program calculates the average weight of all elephants and stores the result to integer “avg_w”, here avg_w is the average.1.Please fill in the blanks to make it complete.#include "stdafx.h"#include "stdio.h"int weight[5]={1100,2100,3200,4200,5400};int avg_w, count=5;int main(int argc, char* argv[]){_asm {LEA ESI, weight[0]XOR EBX,EBXCLDR1: LODSDLOOP R1MOV EAX,EBXMOV avg_w, EAX}printf("avg_w=%d\n" ,avg_w);return 0;}2.The printf will output: avg_w= .==================================【答案1】:(每空格2分)1.LEA ESI, weight[0]XOR EBX,EBXMOV ECX,count;错误答案:mov CX,5CLDR1: LODSDADD EBX,EAXLOOP R1MOV EAX,EBXXOR EDX,EDX; 或sub edx,edx; 或mov edx ,0;IDIV count ;或DIV count 错误答案:div 5MOV avg_w, EAX2. The printf will output: avg_w= 3200 .==================================【答案2】:(每空格2分)1.LEA ESI, weight[0]XOR EBX,EBXMOV CX, word ptr count 错误答案:mov CX,5CLDR1: LODSDADD BX, AXLOOP R1MOV EAX,EBXXOR DX,DX; 或sub dx,dx; 或mov dx ,0;IDIV word ptr count ;或DIV word ptr count 错误答案:div 5MOV avg_w, EAX2. The printf will output: avg_w= 3200 .五.(10 points) In protected mode, a Pentium 4 descriptor describes a segment, and the content of the descriptoris: 3CH, C0H, A2H, 6CH, 40H, 00H, 00H, 2FH,here the first byte 3CH is the most significant byte (B31-B24 of base address ). According to these content of descriptor: (please fill the answer in the below table.)1、the first byte address of the memory segment is (1) ;2、the size of the memory segment is (2)bytes;3、the segment has (3) . (been accessed, or not been accessed)4、the instruction mode of the memory segment is (4)(option :16-bit or 32-bit );5、the descriptor is a (5)descriptor. (option:system, or code segment ,or data segment)【答案】:(每空格2分)1、the first byte address of the memory segment is 3C6C4000H;2、the size of the memory segment is 30000H bytes; limit=0 00 2FH,size=30 000H3、the segment has not been accessed .; the access right byte of the memory segment is A2H=10100010 ;4、the instruction mode of the memory segment is 32-bit(16-bit or 32-bit );5. the descriptor is a system descriptor. (system or code segment or data segment)六.( 28 points) We use one 16550 chip and three 8259As to construct a communication subsystem which isbased on interrupt. The 16550’s port address is 3F0H—3F7H, and the 8259A’s port address is 20H and 21H.Every 8259A has 8 interrupt request pins: IR0—IR7. The main 8259A’s IR2 pin and IR3 pin connect to two slave 8259A’s INT pin respectively. The 16550’s INTR pin connects to main 8259A’s IR4.The following pro cedure INIT is used to initialize the 16550 and main 8259A, and two slave 8259A’s initialization program is not included in INIT.1.Please fill an instruction or part of an instruction in each blank. The content you filled must be in accordance with the prompt information beside each instruction. (20 points)INITPROC NEAR;============part I: begin to program 16550 ( 10 points) ===========CLIMOV AL, B ; ( 1 points)MOV DX, 3F3HOUT DX, ALMOV AL, ; ( 1 points) program Baud as 38400.MOV DX, 3F0HOUT DX, ALMOV AL, ;( 1 points); ( 1 points)OUT DX, ALMOV AL, 0 0 B ;program 8 data bit ,odd parity, 2 stop bit, ( 3 points)MOV DX, 3F3H ;OUT DX, ALMOV AL, 00 00 B; ( 2 points)MOV DX, 3F2H; ( 1 points);============part II: begin to program main 8259A and 16550 ( 10 points) ===========MOV AL, 000 0 B ;program ICW1 of 8259A ( 2 points)OUT 20H, AL ;edge trigger, two 8259 chips cascaded, ICW4 is neededMOV AL, ;program ICW2 ( 1 points)OUT 21H, AL ;set int. vector type numbers as 60—67HMOV AL, B ;program ICW3, The main 8259A’s;IR2、IR3 connect to 2 slave 8259As. ( 1 points)OUT 21H, AL ;MOV AL, 0 0 B; program ICW4 ( 3 points)OUT 21H, AL ;8086 mode,normal EOI, not SNFM, buffer mode , master chipMOV AL, B ; program OCW1 ( 1 points)OUT 21H, AL ;mask IR0—IR3, IR5—IR7 of 8259A( 1 points)MOV AL, B ; ( 1 points)enable transmitter interrupt of 16550,disable other interruptsMOV DX, 3F1H ;OUT DX, AL ; program interrupt control registerRETINIT ENDP【答案】:INITPROC NEAR;============part I: begin to program 16550 ( 10 points) ===========CLIMOV AL, 10000000B ;允许波特率除数, 最高位必须为1,其余位任意,1分MOV DX, 3F3H ; line control reg.OUT DX, ALMOV AL, 30 ;编程波特率16位除数为30,1分MOV DX, 3F0H ;LSB=3F0H , 38400波特OUT DX, ALMOV AL, 0 ;1分INC DX ; 或add dx,1; 或mov dx,3F1H 或其他正确答案,1分OUT DX, ALMOV AL, 00 0 0 1 1 1 1 B ;共3分,每空格0.5分MOV DX, 3F3H ;program 8 data bit ,odd parity, 2 stop bit, 00011111BOUT DX, AL ;line control reg. =base+3HMOV AL, XX0XX111B ;2分MOV DX, 3F2H ; FIFO reg. EQU base+2HOUT DX, AL ;1分;============ now begin to program main 8259A and 16550 ( 10 points) ========MOV AL, XXX10X01B ;program ICW1 of main 8259A ( 2 points)OUT 20H, AL ;edge trigger, two 8259 chips cascaded, ICW4 is neededMOV AL, 60H ;编程ICW2 ( 1 points)OUT 21H, AL ;set int. vector type numbers as 60—67HMOV AL, 00001100 B ;( 1 points) ICW3, The main 8259A’s IR2、IR3 connect to slave 8259A’OUT 21H, AL ;MOV AL, 0 0 B ; 编程ICW4=000 01101B ( 3 points)OUT 21H, AL ;8086 mode,normal EOI, not SNFM, buffer mode , master chipMOV AL, 11101111 B ; program OCW1 ( 1 points)OUT 21H, AL ;mask IR0—IR3, IR5—IR7 of 8259ASTI ( 1 points)MOV AL, 00000010B ; ( 1 points) enable transmitter interrupt of 16550,disable other interruptsMOV DX, 3F1H ;OUT DX, AL ; program interrupt control registerRETINIT ENDP2.The 16550’s D0—D7 pins connect to D0—D7 of system data bus, and its A0—A3 pins connect to A0—A2 of system address bus, please choose the best answer. (8 points)(下面每小题2分)(1). The 16550’s XIN and XOUT pins connects a crystal oscillator 18.432 MHZ, and the Baud rate is 38400 bit/s, then the BAUDOUT pin should has a frequency of HZ.A. 614400B. 307020C. 38400D. 19200【答案】:A(2). When a instruction “OUT DX,AL” is executed and DX=3F3H, AL=11001010B, the A2-A1-A0 pins of 16550 will be .A. 1-1-0B. 1-0-1C. 0-1-1D. 0-1-0【答案】:C(3). When a instruction “OUT DX,AL” is exec uted and DX=3F3H, AL=11001010B, the D2-D1-D0 pins of 16550 will be .A. 1-1-0B. 0-0-1C. 0-1-1D. 0-1-0【答案】:D(4).After 2 instructions “MOV DX, 3F2H” and “IN AL, DX” is executed, AL’s value is 00000010B, this indicates that for 16550.A. interrupt of receiver error is pendingB. interrupt of empty transmitter is pendingC. interrupt of newly received data is pendingD. no interrupt occurs【答案】:B七.(12 points)In a newly designed 8086-based personal computer, 82C55 is used. Suppose that the portaddress of 82C55 is 60H-63H, and the port B is set as mode 1 strobed input, the port C is set as mode 0 input, port A is set as mode 1 strobed out.Step 1: The CPU repeatedly polls the IBF of port B. When it finds that the IBF of port B is 1, the data inport B is read and added to DX.Step 2: Then the CPU checks whether the PC7 (the highest bit of port C) is 1, if yes, the DX is saved to 2-byte memory word located at 7000:32e4H and the procedure returns; otherwise the CPU goes to Step1.All registers except AX are protected. Please fill instruction or part of a instruction in the below procedure to accomplish the above task.sum8255 PROC NEARPUSH SIMOV AL, B ; (this blank takes 4 points, other blank takes 1 point each )OUT 63H, ALXOR DX, DXrep1: IN AL, 62H ;JZ rep1IN AL, 61HADD DL, AL;IN AL, 62HJZ rep1MOV AX,7000hMOV DS, AXMOV [SI], DXPOP SIRETsum8255 ENDP【答案】:sum8255 PROC NEARPUSH DSPUSH DXPUSH SIMOV AL, 10101111B ; (本空格4 points ,其他每空格1分)OUT 63H, ALXOR DX, DX ; or SUB DX,DX; XOR DX,DXrep1: IN AL, 62H ; 查IBF(PC1)=1?TEST AL,00000010B ; and AL, 00000010B是错的JZ rep1IN AL, 61HADD DL, ALADC DH,0 ; 把进位加到DHIN AL, 62HTEST AL, 10000000BJZ rep1MOV AX,7000hMOV DS, AXMOV SI, 32E4HMOV [SI], DXPOP SIPOP DXPOP DSRETsum8255 ENDP11。