#include /* common defines and macros: file found in CodeWarrior folder */
#include "derivative.h" /* derivative-specific definitions (e.g.: PORTA, DDDRK) */
// datapage.c: Not mandatory in most cases.
// .h: list the functions and definitions. .c: specify the functions
/* Global Variables: */
unsigned int valu = 1024; // stored in $1100 (right after the Stack)
unsigned int result; // Where the value of the sum will also be stored
// Program starts at $C000
// Program: Given 10 16-bit unsigned numbers in an array, compute the sum. The sum has an initial value
// given by valu+cnst
// This is considered to be a Subroutine in the ASM Code:
void main(void) { // in Assembly code, this is treated as a SubRoutine
// Local Variables: they are placed in the Stack (Stack is empty at $1000, max. size is 0x100)
const unsigned int cnst = 20; // constants are like EQU in ASM code, they don't occupy memory
unsigned char array[10] = {0x35, 0xFF, 0xFE, 0x39, 0x35, 0x31,0x15, 0xFA, 0xEB, 0x34};
// unsigned char: unsigned integer of 1 byte. The 'char' attribute is only useful when using character
// manipulating functions.
unsigned int i, sum; // 16-bit numbers --> i, sum <= 65535
// Add numbers in the array
sum = valu + cnst; // this is just to illustrate how global variables and local constants work
// Adding the numbers in the array
for (i = 0; i < 10; i++) {
sum = sum + array[i];
}
asm ("ldd sum"); // inline Assembly instructions
asm ("movw sum,result"); // We know where to look for in result
// After this, the stack will be empty
}