HCS12 Full Chip Simulation, STD writing 'uu' to memory instead of registers A:B value. Why?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS12 Full Chip Simulation, STD writing 'uu' to memory instead of registers A:B value. Why?

Jump to solution
1,058 Views
frmdstryr
Contributor I

Hi folks,

 

I'm writing a lab assignment for my class but cant figure out why this writes 'uu' instead of the register values.

 

Registers have A = 00, B = 41 when stepping through.

      
save:
   STD 2,SP+ ; Store the value in the Result array, then increment
   

I know uu means not initalized, but what does that mean??

 

Thanks!

Jairus

Labels (1)
Tags (1)
0 Kudos
1 Solution
671 Views
kef
Specialist I
  • I'm trying to iterate through two equal length arrays and add the corresponding elements and save the sums in another array (see the attached main.asm). This means I need 3 registers (or 2 registers and a word in memory) to keep track of where I'm currently at in each array.

Like I said, simulator treats locations below SP as undefined. This is very useful to detect problems in real life applications. On access to such uu variable, simulator can stop execution and tell you where your application reads undefined or uninitialized data. You have no such luxury debugging on real hardware. Yes, you may use your code as is on real hardware. It should work, provided interrupts are disabled.

 

For your app it's enough to have only 2 index registers. Like I said, since input arrays are of the same size, you need only 1 index regsiter to access elements of both arrays [i] and [i+sizeof(first array)]. Even if arrays are not close to each other, or A2 is allocated below A1, it should work.

You also couldd stop using additional memory for Count. Instead of determining array size, which is compile time constant in your case, you could check if index register reached end of array or not. See attached

 

 

 

View solution in original post

0 Kudos
4 Replies
671 Views
kef
Specialist I

In this context uu is undefined. I like this feture of CW simulatior very much.

STD 2,SP+ is not useful for real life applications. Almost every real life application uses interrupts. With interrupts enabled, what is below address pointed by SP is undefined since interrupt entry/exit will overwrite locations below SP.

Yes, you could use all 3 index registers (X,Y and SP) to do some smart application intialization, while interrupts are not yet enabled, but this is exception where CW simulator makes bad job for you.

In your case, since size of array A1 and A2 is known and one array immediately follows another, you could use single index register to access both arrays like this

 

   LDAB 1,X+

   ADDB A2-A1,X

   INX

 

If you insist using SP and simulator, you could iterate through array in reverse direction, from higher addresses towards lower addresses "pushing data to stack".

0 Kudos
671 Views
frmdstryr
Contributor I

I'm trying to iterate through two equal length arrays and add the corresponding elements and save the sums in another array (see the attached main.asm). This means I need 3 registers (or 2 registers and a word in memory) to keep track of where I'm currently at in each array. 

 

I used the method you stated above for iterating through the two arrays, but I need a way to keep track of the resulting array.

 

The assigment was a lab that we did prior to learning how to use the stack, so i'm not supposed to really be pushing an address into the stack.  In this situation, the stack would be the correct thing to use?

 

Thanks again!

0 Kudos
672 Views
kef
Specialist I
  • I'm trying to iterate through two equal length arrays and add the corresponding elements and save the sums in another array (see the attached main.asm). This means I need 3 registers (or 2 registers and a word in memory) to keep track of where I'm currently at in each array.

Like I said, simulator treats locations below SP as undefined. This is very useful to detect problems in real life applications. On access to such uu variable, simulator can stop execution and tell you where your application reads undefined or uninitialized data. You have no such luxury debugging on real hardware. Yes, you may use your code as is on real hardware. It should work, provided interrupts are disabled.

 

For your app it's enough to have only 2 index registers. Like I said, since input arrays are of the same size, you need only 1 index regsiter to access elements of both arrays [i] and [i+sizeof(first array)]. Even if arrays are not close to each other, or A2 is allocated below A1, it should work.

You also couldd stop using additional memory for Count. Instead of determining array size, which is compile time constant in your case, you could check if index register reached end of array or not. See attached

 

 

 

0 Kudos
671 Views
frmdstryr
Contributor I

Okay, I understand what you were saying now.  That's so much more efficient than what my teacher had shown our class!

 

Thanks!

0 Kudos