I am trying to write a program to calculate the exponent of a number using the ARM-C interaction. I am using LPC1769 (cortex m3) for deduplication. Below is the code:
#include<stdio.h> #include<stdlib.h> extern int Start (void); extern int Exponentiatecore(int *m,int *n); void print(int i); int Exponentiate(int *m,int *n); int main() { Start(); return 0; } int Exponentiate(int *m,int *n) { if (*n==0) return 1; else { int result; result=Exponentiatecore(m,n); return (result); } } void print(int i) { printf("value=%d\n",i); }
this is assembly code that complements the above C code
.syntax unified .cpu cortex-m3 .thumb .align .global Start .global Exponentiatecore .thumb .thumb_func Start: mov r10,lr ldr r0,=label1 ldr r1,=label2 bl Exponentiate bl print mov lr,r10 mov pc,lr Exponentiatecore: // r0-&m, r1-&n mov r9,lr ldr r4,[r0] ldr r2,[r1] loop: mul r4,r4 sub r2,
however, during a debugging session, I encounter a Hardfault error to execute "Exponentiatecore (m, n)".
as shown in the debug window.
Name : HardFault_Handler Details:{void (void)} 0x21c <HardFault_Handler> Default:{void (void)} 0x21c <HardFault_Handler> Decimal:<error reading variable> Hex:<error reading variable> Binary:<error reading variable> Octal:<error reading variable>
Am I doing some stack damage during alignment or is there an error in my interpretation? Please kindly help. early