Help with ARM asm issue

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 1
Reputation: luken8r is an unknown quantity at this point 
Solved Threads: 0
luken8r luken8r is offline Offline
Newbie Poster

Help with ARM asm issue

 
0
  #1
Nov 4th, 2008
Im modifing an assembly module to add a branch to a new C function but I cant seem to get it working right. My stack is crashing and I cant track it down because, unfortunately, I dont have an emulator

The original asm file is a 16 bit signed division library that just jumps to a 32 bit library to do the divide. Im trying to add a branch to a C function in here but it keeps crashing on me. Heres the original:

  1.  
  2. .state16
  3.  
  4. .global I$DIV
  5. .global I_DIV
  6.  
  7. dvs .set r2 ; WORK COPY OF THE DIVISOR (SHIFTED)
  8. quo .set r3 ; WORK COPY OF THE QUOTIENT
  9. negs .set r4 ; SAVED COPY OF THE SIGNS
  10.  
  11. I$DIV:
  12. PUSH {lr}
  13.  
  14. NOP
  15. BX pc ; Change to 32-bit state
  16. NOP
  17. .align
  18. .state32
  19. BL I_MOD
  20. ADD lr, pc, #0x1
  21. BX lr
  22. .state16
  23. POP {pc}
  24.  
  25. .end

This is just the standard library file that comes with my TI compiler. What I want to do is add a compare and if that compare is == 0, branch to a C file.

I wrote a C function to do what I want so I can see what the listing file looks like

  1. void brtodiv(ui16_t foo){
  2.  
  3. if (foo == 0){
  4. gohere(); // eventual target function
  5. }
  6. else{
  7. somefunct(); // some other place
  8. }
  9. test(foo);
  10.  
  11. }
  12.  
  13. void gohere(void){
  14.  
  15. volatile ui16_t addr = 272;
  16. volatile ui16_t foo = 0xffed;
  17.  
  18. Wrt2EEP(addr,foo);
  19.  
  20. }

Nice and easy

The resulting list file looks like this

  1. 198 ;*****************************************************************************
  2. 199 ;* FUNCTION NAME: $brtodiv *
  3. 200 ;* *
  4. 201 ;* Regs Modified : A1,A2,A3,A4,V9,SP,LR,SR *
  5. 202 ;* Regs Used : A1,A2,A3,A4,V9,SP,LR,SR *
  6. 203 ;* Local Frame Size : 0 Args + 0 Auto + 4 Save = 4 byte *
  7. 204 ;*****************************************************************************
  8. 205 0000002a $brtodiv:
  9. 206 0000002a B500 PUSH {LR}
  10. 207 0000002c 2800 CMP A1, #0 ; |1155|
  11. 208 0000002e D101 BNE L1 ; |1155|
  12. 209 ; |1155|
  13. 210 00000030 F7FF BL $gohere ; |1156|
  14. 00000032 FFE6
  15. 211 ; |1156|
  16. 212 00000034 L1:
  17. 213 00000034 F7FF BL $test ; |1161|
  18. 00000036 FFF1

Push the LR to stack, do the comparison, if not equal do some stub function, if equal, branch to my target routine

So I tried this in my asm file but no dice.

  1. I$DIV:
  2. PUSH {lr}
  3. CMP R1, #0
  4. BNE L1
  5.  
  6. BL $gohere
  7. L1:
  8. <original code>
  9.  
  10. .end

So as a test, I removed the call to Wrt2EEP(addr,foo); in the gohere() routine and it didnt crash on me. This function is going to write some code foo to an address in EEPROM. Anyway, because this didnt crash, its obviously killing the stack. What am I not passing to the stack from my assembly file?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC