Thu, 7 Feb 2013, 02:59
A student writes: > Dr. Patt, > > I was working on the 2nd programming assignment and was wondering why the > program starts storing the instructions at the .orig / 2 (0x3000 / 2 = > 0x1800). What is the purpose of storing the instructions here? Would this > have any effect on incrementing the PC in the LDB, LDW, etc. opcodes? > > Thanks, > <<name withheld to protect the student misunderstanding memory addresses>> Thank you for this question. It may be bothering many students, so I am glad to add some explanation now, while you still have tonight + four full days before Lab2 is due. The important point is that the shell code we provided declares memory as a two dimensional array: int MEMORY[0x08000][2]; That means, for example, the second word of memory consists of two bytes, the first at address 0x0002 and the second at address 0x0003. That is, the 2^16 addresses are broken down into 2^15 word addresses (from 0x0000 to 0x7FFF), each consisting of two bytes. The address of each byte is obtained by concatenating the word address with a 0 or a 1. Thus, there are 0x08000 words in the LC3b address space, and each is composed of an addressable low byte and an addressable high byte. For example, if the first instruction is 0xF025, and it is stored at address 0x3000, the two bytes of that instruction would be stored, as follows: MEMORY[(0x3000>>1)][0] = 0x25; MEMORY[(0x3000>>1)][1] = 0xF0; Our intent was to provide shell code that tries to eliminate as much of the tedium as we can, enabling you to focus on the logic of the instruction level simulation for this lab. We are parsing the input file and loading it into the LC3b's memory. And, we have implemented the simulator shell commands (to run the program, print the contents of memory, print registers, etc.). Hopefully, you are mostly freed up to work on writing the code that correctly changes the state of the computer as a result of executing the instruction the PC is pointing to. Good luck finishing this by Sunday night. Yale Patt