Help with example (assembly language)

Thread Starter

magic smoke

Joined Apr 2, 2012
2
Hope someone could help me explain some assembler. The picture attached is an example and is complete. The line

LDW.D1 *+A4[0x1],A8 ; Increment the address A4 by 1 and load A8 with the value

My question is what is the value of A4 after being incremented?
 

Attachments

Last edited:

Papabravo

Joined Feb 24, 2006
21,159
The only answer that makes sense to me is for an increment of +1 to represent a word holding a single precision floating point number consisting of four bytes. In this interpretation A4 will be incremented to the contents of A4 plus 4.
 

WBahn

Joined Mar 31, 2012
29,978
It will be whatever the instruction set being used specifies that it will be (and, if it doesn't specify a result for this particular chain of operations, then it will be unspecified and could be anything).

I'm not being flip with this answer. For example, if asked what the result in C would be in the case C = A + B (say all three are 8-bit signed integers to keep it easy) and A=100 and B=50. Ignoring the finite width, the answer should be 150. But this exceeds the maximum positive value of 127 that most implementations can deal with. So does the result end up being the same bit pattern as 150 (and which would be interpretted as -156)? Or would the result be 127 (as a result of clipping at the largest value representable on the basis of this representing the smallest error)? Or would the result be whatever what is the C beforehand (as a result of saying that if you can't store a correct value, don't store anything at all)? In fact, there are instruction set architectures that take each of these approaches while others leave the behavior completely unspecified.

In this case, it is unclear that the contents of A4 would be changed at all. For instance, what if (in C) you had:

x = b[y+1];

and ask what the value of y is after being incremented. Well, y was never changed. The incremented value (y+1) was the result of an arithmetic computation and the result was used in further evaluating the expression.

But consider

x = b[++y];

Now the value of y will change.

My recommendation would be to either dig into the language specification (which probably is reasonably tame for the TMS320xxx) or to match up sections of the code to the operations described at the top of the figure and work out what the behavior needs to be in order for it to produce the desired result.

My leaning is that A4 is not changed since we know that points to a section of memory with three values. Looking at the code, you see A4[0x1] three times and A4[0x2] once. If A4 were being changed each time, you would be accessing values beyond the data structure that was passed to the function. Hence, I would say that A4 is the address of the x value, A4[0x1] is the address of the y value, and A4[0x2] is the address of the z value.
 
Last edited:
Top