================================================================ Assignment #10 - Disk & Intel Assembly Language and Machine Code ================================================================ - Ian! D. Allen - idallen@idallen.ca - www.idallen.com 1. Given the following boot sector dump from a MS-DOS disk: 0000 EB 3C 90 4D 53 57 49 4E-34 2E 31 00 02 40 01 00 .<.MSWIN4.1..@.. 0010 02 00 02 00 00 F8 99 00-3F 00 80 00 3F 00 00 00 ........?...?... 0020 C1 24 26 00 80 00 29 09-AD 62 36 4E 4F 20 4E 41 .$&...)..b6NO NA 0030 4D 45 20 20 20 20 46 41-54 31 36 20 20 20 FA 33 ME FAT16 .3 Use the chart in 19PhysicalFiles.htm to determine what is the start sector of the start of the File Allocation Space (in hex)? ANSWER: number of bytes per sector: 0200 h number of sectors per file allocation unit (cluster): 40 h number of copies of the FAT: 2 h number of root directory entries: 0200 h number of sectors used by each copy of the FAT: 0099 h Data Structure | Size in Sectors | Start Sector | End Sector Boot sector: 1 0 0 2 copies of FAT: 2 * 99h = 132 1 132 Root Directory: (200 * 20)/200 = 20 133 152 File Allocation Space: 40 sect/cluster 153 ...to end of disk Use the chart in 19PhysicalFiles.htm to determine what is the start sector of the start of the File Allocation Space (in hex)? ANSWER: 153 2. Given the following partial dump of an MS-DOS disk root directory: 0000 53 55 48 44 4C 4F 47 20-44 41 54 03 00 1E 1A 7C SUHDLOG DAT....| 0010 8E 21 77 29 00 00 30 67-8E 21 02 00 2E 14 00 00 .!w)..0g.!...... 0020 42 4F 4F 54 4C 4F 47 20-54 58 54 22 00 00 00 00 BOOTLOG TXT".... 0030 00 00 77 29 00 00 1D 73-7A 25 03 00 1C 64 00 00 ..w)...sz%...d.. 0040 41 55 54 4F 45 58 45 43-44 4F 53 21 00 11 CB 70 AUTOEXECDOS ...p 0050 59 22 77 29 00 00 C1 65-8E 21 7C 47 2D 02 00 00 Y"w)...e.!|G-... 0060 4D 4F 55 53 45 20 20 20-45 58 45 20 00 63 CE 70 MOUSE EXE .c.p 0070 59 22 A1 2E 00 00 40 41-F9 1E 28 48 38 A1 01 00 Y"....@A..(H8... 0080 41 66 00 66 00 61 00 73-00 74 00 0F 00 ED 75 00 Af.f.a.s.t....u. 0090 6E 00 30 00 2E 00 66 00-66 00 00 00 78 00 00 00 n.0...f.f...x... 00A0 46 46 41 53 54 55 4E 30-46 46 58 22 00 C5 14 77 FFASTUN0FFX"...w 00B0 85 28 77 29 00 00 17 77-85 28 59 90 00 50 0A 00 .(w)...w.(Y..P.. 00C0 43 4F 4E 46 49 47 20 20-53 59 53 20 00 83 D8 71 CONFIG SYS ...q 00D0 14 2D 55 2F 00 00 D9 71-14 2D 42 87 8C 00 00 00 .-U/...q.-B..... 00E0 E5 6C 00 6F 00 67 00 6F-00 5F 00 0F 00 27 62 00 .l.o.g.o._...'b. 00F0 6D 00 70 00 2E 00 6F 00-6C 00 00 00 64 00 00 00 m.p...o.l...d... 0100 E5 4F 47 4F 5F 42 4D 50-4F 4C 44 31 00 78 CE 70 .OGO_BMPOLD .x.p 0110 59 22 77 29 00 00 1D 6F-3F 22 2E 00 00 00 00 00 Y"w)...o?".H6... a. What kind of file (based on the attribute flags) is/was: i. SUHDLOG.DAT ANSWER: 03 = 0000 0011 = Hidden, Read only ii. BOOTLOG.TXT ANSWER: 22 = 0010 0010 = Archive needed, hidden iii. AUTOEXEC.DOS ANSWER: 21 = 0010 0001 = Archive needed, Read only iv. LOGO_BMP.OLD ANSWER: 31 = 0011 0001 = Archive, subdir, r/o b. What kind of thing is the directory entry that starts at offset 0080? ANSWER: 0F -> Windows long name c. How large (in hex) is SUHDLOG.DAT? ANSWER: 4-byte value at 1Ch -> 142Eh d. What is the first cluster number associated with SUHDLOG.DAT? ANSWER: 2-byte value at 1Ah -> 0002h e. What is the location of (d) as a hex disk-sector address, assuming this root directory is from the same disk as the earlier boot sector dump? ANSWER: 153 + (2 - 2) * 40 = 153 (all in hex) f. What formula did you use to calculate the above sector number? ANSWER: 153 + (N - 2) * 40, where N is the cluster number 3. Given the following 8-bit byte: 10000010 (shown in binary; base 2) a) What is the decimal value of the byte as an unsigned integer? ANSWER: 10000010 = 2**7+2**2 = 130, or 82h = (8*16)+2 = 130 b) What is the decimal value of the byte as an 8-bit, 2's complement signed integer? ANSWER: 10000010 -> 01111101+1 = 01111110 = 01111111-1 = 127-1 = 126 -> -126 or 82h -> 7E = (7*16)+14 = (8*16)-2 = 126 -> -126 c) What is the decimal value of the byte as a sign/magnitude integer? ANSWER: is negative, and remaining bits 0000010 = 2 so 10000010 = -2 d) What is the decimal value of the byte as an excess-127 integer? ANSWER: from (a) -> 130 - 127 = +3 e) Is the byte a valid ordinary ASCII character? ANSWER: NOT ASCII If so, what ASCII character is it? ANSWER: NOT ASCII (ASCII is 7-bit) 4. How many address wires does it take to address 32KB of memory? ANSWER: 2**15 = 32KB, so 15 wires 5. What are the hexadecimal addresses of the two middle bytes of a 32KB address space? ANSWER: 16KB-1 and 16KB -> 2**14-1 and 2**14 -> 3FFF and 4000 6. If a DOS disk has 128-byte sectors and 4 sectors per cluster (per allocation unit), give the size (in decimal bytes) of the smallest non-empty file you can create on this disk. ANSWER: 4 sectors of 128-bytes is 512 bytes 7. If a DOS disk has 128-byte sectors and uses 32 sectors for its ROOT directory, what is the maximum number of files (in decimal) that you can store in the ROOT directory on this disk? ANSWER: (32 sectors * 128 bytes) / 32 bytes = 128 files 8. How many bits are needed to address 64KB of memory? ANSWER: 16 9. How many bits are needed to address 1MB of memory? ANSWER: 20 10. A DEBUG dump shows you this: 1026:0000 2E 20 20 20 20 20 20 20-20 20 20 10 00 00 00 00 . ..... 1026:0010 00 00 00 00 00 00 1A 40-99 19 53 00 00 00 00 00 .......@..S..... 1026:0020 2E 2E 20 20 20 20 20 20-20 20 20 10 00 00 00 00 .. ..... 1026:0030 00 00 00 00 00 00 1A 40-99 19 00 00 00 00 00 00 .......@........ 1026:0040 43 4F 55 4E 54 52 59 20-53 5A 53 20 00 00 00 00 COUNTRY SZS .... 1026:0050 00 00 00 00 00 00 00 28-89 16 2B 00 AD 42 00 00 .......(..+..B.. 1026:0060 45 47 41 20 20 20 20 20-53 59 53 20 00 00 00 00 EGA SYS .... 1026:0070 00 00 00 00 00 00 00 28-89 16 34 00 15 13 00 00 .......(..4..... What byte value is located at address 0FFE:02C9 in the above dump? (Note that the above dump is for segment 1026, not segment 0FFE.) ANSWER: 0FFE0h + 02C9h = 102A9h, and 102A9h - 10260h = 49h, so look in the dump at 1026:0049 and find 5A 11. A DEBUG register dump shows you this: -R AX=0924 BX=001B CX=9770 DX=003A SP=FFDC BP=FFF2 SI=02AE DI=0C14 DS=17B8 ES=17BA SS=38A5 CS=2C6E IP=02E9 NV UP EI PL NZ NA PO NC 2C6E:02E9 9A78563412 CALL 1234:5678 Give, in hexadecimal notation, the segment:offset and real (absolute) memory addresses of these addresses: a) the address of the next instruction to be executed. ANSWERS: 2C6E:02E9 = 2c6E0 + 02E9 = 2c9c9 b) the address of the last value (the top entry) stored on the stack. ANSWERS: 38A5:FFDC = 38A50 + FFDC = 48A2C If the next instruction given in the above dump were executed: c) Which register values would change and what would their old and new values be? (see Notes file call_push_out.txt) ANSWERS: (Remember: Fetch, Increment, Execute!) IP: 02E9 -> 02EE SP: FFDC -> FFDA [SP] <- 2C6E (CS) so [SS:SP] <- 2C6E so [38A5:FFDA] <- 2C6E so [48A2A] <- 2C6E SP: FFDA -> FFD8 [SP] <- 02EE (IP) so [SS:SP] <- 02EE so [38A5:FFD8] <- 02EE so [48A28] <- 02EE IP: 02EE -> 5678 # last two loads can be in either order CS: 2C6E -> 1234 d) What value would appear in the byte addressed by the final value of the stack pointer? ANSWER: the incremented IP (02EEh) was pushed last, so the byte is EEh 12. Use DEBUG to assemble the instruction "CALL 0009" into memory at offset 0000 (zero). Un-assemble the instruction and look at the two bytes of address following the E8 opcode. (a) What is the hex value of that address? ANSWER: dump shows E80600 which means addr is 0006h Use DEBUG to assemble the instruction "CALL 0109" into memory at offset 0100 (not at zero). Un-assemble the instruction and look at the two bytes of address following the E8 opcode. (b) What is the hex value of that address? ANSWER: dump shows E80600 which means addr is 0006h Even though the two instructions "CALL 0009" and "CALL 0109" above look very different, they both result in exactly the same machine code. (c) Why? What value is stored in the address field of these instructions? ANSWERS: The number being stored is the "offset" - the relative distance between the (incremented) IP and the destination address. The distances between IP 0003 and destination 0009 and between IP 0103 and destination 0109 are the same - +6 in both cases. Hence, the same hex values. (d) Based on what you just learned about Intel "near" CALL instructions, are they relocatable? (Do their addresses need to be adjusted by a linker depending on where in memory the code is loaded?) Why or why not? ANSWERS: NOT relocatable. No adjustment is needed by the linker. The code can be loaded anywhere in memory and will still jump to the correct relative location. The linker doesn't need to change ("relocate") the address. A near CALL is NOT relocatable.