1

Hi guys I'm developing this program and its main purpose is like a find_min function. Here is the main function:

int main(void)
{
    int i;
    int dij[T][N]={{9,5,7,8}, //T and N are defined as 3 and 4 in this case
                   {7,9,6,9},
                   {10,8,8,7}};
    int Dj[T][N]={{17,23,14,15},
                  {18,19,18,14},
                  {19,22,17,16}};

    int n_res[T][2]={{N,0},
                     {0,0},
                     {0,0}};

    // Call assembly language function
    distrBF(T,(int*)n_res,(int*)dij,(int*)Dj);
    for ( i=0; i<T ; i++ )
        printf("%d %d\n", n_res[i][0], n_res[i][1]);
    volatile static int loop = 0;
    while (1) {
        loop++;
    }
}

And here is the distrBF.s:

distrBF:
PUSH {R14}
LDR R6,[R1]
MOV R9,R6
LOOP: LDR R4,[R2],#4
      LDR R5,[R3],#4
      ADD R8,R4,R5
      @MOV R10,#1
      SUBS R6,#1

FindMin: PUSH {R2-R3}
     BL ELEMENT
     MOV R5,R4
     BL ELEMENT
     ADD R7,R5,R4
     CMP R7,R8
     ITTT MI
     MOVMI R8,R7
     SUBMI R10,R9,R6
     ADDMI R10,#1
     ADD R2,#4
     ADD R3,#4
     SUBS R6,#1
     BNE FindMin
     STR R8,[R1],#4
     STR R10,[R1],#4
     MOV R6,R9
     SUBS R0,#1
     BNE LOOP
     POP {R14}
     BX LR

@ Subroutine ELEMENT
ELEMENT:
    POP {R4}
    LDR R4,[R4]
    BX LR
    NOP
    .end

The program is to find the smallest (dij+Dj) for each row. I traced my program step by step, and all the registers contain the correct value along the way. (n_res should be {21,3,23,4,23,4} for output) But after it returns to main.c and executes the 'for' statement, it will go into a HardFault_handler. It says that there's an ImpreciseErr error, but I don't know how to solve this.

artless noise
  • 21,212
  • 6
  • 68
  • 105
richards
  • 517
  • 9
  • 27

0 Answers0