Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Motorola familiarity helpful, 68HC12 instruction question

Posted on 2004-03-29
1
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
grg99 earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The online market is growing at an unprecedented rate and retail eCommerce sales are expected to reach $4 trillion by 2020. Yet, the profit is not just there for the taking because you have to set yourself apart from the competition.
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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