two symbols with the same address!!

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

two symbols with the same address!!

bader
This post was updated on .
my code works but i think i did not fully understand!!

what i understant is:
in theimplementation part at stage 2, in first pass:
1) i have saved the predefiend symbols with their addresses (18 addresses in total 0-15 ,16384 and 24576).
2) i have saved the L_COMMANDS associated with the current ROM address in the same symbol table.

its true that in both cases i'v saved the pairs in the same table.. but they demonstrate different things:
1) i save the memory location of the symbol(or variable - pass2) RAM[address] <-> M[address].
2) i save the ROM address of the associated L_COMMAND. which is tottaly different than the above.

conclusion: its ok that there is: pair1 <L_COMMAND, address1> and  pair2 <variable, address2>
where:   ROM address ==  address1 == address2 == memory location.
example: <loop, 2> and <R2,2>.

and here comes my problem: if the my conclusion is correct why what is written in section 6.1 holds :

""note that the variable allocation assumption implies that the largest program that we can run is 1,024 instructions
long. Since realistic programs (like the operating system) are obviously much larger,
the base address for storing variables will normally be much farther""
 


its confusing cuz if the L_COMMANDS addresses and the variable addresses can intersect, does it really matter which address do we start saving variables. i think the main thing that they are saved in consecutive memory blocks. right ??!!!

correct me if i'm wrong, i feel that i'm missing something.
----->i got two symbols with the same address value but not the same address (one as a ROM and the other as a RAM)


a help would be appreciated, thanks
bader.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: two symbols with the same address!!

cadet1620
Administrator
bader wrote
conclusion: its ok that there is: pair1 <L_COMMAND, address1> and  pair2 <variable, address2>
where:   ROM address ==  address1 == address2 == memory location.
example: <loop, 2> and <R2,2>.
Your conclusion is correct; it's OK for ROM and RAM symbols with the same address to be stored in the symbol table.
and here comes my problem: if the my conclusion is correct why what is written in section 6.1 holds :

""note that the variable allocation assumption implies that the largest program that we can run is 1,024 instructions
long. Since realistic programs (like the operating system) are obviously much larger,
the base address for storing variables will normally be much farther""
 
This comment applies to computers that store both program code and data in RAM. In that case, if the variables were allocated at addresses that conflicted with where the program is stored, writing to the variables would change the program.

Since the Hack computer has separate code ROM and data RAM the differentiation between code and data addresses only occurs when they are used.
    @FOO
    M=D     // uses FOO as a RAM address

    @FOO
    0;JMP   // uses FOO as a ROM address
It is up to the programmer to make sure that he uses the symbol FOO correctly.

its confusing cuz if the L_COMMANDS addresses and the variable addresses can intersect, does it really matter which address do we start saving variables. i think the main thing that they are saved in consecutive memory blocks. right ??!!!
The reason to start allocating allocating RAM variables at 16 is so that RAM addresses 0-15 are reserved for special uses.  The SP, LCL, etc. symbols will make more sense when you get to the Virtual Machine chapter.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: two symbols with the same address!!

bader
thanks alotttttt :).
Loading...