CPR E 281x/282x - Lab 11b
Mixed
C & Assembly Programming
1. Objectives
In this lab you will write a
C & assembly program in PowerPC.
1.1
Reference Files for Lab
Lab Evaluation Form
2. Prelab
Before you come to lab it would
be good to understand how to setup, declare, and use structures. Also, it would be good to understand the EABI
guidelines, e.g. how to pass parameters in mixed coding. You can find information on all of these
topics in the following documents:
PowerPC
Manual
PowerPC Quick
Reference
EABI Guidelines
3. Mixed C & Assembly Program
Write a program that will
add two 64-bit numbers and display the resulting number on the QTerminal. You will need to use a struct in C to
represent a 64-bit number, (upper and lower halves). You will need to write an assembly function
to perform the addition. To test your
program, add the numbers 0x2031425364758698
and 0xF0F0F0F0F0F0F0F0.
Hints:
- When adding the lower 32 bits of the two
numbers, you need to generate a carry, and then use this carry in the
addition of the upper 32 bits.
There are assembly instructions to do this.
- The assembly function should have 3 parameters,
each a pointer to a struct (2 for operands, 1 for result). Your assembly function should not have
any return value.
- To be able to call your assembly function from
your c code, do the following:
- In the assembly, include the line .export function_name at
the beginning of the assembly file (where function_name is the name of your assembly function).
- Also in assembly, include the line .function “function_name”, PPC_Start_Asm, PPC_End_Asm (where
PPC_Start_Asm and PPC_End_Asm at the beginning and end of your assembly
function).
- In the c code, include the line extern void function_name(function_parameters);
This
will allow the assembly function to be called just as you would a regular c
function (you will not use JumpAsm).
- To print to the Q-Term, you will need to first
format the result of the addition into a string using sprintf, then use
LCD_PutString to print out the string.
For examples, see lab 1a.