pointers - pass by reference in assembly -
Using ARM-C inter-work, I am trying to write a program to calculate the number of exponentials I am I am using LPC 1769 (Cortex M3) for DBUugging. The following code is:
/ * Here is the main.c file * / #include & lt; Stdio.h & gt; #to & lt include, stdlib.h & gt; External int start (zero); Extension in Exponentcore (Int * M, Int * N); Zero print (int i); Int exponent (int * m, int * n); Int main () {start (); Return 0; } Int exponent (int * m, int * n) {if (* n == 0) returns 1; Else {int results; Results = Exponentiatecore (M, N); Return (results); }} Zero print (int i) {printf ("value =% d \ n", i); } This assembly code that meets the above c code
.yntax integrated Cpu cortex-m3 Thumb .align .global start .global exponentcore Thumb Thumb_Funk start: mov r10, lr ldr r0, = label 1 ldr r1, = label2 bl exponentiate bl print mov lr, r10 mov pc, lr exponentiatecore: // r0- and m, r1- and n mov r9, lr ldr r4, [R0] ldr r2, [r1] loop: mul r4, r4 sub r2, # 1 bne loop mov r0, r4 mov lr, r9 mov pc, lr label 1: .word 0x02 label 2: .word 0x03 However during the debug session, I got a hard error for executing "Exponentcore (M, N)".
As seen in the debug window.
Name: Hardfault_handler Description: {Zero (zero)} 0x21c & lt; HardFault_Handler & gt; Default: {Zero (zero)} 0x21c & lt; HardFault_Handler & gt; Decimal: & lt; Error reading variable; Hex: & lt; Read error & gt; Binary: & lt; Error reading variable & gt; Auctioneal: & lt; Error reading variable & gt; Am I doing some stack corruption during alignment or is there any mistake in my interpretation? Please help please Thankyou in advance
There are several problems with your code First, you have an infinite Loop because your subdirectory is not setting the flag. Change it to SUBS The next problem is that you are unnecessarily manipulating the LR register. You do not call other functions from Exponentcore, so do not touch LR. The last instruction of the function to return to the caller should be "Bx LR". Problem # 3 is that your multiplication instruction is wrong. In addition to taking 3 parameters, if you multiply the number by you, then it will grow very fast, for example:
Exponentialcore (10, 4);
Values through each loop:
R4 = 10, n = 4 = R4 = 100, n = 3 = R4 = 10000, N = 2 = R4 = 100,000,000 N = 1
< / P>
The problem # 4 is that you are changing a non-volatile register (R4). If you do not save / restore them, you are only allowed to leave R0-R3 garbage, try it again:
Start: stmfd sp !, {lr} ldr r0, = Label1 ldr r1, = label2 bl exponentiatecore // red print ldmfd sp! PC} Exponentiatecore: // r0- & amp; M, r1- & amp; 0 shiftq r0, # 1 LEFT PC, LR / initial exit loop for the special value of ldr r0, [r0] mov r2, r0 ldr r1, [r1] cmp r1, # 0/0: mul r0, r0, r2 // Multiply the original value by n times subs r1, r1, # 1 bne loop bx lr
Comments
Post a Comment