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
Computer Science 101 Homework Set 9 Due Wednesday, November 12 All homework should be turned in at class time and done in a neat fashion. You may work together with one other person from the class (only one). If the work is exactly the same for two people, turn in one paper with both names. 1. Here is a summary table of our assembly language for the hypothetical lab machine: Assembly Language Table Numeric Assembly Language Op Code Mnemonic 0000 LOAD X 0001 STORE X 0010 CLEAR X 0011 ADD X 0100 INCREMENT X 0101 SUBTRACT X 0110 DECREMENT X 0111 COMPARE X Numeric Op Code 1000 1001 1010 1011 1100 1101 1110 1111 Assembly Language Mnemonic JUMP X JUMPGT X JUMPEQ JUMPLT JUMPNEQ X IN X OUT X HALT Assume that the first few memory cells of our hypothetical lab machine have the following contents: Address (decimal) Contents(binary) 0 0000000000000101 1 0101000000000110 2 0001000000000111 3 1110000000000111 4 1111000000000000 5 0000000000001001 6 0000000000000101 7 0000000000011010 Assume further that the machine is ready to begin the fetch-decode-execute cycle, that the PC holds 000000000001, and that the register R holds 9 (decimal). Note that we are not starting at the first memory location. a. Tell exactly what will be stored in each of the following locations at the end of the fetch phase (a single fetch phase beginning with the situation described). Use decimal values for the PC, MAR, MDR, R and memory locations. Use the usual instruction format for IR (not binary). PC: IR: MAR: MDR: R: Memory location 6: b. Tell exactly what will be in these locations at the end of the execute phase (the single execute cycle following the fetch phase of part a). PC: IR: MAR: MDR: R: Memory location 6: c. Tell exactly what will be stored in these locations at the end of the next fetch. PC: IR: MAR: MDR: R: Memory location 6: d. Tell exactly what will be stored in each of these locations at the end of the next execute phase. PC: IR: MAR: MDR: R: Memory location 6: e. If we run the program, beginning at location 0, what will be the output? These problems refer to the assembly language for the hypothetical lab machine. First and foremost, your programs should be correct and follow the pseudocode. Extra credit will be given for the “fastest” correct solutions, under the assumption that execution of LOAD, STORE and CLEAR instructions take 2 units of time; INCREMENT, DECREMENT, IN and OUT take 3 units of time; all other instructions take 1 unit of time. 2. Using the pseudocode covered in the course or Python, write an algorithm to print out the sum of three numbers entered by the user. Now convert your pseudocode into a complete assembly language program, including pseudo-operations. 3. Write a pseudocode or Python algorithm for a program that allows the user to input 100 numbers and prints the sum. Convert your pseudocode into a complete assembly language program. 4. Convert the following algorithm into a complete assembly language program: Set Ct to 0 Set ToGo to 100 While ToGo > 0 Do Get Num If Num > 0 Then Set Ct to Ct + 1 Set ToGo to ToGo – 1 End-Of-Loop Print Ct Stop