Solved

Motorola familiarity helpful, 68HC12 instruction question

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert from C to MIPS 14 1,334
Problems and Best Bios settings for i5 2500K on a Asus P8P67-M Motherboard 74 1,017
query on ldd in Linux 16 567
BufferBomb Phase 0 4 1,335
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
A Short Story about the Best File Recovery Software – Acronis True Image 2017
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

15 Experts available now in Live!

Get 1:1 Help Now