0

I would like to know how do I get access to the data contained at a specific address given that the address has been stored as a data at another address in a variable (sort of indirect addressing) in little man computer (lmc)?

I was thinking of doing LDA twice, for instance LDA temp (to have the address that I want) then I need to do LDA of that address to get the data stored there. However, it is not working.

get  LDA temp
     LDA get
  • 1
    The only way to dereference a pointer on LMC is self-modifying code (where you rewrite the address that's part of the machine code for another load instruction). It doesn't have an indirect addressing-mode like a normal CPU. Your `lda` instructions are just two different loads into the accumulator, from an absolute address. – Peter Cordes Nov 27 '22 at 16:19
  • Does that mean that if I know that it is stored at address 90 for instance, I should do LDA 90 directly ? – bestgamer14 Nov 27 '22 at 16:22
  • @PeterCordes I am trying to get access to a memory location given the input of the user. i.e there is an array starting at the address 60 and I need to output the data at location 60 + the input of the user. What I did is store the result in temp and now i need to get access to the data in temp. – bestgamer14 Nov 27 '22 at 16:24
  • Yes, if you know an absolute address, use it directly. You only need indirection to do things like looping over an array or indexing it with a run-time variable. ([How can I store an unknown number of inputs in different addresses in LMC (little-man-computer)?](https://stackoverflow.com/q/47346971) / [Programming arrays in LMC](https://stackoverflow.com/q/68265100)) – Peter Cordes Nov 27 '22 at 16:27
  • The basic ideas is that you create new instructions at runtime. This allows the instructions to vary, which can achieve the same as indexing. A simple approach to that is to make a prototype instruction, e.g. access the start of the array, and later in the loop, increment the instruction, so LDA 80 becomes LDA 81 in the next iteration, LDA 82, etc.. And other variations on that theme, such as summing an opcode with the mailbox number to create an arbitrary load or store. – Erik Eidt Nov 27 '22 at 16:33
  • @PeterCordes Ok, thanks for your help! I will try to figure out the indirection thing – bestgamer14 Nov 27 '22 at 16:35
  • @ErikEidt Ok given that my array starts at 60, I should do LDA 60, then have an etiquette (the "get" I put in the snippet), and increment it right? that it instead of using a variable(the "temp" I used) – bestgamer14 Nov 27 '22 at 16:38
  • 1
    Yes, just increment the instruction, for example and next time it executes it will be a different instruction! This requires load add store back, though the load, add, and store all have fixed build-time addresses, so themselves don't need indirection. – Erik Eidt Nov 27 '22 at 16:39
  • And other variations on the scheme for arbitrary indexing rather than linear indexing: Store, as data an `LDA 60` (as data it is a 560). Then load that data item, 560, add an index, e.g. 4, to it (e.g. 560+4=564 which is `LDA 64`), and store it as an instruction somewhere in your upcoming instruction stream (leaving the `LDA 60` as data alone for later doing the same). – Erik Eidt Nov 27 '22 at 16:44
  • @ErikEidt Yes, I guess that will be much easier. Thanks a lot ! – bestgamer14 Nov 27 '22 at 17:07

0 Answers0