|
|
  |
Не получаеся вернуться из функции из в ASM коде для ARM7 |
|
|
|
Apr 8 2009, 05:15
|
Местный
  
Группа: Участник
Сообщений: 206
Регистрация: 12-10-06
Из: ufa
Пользователь №: 21 241

|
Я привел кусок АСМ-кода, вызывающего функцию reverse5. По завершению ф-ии reverse5 делаю возврат: mov r15,r14. Но похоже возврата не происходит.. Почему? ;------------------------------------------------------------------------------- reverse5: ldr r5,=0x10 mov r4,r7 and r4,r4,r5 movs r5,r4,LSR#4 ;b[0] = (x & 0x10) >> 4, ãäå r7=x ldr r4,=0x1 and r5,r5,r4 ;b[0] = b[0] & 0x1 str r5,[r13,#30] ldr r5,=0x8 mov r4,r7 and r4,r4,r5 movs r5,r4,LSR#2 ;b[1] = (x & 0x8) >> 2, ãäå r7=x ldr r4,=0x2 and r5,r5,r4 ;b[1] = b[1] & 0x1 str r5,[r13,#31] ldr r4,=0x4 and r5,r7,r4 ;b[2] = x & 0x4 str r5,[r13,#32] ldr r5,=0x2 mov r4,r7 and r4,r4,r5 movs r5,r4,LSL#2 ;b[3] = (x & 0x2) << 2, ãäå r7=x ldr r4,=0x8 and r5,r5,r4 ;b[3] = b[3] & 0x8 str r5,[r13,#33] ldr r5,=0x1 mov r4,r7 and r4,r4,r5 movs r5,r4,LSL#4 ;b[4] = (x & 0x1) << 4, ãäå r7=x ldr r4,=0x10 and r5,r5,r4 ;b[4] = b[4] & 0x10 str r5,[r13,#34] ldr r4,[r13,#30] ldr r5,[r13,#31] and r7,r4,r5 ldr r4,[r13,#32] ldr r5,[r13,#33] and r7,r4,r5 ldr r5,[r13,#34] and r7,r7,r5 ;x = b[0]|b[1]|b[2]|b[3]|b[4] mov r15,r14 ;load LR into PC (r15) [causing a return] ;-------------------------------------------------------------------------------
Main: mov r7,r11 B reverse5
|
|
|
|
|
Apr 8 2009, 08:35
|
Местный
  
Группа: Участник
Сообщений: 206
Регистрация: 12-10-06
Из: ufa
Пользователь №: 21 241

|
Цитата(meister @ Apr 8 2009, 12:27)  Если мне не изменяет мой склероз, то возврат из "функции" делается BX lr, а вызов BL label. BX и BL не помогли. Разве при переходе BL содержимое PC запоминается?
|
|
|
|
|
Apr 8 2009, 08:39
|

Местный
  
Группа: Участник
Сообщений: 219
Регистрация: 20-11-07
Пользователь №: 32 484

|
Цитата(Bulat @ Apr 8 2009, 12:35)  BX и BL не помогли. Разве при переходе BL содержимое PC запоминается? Как бы есть "ARM Instruction Set", там написано: Код Branch with Link (BL) writes the old PC into the link register (R14) of the current bank. The PC value written into R14 is adjusted to allow for the prefetch, and contains the address of the instruction following the branch and link instruction. Note that the CPSR is not saved with the PC and R14[1:0] are always cleared. To return from a routine called by Branch with Link use MOV PC,R14 if the link register is still valid or LDM Rn!,{..PC} if the link register has been saved onto a stack pointed to by Rn.
|
|
|
|
|
  |
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0
|
|
|