Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
EE-314 Spring 2001 Midterm Exam #1 Answer Key Name:_____________________________________ Student ID #:_______________________________ Problem 1) (5 Points) Identify the operand addressing mode used in each of these instructions. a) AND DX,CX __Register____________ b) CALL WORD PTR [SI+4] __Index + Disp________ c) ADD CX,15 __Immediate__________ d) MOV IVAL[BX+DI+2],BX __Base + Index +Disp___ e) CMP FOO[BP],AL __Base + Disp_________ Problem 2) (10 Points) What will be the value in AX after executing the following instructions? Give the answer in both hexadecimal and binary. mov xor mov rol add adc al,17 ah,ah cl,4 al,cl al,88h ah,0 AX AX AX AX AX AX = = = = = = ?? 00 00 00 00 00 11 11 11 11 CY = 1 99 CY = 0 99 __0099h_______________ __0000 0000 1001 1001b__ Problem 3) (10 Points) What will be the value in AX after executing the following instructions? Assume that DS and ES are set up appropriately to access the variable ‘stuff’. Give the answer in hexadecimal: 1 stuff 0 3 2 5 4 7 6 dw 12 34h,23 45h,34 56h,45 67h mov mov add mov bx,1 si,5 si,bx ax,stuff[si-3] BX=1 SI=5 SI=6 AX=[stuff+3] (byte 3 & 4) ______5623h___________ AX gets the contents of bytes at offset 3 and 4 from the beginning of stuff. The byte at offset 3 goes to AL and the byte at offset 4 goes to AH. EE-314 Spring 2001 Problem 4) (20 points) Write a complete DOS assembly language program which does the following: Read a single character from the keyboard. If the character read is ‘A’, print the message “A was entered”, if the character read was ‘B’, print the message “B was entered”. If any other character was typed, print the message “Unknown character”. The program should then terminate. Hints: Make sure that the data is in a data segment and the code in a code segment. Set up segment registers appropriately. Use appropriate DOS functions for the input and output. _data segment msgA msgB msgErr db db _data ends _stck segment stck dw 128 dup (?) label word _stck ends _text segment assume word public ‘code’ cs:_text,ds:_data,ss:_stck main: mov mov mov ax,seg _DATA ds,ax es,ax mov int ah,1 21h cmp jnz mov jmp al,’A’ ;was A typed main10 dx,offset msgA main50 main10: cmp jnz mov jmp al,’B’ ;was B typed main20 dx,offset msgB main50 main20: mov dx,offset msgErr main50: mov int ah,9 21h mov int ax,4C00h 21h _TEXT byte public ‘data’ “A was entered”,0Dh,0Ah,’$’ “B was entered”,0Dh,0Ah,’$’ db “Unknown character”,0Dh,0Ah,’$’ word stack ‘stack’ ends end main ;read a char from keyboard ;print the message EE-314 Spring 2001 Problem 5) (20 Points) Write a subroutine called ‘SUM’ which accepts two word sized parameters on the stack, adds them together and returns the result in AX. It should be a near procedure declared using the PROC directive. (Hint: be sure to set up a stack frame appropriately for accessing the parameters) A call to this subroutine would appear as follows: mov ax,val1 push ax ;push first parameter mov ax,val2 push ax ;push second parameter call sum ;returns result in AX add sp,4 ;clean up stack sum sum proc near push mov bp bp,sp mov add ax,[bp+6] ax,[bp+4] pop ret bp endp ;get val1 ;add in val2 EE-314 Spring 2001 Problem 6) Refer to the information on the following page to answer these questions: a) (10 Points) The instruction shown in bold (address: 1266:0043) in the program listing is the current instruction being executed. While this instruction is executing, an NMI occurs. The NMI will be serviced before the next instruction begins executing. What is the address of the NMI interrupt service routine? NMI uses the INT 2 vector. Each vector occupies four bytes, so the INT 2 vector is the four bytes at offset 8 in the interrupt vector table (0000:0008). Remember the proper byte order for Intel machines. ___05DB:1016___________ b) (15 Points) Show the contents of the program stack in the NMI interrupt service routine just before the call to HANDLENMI occurs. Use one row of the table for each word on the stack. (Hint: There will be values placed on the stack by the CPU during interrupt processing and by the ISR itself before the call to HANDLENMI occurs.) Memory Address (offset only) Memory Value (word) 007E 001D 007C 0240 (FLAGS) 007A 1266 (CS) 0078 0045 (IP) 0076 002C (DI) 0074 0063 (AX) 0072 0000 (BX) c) (10 Points) At address 1266:0045 is a JZ instruction. Given the current state of the registers and the contents of memory, determine if this jump will be taken or not. Give the address of the instruction that will execute after the JZ instruction. ___1266:0047____________ The instruction in question is a JZ. The jump will be taken if the zero flag is set. To determine if the zero flag will be set or not, it is necessary to look at the last instruction executed which sets the zero flag. This is the CMP instruction immediately prior to the JZ instruction. This instruction: cmp al,[di] compares the contents of AL, which is 63h, with the contents of memory location 125A:002C (the value in DS:DI). This memory location contains 4Dh, which is not equal to 63h. The zero flag will not be set, and the jump will not be taken. The next instruction to be executed would be at 1266:0047 EE-314 Spring 2001 Problem 6 Data) You are stepping through the execution of an 8088 assembly language program. The following information shows the state of the machine. Shown are memory dumps, a disassembled listing of the part of the program that is currently executing, and the current contents of the CPU registers. Dump of Interrupt Vector Table: 0000:0000 0000:0010 0000:0020 0000:0030 BB 65 00 6A 08 04 00 00 0B 70 00 DA 02 00 C9 05 65 D7 28 82 04 04 00 00 70 00 DA DA 00-16 C0-85 05-3A 05-9A 10 98 00 00 DB 00 DA DA 05 F0 05 05 65 53 52 65 04 FF 00 04 70 00 DA 70 00 F0 05 00 ....e.p.....e.p. e.p.........S... ....(...:...R... j...........e.p. 20 31 31 23 74 00 34 31 6F 57 20 00 20 65 4D 18 45 6C 69 00 45 63 64 00 33 6F 74 00 ..Welcome to EE3 14 Exam #1.Welco me to EE314 Midt erm Exam #1..... 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00-00 00 00 00 00 00 1D 00 ................ ................ Dump of the Program’s Data Segment: 125A:0000 125A:0010 125A:0020 125A:0030 00 31 6D 65 00 34 65 72 57 20 20 6D 65 45 74 20 6C 78 6F 45 63 61 20 78 6F 6D 45 61 6D-65 20-23 45-33 6D-20 Dump of the Program’s Stack Segment: 125E:0060 125E:0070 Listing of the program code: 1266:0035 1266:0036 1266:0037 1266:003A 1266:003C 1266:003F 1266:0041 1266:0043 1266:0045 1266:0047 1266:0049 1266:004C 1266:004E 1266:0051 1266:0053 1266:0055 46 47 803C00 7505 803D00 7412 8A04 3A05 74EE 7305 B8FFFF EB07 B80100 EB02 33C0 C3 INC INC CMP JNZ CMP JZ MOV CMP JZ JNB MOV JMP MOV JMP XOR RET SI DI BYTE PTR [SI],00 0041 BYTE PTR [DI],00 0053 AL,[SI] AL,[DI] 0035 004E AX,FFFF 0055 AX,0001 0055 AX,AX Current Contents of the CPU Registers: AX=0063 DS=125A BX=0000 ES=125A CX=0018 SS=125E DX=0000 CS=1266 SP=007E IP=0043 BP=0000 SI=0013 FLAGS=0240 NMI Interrupt Service Routine: NMIISR: PUSH PUSH PUSH CALL POP POP POP IRET DI AX BX HANDLENMI BX AX DI ;process the NMI DI=002C