Tues, 8 Oct 2019, 00:30 A few words, based on questions I have gotten in the past couple of days



My students,

Some questions some students asked recently that I thought I would forward to all of you.

1. When we submit this first programming assignment in 0s and 1s, how do we know where in memory
it will go?

Answer: See "Notes and Suggestions" which spells it out pretty specifically: "To do this,
the first line of your program should be the bit pattern 0011000000000000."  This is x3000 and
spells out where the program starts.  That is the first line of your program is x3000.  The second
line of your program is the first instruction in your program, which will then be in memory 
location x3000.

2. Sabee always beats me up that I am too sloppy about the address of a memory location and the
contents of that memory location.  Of course, he is correct!  So, x3100 is the address of a
memory location, and M[x3100] is the 16-bit value stored in that memory location.  In class
today, the first instruction of my program, I wrote: "0010 001 followed by x3100."  While I was
doing that, I SAID (but Sabee was concerned that not everyone heard, that: 

0010 is the opcode for load when we use PC+offset for determining the memory location containing 
the value to be loaded,

001 is the register number, signifying that the value will be loaded into register 1, and

x3100 represents the address of the memory location that contains the value to be loaded.  
An instruction consists of 16 bits.  We have used 4 for the opcode and 3 for the destination
register.  That leaves 9 bits for calculating the address of the memory location.  How we 
determine those 9 bits we will look at next.

3. The 9 bits needed to calculate the address where the value to be loaded into R1 is stored.
The address where the value is stored is x3100.  The PC at the time of calculating that address
is x3001 since the load instruction is in M[x3000], and we have incremented the PC in the first 
clock cycle of starting the processing of the load instruction.

PC+offset means: "sign-extend the 9 bit offset to 16 bits, and then add the result to the
incremented PC to obtain the memory address of the location where the value to be loaded is 
stored."  Since the incremented PC is x3001, and since the memory address is x3100, the 9-bit 
offset MUST BE x0FF, and becomes x00FF when sign-extended to 16 bits.  Why?  Because 
x3001 + x00FF = x3100.

That is, when the the memory address is calculated in the EVALUATE ADDRESS phase of the
instruction cycle, the 9-bit offset is sign-extended to 16 bits and added to the incremented PC.
Thus, when the instruction is constructed (before the program is executed), the 9-bit offset 
is determined by knowing the incremented PC and knowing the memory address, and solving the 
equation:

memory address = incremented PC + sign-extended offset.

When the program is actually executed, the computer sign-extends the 9 bit offset, and adds
it to the incremented PC to obtain the memory address that is required by the instruction.

Hope all this helps.

Good luck getting the program done on time.


Yale Patt