pointers/arrays in asm

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

pointers/arrays in asm

Marty Billingsley
Having trouble implementing arrays/pointers in assembly language. Seems like I had this figured out at one point a couple of years ago, but am stumped now.
Example: x[i] = 23
You need to arrive at the point where 23 is in the D register, and value x + what is in memory location i is in the A register.  
Is there a way to do this without using a temporary variable?  (I end up with x+M[i] in D and 23 in A, and need to swap them.)
Reply | Threaded
Open this post in threaded view
|

Re: pointers/arrays in asm

ybakos
Hmmm... something like AD=D+M ?


Reply | Threaded
Open this post in threaded view
|

Re: pointers/arrays in asm

cadet1620
Administrator
In reply to this post by Marty Billingsley
Marty Billingsley wrote
Having trouble implementing arrays/pointers in assembly language. Seems like I had this figured out at one point a couple of years ago, but am stumped now.
Example: x[i] = 23
You need to arrive at the point where 23 is in the D register, and value x + what is in memory location i is in the A register.  
Is there a way to do this without using a temporary variable?  (I end up with x+M[i] in D and 23 in A, and need to swap them.)
The only way to get the constant into D is @constant; D=A, so you must have the computed target address in memory so that you can load it into A.  R13-R15 are reserved as temporary variables for this purpose.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: pointers/arrays in asm

Marty Billingsley
Thanks! That answers my question. You DO need to use a temporary storage space in memory, and R13-R15 are supposed to be used for that purpose.