Solved

Motorola familiarity helpful, 68HC12 instruction question

Posted on 2004-03-29
1
240 Views
Last Modified: 2011-09-20
I am trying to develop a lab illustrating how C++ cross-compiles into fairly 'inefficient' assembly code, rather than writing directly in assembly.  I wrote the following example program and cross-compiled it using a GNU 68HC12 (ver. 3.0.4) compiler:

int main (void)
{

int first = 4;
int second = 5;
int third = 6;

int final = first + second + third;

return 0;

}

The first five assembly instructions are the following:

movw_.frame,2,-sp
leas -16,sp
sts_.frame
ldy_.frame
movw#4,2,y

After quite a bit of searching, I have found out that the frame is a part of the stack used for parameters and local storage of variables and is only used with high-level languages, but I have not been able to find anything referencing how it is used/accessed.  I have come up with less than that on the MOVW instruction being used with three parameters.  

If anyone has any insight to how the frame works, the notation used, or the use of MOVW with three parameters, I would greatly appreciate it.

0
Comment
Question by:Baskanavitch
1 Comment
 
LVL 22

Accepted Solution

by:
grg99 earned 500 total points
ID: 10713024

The stack is often used to store local variables. If you declare three local variables, as you did in -main-,
the compiler subtracts 3*the size of an int from the stack pointer, that reserves space for those variables.
Most CPU's have an instruction addressing mode of sp+xxxx, so those local variables can be accessed with addressing upwards from SP.
This same addressing mode can access any parameters pushed onto the stack.  At function exit, a simple "add sp,yyyy", will deallocate all the local variables.

sing the stack in this way makes for a nice general way to allocate variable space. The downside is some short functions can sometimes keep all the local variables in registers, so using the stack is a bit less efficient.  Some compilers will optimize away stack variables if they realize the function can do without them.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Google always has something new and amazing up its sleeve, and the most current thing that they have been working on is another step in the evolution of Google Search, from machine learning to its brilliant successor, deep learning.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question