Solved

Motorola familiarity helpful, 68HC12 instruction question

Posted on 2004-03-29
1
239 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
When rebooting a vCenters 6.0 and try to connect using vSphere Client we get this issue "Invalid URL: The hostname could not parsed." When we get this error we need to do some changes in the vCenter advanced settings to fix the issue.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now