Solutions and grading by Elena Oranskaya (eoranska@cs.princeton.edu, office hours MW 12:30-1:30 or by appointment) Problem 1. The halt instruction can only be excuted when the 'jump' instruction in location F6 is taken. That only happens when the contents of register 0 equal the contents of register 3, namely the binary value 5. So the program loops, incrementing the value in register 0 with every iteration until it reaches 5. Problem 2. 10 11FF load R1 with contents of memory location FF 12 1200 load R2 with contents of memory location 00 14 5312 add content of R1 and R2 and save result in R3 16 2000 load R0 with value 0 18 B320 jump to address 20 if contents of R3 equal content of R0 (else continue) 1A 3100 store contents of R1 into memory location 00 1C 32FF store contents of R2 into memory location FF 1E B024 jump to address 24 - unconditionally 20 3000 store value 0 into memory location 00 22 30FF store value 0 into memory location FF 24 C000 halt The solution above is one possible correct answer. There exist a few variations, which will also produce the desired result. Problem 3. A person types 30 words per minute, each of length 5 characters, which amounts to 5 * 30 = 150 characters per minute. 1 minute = 60 seconds and therefore the typing rate also equals 150 / 60 = 2.5 characters per second. The time that elapses between the typing of two characters is 1/ 2.5 = 0.4 seconds. Since the machine can execute 1000000 instructions per second, it executes 0.4 * 1000000 = 400000 instructions between the typing of two consecutive characters. Problem 4. Complications may arise if processes intend to alter the file. Simultaneous alteration will result in the inconsistency of data, which means that changes made by once process may be overwritten by the other and vice versa. In certain cases errors will result even if only one of the processes is writing to the file while the other is reading. So a universal solution would be to only grant simultaneous read access. In special cases when an interprocess communication protocol has been established between the processes they may get write access. Problem 5. Access time = 0.017 + 0.008 = 0.025 seconds Time slice = 0.05 seconds, so the process spends 0.025/0.05 = 50% of its time slice waiting for a read opration to complete. The machine executes 1000000 instructions per second, so during the waiting period it can execute 0.025 * 1000000 = 25000 instrucitons. Problem 6. Greater throughput would be achieved if one of the processes was I/O bound and the other - compute bound. The reason is that as we saw in Problem 5, I/O operations take a long time, during which the compute bound process can execute and get a chunk of its computation accomplished. Furthermore, the modern I/O systems have DMA channels, which allow them to transfer data in and out of memory without interrupting the CPU. So the two processes demand fewer of the same resources thus minimizing the system delays. If we had two I/O bound processes they may compete for the same peripherals, and would have to be run intermittenly, increasing the time spent in doing interrupt handling in addition to greater usage of the slower I/O devices. Problem 7 (extra credit). 00 2000 load R0 with value 0 02 2201 load R2 with value 1 04 11FE load R1 with contents of memory location FE 06 8312 AND the contents of registers R1 and R2 and save the reslut in R3 08 B304 jump address 04 (reload memory location FE) if the result of the AND was 0 - i.e. printer not ready 0A 35FF store the contents of R5 to memory location FF - i.e. print! 0C C000 halt