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
Solved

Motorola familiarity helpful, 68HC12 instruction question

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
How to start solving phase 4 of binary bomb 12 5,567
Creating EXE from Assembly Code 13 774
wrong referenced assembly version  (using VS 2008) 3 218
Crystal Report for VS2013 17 129
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?

839 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