|
|
Here in the textbook, it says the RAM is divided into three major spaces i.e
RAM (from address 0 - 16383) 16Kb
SCREEN (from address 16384 - 24575) 8Kb
KEYBOARD (address 24576) 1 Byte
Total 24576 Bytes
but if we consider 15 bits of address then the maximum memory that is addressable is 32767
So the first question is, why are we not using 32767 - 24576 = 8191 bytes?
The RAM(16383 bytes) is again compartmentalized into memory segments i.e
RAM address Usage 0-15 sixteen virtual registers
16-255 Static variables
266-2047 Stack
The second question is from 2048 to 16383, What are we using this space for?
(Continuing....)
The sixteen virtual registers are as follows:
SP RAM[0]
LCL RAM[1]
ARG RAM[2]
THIS RAM[3]
THAT RAM[4]
TEMP RAM[5-12]
R13 RAM[13]
R14 RAM[14]
R15 RAM[15]
SCREEN RAM[16384]
KBD RAM[24576]
When writing an assembler I have initialized the predefined symbol Table from RAM[5-20] as R0 to R15
but first five segments are the same, but for writing Virtual machine code we are again segmenting the same space into TEMP, R13,R14 and R15 why is that?
Also, the sample assembly programs provided to test our own assembler make use of:
@R0 and @R1, so the question is if our virtual machine commands make use of TEMP then how would it be mapped to the assembly code, for example, if I use TEMP[6] then the same RAM space in assembly code is @R1 or R14 for @R13 in assembly code.
Please correct me if I have understood the concept in the wrong manner!
|
Administrator
|
The reason we are not using the full memory space addressable with 15 bits is for simplicity of implementation (i.e., to make your life easier). The hiccup is the one-work Keyboard interface and carving that out of that final 8K block. There were other alternatives that could have been considered (and I probably would have gone with one of them), but the current memory organization is sufficient for the needs of the project.
The memory from 2048 to the start of the screen buffer is known as the "heap" and is for dynamically allocated memory objects.
The mistake you are making is that R0 through R15 are to map to RAM[0] through RAM[15]. Look at the conflict your mapping creates. The virtual register list that you reference specifically maps R13, R14, and R15 to RAM[13], RAM[14], and RAM[15]. But your predefinitions map them to RAM{18], RAM[19], and RAM[20]. But these RAM locations are in the memory space reserved for static variables (in the Virtual Machine).
For pure assembly language programs, the only named registers are R0 to R15, SCREEN, and KBD. The other names have meaning for the Virtual Machine and its implementation. In the VM, R0 through R4 are given additional, more meaningful, names. So R0 and SP both refer to RAM[0], but in the VM implementation, only SP should be used for readability.
|
|
Okay, can I put it this way:
SP or R0 is RAM[0]
LCL or R1 is RAM[1]
ARG or R2 is RAM[2]
THIS or R3 is RAM[3]
THAT or R4 is RAM[4]
TEMP or R5 to R12 is RAM[5-12]
R13 is RAM[13]
R14 is RAM[14]
R15 is RAM[15]
RAM[16] to RAM[255] is for static variables
RAM[256] to RAM[2047] is for stack
RAM[2047] to RAM[16383] is heap
RAM[16384] toRAM[24575] is screen
RAM[24576] is for Keyboard
in the case of pure assembly language R0 to R15 are used to refer to memory locations from RAM[0] to RAM[15] but in the case of VM language R0 to R4 are been alised to segments SP, LCL, ARG, THIS, and THAT also R5 to R12 is been alised to TEMP segments and R13, R14, R15 are used as scratchpad memory.
|
Administrator
|
Correct except for a typo -- the heap starts at RAM[2048].
|
|