========================================================= Assignment #11 - Intel Assembly Language and Machine Code ========================================================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Sunday November 29, 2009 Due date in the Blackboard Assignment Area: due at 23:59 PM on Wednesday December 9, 2009 Do *not* use the DigitalDropbox to submit your answers. Answers will be posted after the due date/time so that you can check your answers before coming to class and ask questions in class. Please check your answers (and my answers!). I go over each assignment in class if there are questions about the answers. No questions means no review. Submission method: Via the "Assignments" DAT2343_Assignment_11 upload. Due to bugs in Blackboard, you can only submit your Assignment to me *once*. After that, you cannot submit any more times. If you need to re-submit it, you have to ask me to clear your previous submission. Do *not* use the DigitalDropbox to submit your answers. Answers will be posted shortly after the due date/time. Upload Assignment file name: assignment11.txt The name must be exactly as given. Typing mistakes in the name mean no credit. Be precise. (Your userid is not required.) Upload only plain text, not HTML, not MSWord. No fonts. Plain text only. Plain text only. Did I mention that the format is plain text? ------------------ The following memory dump might be required to answer one or more of the next questions in this week's homework set: 0AC9:0000 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 0AC9:0010 00 01 3F 05 3E 05 AA 01-6A 01 C1 04 8C 05 52 42 0AC9:0020 8B E8 8C C0 05 10 00 0E-1F A3 04 00 03 06 0C 00 0AC9:0030 8E C0 8B 0E 06 00 8B F9-4F 8B F7 FD F3 A4 50 B8 0AC9:0040 34 00 50 CB 8C C3 8C D8-48 8E D8 8E C0 BF 0F 00 0AC9:0050 B9 10 00 B0 FF F3 AE 47-8B F7 8B C3 48 8E C0 BF 0AC9:0060 0F 00 B1 04 8B C6 F7 D0-D3 E8 8C DA 2B D0 73 04 0AC9:0070 8C D8 2B D2 D3 E0 03 F0-8E DA 8B C7 F7 D0 D3 E8 0AC9:0080 8C C2 2B D0 73 04 8C C0-2B D2 D3 E0 03 F8 8E C2 0AC9:0090 AC 8A D0 4E AD 8B C8 46-8A C2 24 FE 3C B0 75 05 0AC9:00A0 AC F3 AA EB 06 3C B2 75-6D F3 A4 8A C2 A8 01 74 0AC9:00B0 B1 BE 32 01 0E 1F 8B 1E-04 00 FC 33 D2 AD 8B C8 0AC9:00C0 E3 13 8B C2 03 C3 8E C0-AD 8B F8 83 FF FF 74 11 0AC9:00D0 26 01 1D E2 F3 81 FA 00-F0 74 16 81 C2 00 10 EB 0AC9:00E0 DC 8C C0 40 8E C0 83 EF-10 26 01 1D 48 8E C0 EB 0AC9:00F0 E2 8B C3 8B 3E 08 00 8B-36 0A 00 03 F0 01 06 02 1. What register(s) would change if the next instruction (as indicated by this register display) were executed? What would be its(their) old and new contents? AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=0B10 CS=0ADB IP=0317 NV UP EI PL NZ NA PO NC 0ADB:0317 B8BC71 MOV AX,71BC ANSWER: 2. What register(s) would change if the next instruction (as indicated by this register display) were executed? What would be its(their) old and new contents? AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=0B10 CS=0ADB IP=0389 NV UP EI PL NZ NA PO NC 0ADB:0389 89D9 MOV CX,BX ANSWER: 3. What register(s) would change if the next instruction (as indicated by this register display) were executed? What would be its(their) old and new contents? AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=0B10 CS=0ADB IP=0419 NV UP EI PL NZ NA PO NC 0ADB:0419 8B17 MOV DX,[BX] ANSWER: 4. What register(s) would change if the next instruction (as indicated by this register display) were executed? What would be its(their) old and new contents? AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=0B10 CS=0ADB IP=0424 NV UP EI PL NZ NA PO NC 0ADB:0424 26 ES: ...this is a segment prefix, so 0ADB:0425 8B07 MOV AX,[BX] ...treat this as MOV AX,[ES:BX] ANSWER: 5. What register(s) would change if the next instruction (as indicated by this register display) were executed? What would be its(their) old and new contents? AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=0B10 CS=0ADB IP=031E NV UP EI PL NZ NA PO NC 0ADB:031E E97F02 JMP 05A0 ANSWER: 6. What register(s) would change if the next instruction (as indicated by this register display) were executed? What would be its(their) old and new contents? AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=0B10 CS=0ADB IP=0321 NV UP EI PL NZ NA PO NC 0ADB:0321 79F8 JNS 031B ANSWER: 7. What register(s) would change if the next instruction (as indicated by this register display) were executed? What would be its(their) old and new contents? AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=0B10 CS=0ADB IP=0333 NV UP EI PL NZ NA PO NC 0ADB:0333 77FA JA 032F ANSWER: 8. Given the following register contents: AX=1AFD BX=004C CX=0FC2 DX=97A1 SP=FF10 BP=0000 SI=0000 DI=0000 DS=0AC9 ES=0ACD SS=000A CS=0ADB IP=0333 NV UP EI PL NZ NA PO NC 0ADB:0333 9A3412A40C CALL 0CA4:1234 Each of the following instructions references a memory data value. What is the address of the memory data value in each of the following instructions? Give the answer in segment:offset and 20-bit hex forms: a. MOV AL,[000Ah] ANSWERS: b. MOV AH,[BX] ANSWERS: c. ADD AX,[ES:000Ah] ANSWERS: d. INC BYTE PTR [SI] ANSWERS: e. DEC WORD PTR [CS:DI] ANSWERS: f. POP CX ANSWERS: 9. Given the same register contents as the previous question, if the listed "CALL 0CA4:1234" instruction were executed, list, in execution order, the changes to registers and memory that would occur. Give both the old value and new value of each register that changes. You must address all of these items: a) What registers would change, and what would be their old and new values? b) What memory values would change? Give the memory addresses in both segment:offset and 20-bit real form. c) What would be the values put in those changed memory locations? d) What value would appear in the byte addressed by the final value of the stack pointer? ANSWER (a-c): ANSWER (d): ------------------ 10. What is the difference between an Intel "near" CALL and a "far" CALL instruction? ANSWER: 11. If an interrupt fetches a new IP from 0000:0098, from where does it fetch the new CS? ANSWER: 12. Give the segment:offset and real (absolute) address of the Interrupt Vector accessed by "INT 14". ANSWERS: ------------------ 13. Questions below are based on the Intel DOS DEBUG dump information supplied below. Some of the information supplied by these dumps is irrelevant to the questions being asked. The ASCII part of the DUMP has been omitted. AX=0924 BX=0059 CX=9770 DX=003A SP=FFDC BP=FFF2 SI=02AE DI=0C14 DS=0010 ES=0020 SS=0001 CS=0100 IP=02E9 NV UP EI PL NZ NA PO NC 0100:02E9 CD14 INT 14 0000:0000 9E 0F C9 00 65 04 70 00-16 00 20 07 65 04 70 00 0000:0010 65 04 70 00 54 FF 00 F0-3F 37 00 F0 53 FF 00 F0 0000:0020 00 00 00 CE 28 00 20 07-3A 00 20 07 52 00 20 07 0000:0030 6A 00 20 07 82 00 20 07-9A 00 20 07 65 04 70 00 0000:0040 05 00 57 CE 4D F8 00 F0-41 F8 00 F0 27 25 5F FD 0000:0050 39 E7 00 F0 42 04 4E 05-2D 04 70 00 28 0A 92 02 0000:0060 10 E6 00 F1 2F 00 E1 07-6E FE 00 F0 04 06 92 02 0000:0070 1D 00 00 CE A4 F0 00 F0-22 05 00 00 E3 53 00 C0 0000:0080 A8 0F C9 00 2F 04 AC 0E-4F 03 F3 14 8A 03 F3 14 0000:0090 17 03 F3 14 BC 0F C9 00-C6 0F C9 00 D0 0F C9 00 0000:00A0 6C 10 C9 00 66 04 70 00-B4 05 92 02 6C 10 C9 00 0000:00B0 6C 10 C9 00 6C 10 C9 00-62 01 1D 11 CC 01 1E 11 0000:00C0 EA E4 0F C9 00 FF 00 F0-6C 10 C9 00 01 00 89 0F 0000:00D0 6C 10 C9 00 6C 10 C9 00-6C 10 C9 00 6C 10 C9 00 0000:00E0 6C 10 C9 00 6C 10 C9 00-6C 10 C9 00 6C 10 C9 00 0000:00F0 6C 10 C9 00 6C 10 C9 00-6C 10 C9 00 6C 10 C9 00 0001:FFB0 6C 10 C9 00 6C 10 C9 00-62 01 1D 11 CC 01 1E 11 0001:FFC0 EA E4 0F C9 00 FF 00 F0-6C 10 C9 00 01 00 89 0F 0001:FFD0 6C 10 C9 00 6C 10 C9 00-6C 10 C9 00 29 AF C9 00 0001:FFE0 6C 10 C9 00 6C 10 C9 00-6C 10 C9 00 6C 10 C9 00 0001:FFF0 6C 10 C9 00 6C 10 C9 00-6C 10 C9 00 6C 10 C9 00 0010:0000 80 74 04 43 80 E6 7F C7-06 6A 42 0A 00 F6 44 07 0010:0010 0E 75 06 C7 06 6A 42 0A-00 E8 56 FD 0B DB 74 05 0010:0020 33 D2 B2 2D 52 55 C3 B4-38 B0 00 8D 16 77 42 CD 0010:0030 21 72 20 56 8B F2 AD A3-6C 42 83 C6 05 AD A3 6E 0010:0040 41 AD A3 70 42 AD A3 72-42 AD A3 74 42 AD AC A2 0010:0050 76 42 5E C3 51 52 1E 80-FA C0 76 08 8A C2 24 0F 0010:0060 B4 0C EB 02 8A E2 06 1F-8B D7 CD 21 1F 80 FA 0A 0010:0070 F8 74 02 B4 00 5A 59 EB-04 83 C4 04 F9 C3 56 53 0010:0080 33 F6 33 C9 C7 06 66 42-00 00 80 FE 00 75 03 EB 0010:0090 70 90 80 FE 03 75 05 BE-28 00 EB 15 F6 C6 02 74 Pay close attention to whether the questions below ask you for a memory address, or a memory value (the content of memory at an address). Give all answers in hexadecimal. Do not convert to decimal. Pay attention to the segment addresses in the dumps. Give the segment:offset and 20-bit real (absolute) memory addresses of these two addresses: a) the address of the next instruction to be executed. ANSWERS: b) the address of the last value (the top entry) stored on the stack. ANSWERS: c) Give the 16-bit value of the last value (the top entry) stored on the stack. ANSWER: If the next instruction given in the above dump were executed, list, in execution order, the changes to registers and memory that would occur. Give both the old value and new value of each register that changes. You must address all of these items: d1) What registers would change, and what would be their old and new values? d2) What memory values would change? Give the memory addresses in both segment:offset and 20-bit real form. d3) What would be the values put in those changed memory locations? (Use "?" if you don't know the value being assigned to memory.) ANSWERS (d1-d3): Note that order is important here! e) What value would appear in the byte addressed by the final value of the stack pointer? ANSWER: For the next two questions, pretend the above never happened. What value would be loaded into the AL register by executing the next instruction, if that next instruction were changed from INT 14 to be: (Note that ES is not a typing error in the question below.) f) MOV AL,[BX] ANSWER: g) MOV AL,[ES:004E] ANSWER: ------------------ 14. Given following DEBUG dump excerpt: -t AX=0000 BX=0000 CX=0000 DX=0000 SP=FFE0 BP=0000 SI=0000 DI=0000 DS=0010 ES=0010 SS=0010 CS=0010 IP=1234 NV UP EI PL NZ NA PO NC 0010:1234 E84144 CALL 5678 -d ffe0 0010:FFE0 BF 9A 7B 56 37 12 BF 9A-7B 56 37 12 03 01 00 00 ..{V7...{V7..... 0010:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ a) What is the segment:offset and real (absolute) address of the high byte of the item on top of the stack at this point? (The high byte is the higher memory address of the 16-bit quantity on top of the stack. The "top" of the stack is the 16-bit quantity addressed by the current value of SS:SP. Note that, since the stack grows *downward* in memory, the word on the "top" of the stack has an address *lower* than the "bottom" of the stack. The high byte of the word will be stored in higher memory than the low byte [according to Intel Little-Endian rules], so the address of the high byte will be one larger than the address of the low byte.) ANSWER: b) From the dump, what is the actual value (in hex) stored in memory at the address of the byte calculated in the previous question? ANSWER: For the next two questions below provide these three things: a) What is the Segment:Offset used in the final MOV instruction? b) What is the real (absolute) Address used in the final MOV instruction? c) What value would be picked up from memory and copied to register AL? 15. MOV BP,SP MOV AL,[BP] ANSWERS(a-c): 16. MOV BX,SP ADD BX,1 MOV AL,[BX] ANSWERS(a-c): ------------------ 17. What is the difference between (a) and (b): a) MOV AH,4Ch MOV AL,01h INT 21h b) MOV AX,4C01h INT 21h ANSWER: 18. What ASCII character is output on your screen after this executes? (You shouldn't need to run it to figure this out...) MOV AX,2Fh ADD AX,5 MOV DL,AL MOV AH,02h INT 21h ANSWER: ------------------ 19. Hand-translate these conditional fragments into Intel assembly language, paying attention to the Intel allowed operand chart (25BasicAssembler.htm). You do not have to code the whole program or declare any storage (unless you want to assemble and test your program). a) unsigned int dog, cow; if ( dog < 27h ) { dog = dog + 5h; } else { dog += cow; } ANSWER: (about 6-7 lines of assembler) b) signed int dog, cat; while ( dog > cat ) { dog -= 3h; } ANSWER: (about 5-6 lines of assembler) c) signed int sum,i,stop; for ( sum=0h, i=0h, stop=9h; i <= stop; i++ ) { sum += i; } ANSWER: (about 10-11 lines of assembler) d) Optional - uses array addressing - can you do it? Hints: 1. The memory address "array[i]" is made up of the address of "array" plus an offset that changes each time through the loop. Intel assembler lets you code an offset like this: MOV AX,ARRAY[BX] where BX contains a byte offset from the start of ARRAY. 2. ARRAY is an array of words, not an array of bytes. Every item in ARRAY is two bytes long. Index accordingly. 3. To multiply any integer value by two in assembler, ADD it to itself or shift it left (SHL) one bit. unsigned int sum,i,stop,array[10]; for ( sum=0h, i=0h, stop=9h; i < stop; i++ ) { sum += array[i]; } ANSWER: (about 12-13 lines of assembler)