Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am trying to write a program to calculate the exponential of a number using ARM-C inter-working. I am using LPC1769(cortex m3) for debuuging. The following is the code:
 /*here is the main.c file*/
 
/*function prototypes*/
#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=NULL;
        result=(int *)malloc(sizeof(int));
        *result=Exponentiatecore(m,n);
        return (result);
    }
 
}
 
void print(int i)
{
printf("value=%d\n",i);
}
 
/*end of C file */
 
this is the assembly code which 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
		ldr r0,[r0]
		bl print
		mov lr,r10
		mov pc,lr
 
Exponentiatecore:          // r0-&m, r1-&n
ldr r0,[r0]
mov r2,r0
ldr r1,[r1]
 
loop:
mul r2,r0
subs r1,#1
bne loop
mov r0,r2
bx lr
 
label1:
.word 0x02
 

label2:
.word 0x03
 

however during the debug session, I encounter a Hardfault error for the execution of "Exponentiatecore(m,n)". During the first branch from assembly to C i.e. BL Exponentiate-- LR is saved. Again during second branch to assembly routine Exponentiatecore(m,n) LR is over written. This is the line I am facing the hardfault error. Any suggestions are appreciated.
 
as seen in 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 making some stack corruption during alignment or is there a mistake in my interpretation? please kindly help. thankyou in advance
Posted 22-Mar-13 9:41am
Edited 22-Mar-13 9:46am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is not my area of expertise, so if I am being misled by a syntax that I don't really understand, please ignore me.
 
With that in mind, my question is: Where does this line take you ?
bl Exponentiate
  Permalink  
Comments
Venkatesh Kuppan at 23-Mar-13 2:11am
   
bl exponentiate will take you to the C function Exponentiate(int *m,int *n); Registers r0 and r1 will have the contain the paramenters

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100