реклама на сайте
подробности

 
 
> Вопрос по ассемблеру ARM, Не пойму как расчитывается смещение
NeDoEng
сообщение May 17 2016, 09:26
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 16
Регистрация: 17-04-16
Пользователь №: 91 333



Вот, например, запускаю симулятор и смотрю дизассемблер startup_stm32f10x_md.s

Строку 133: LDR R0, =SystemInit
компилятор разворачивает в строку:

0x0800016C 4809 LDR r0,[pc,#36] ; @0x08000194
Это значит, что будет загружено в R0 значение из памяти по адресу PC+36. И в данный момент PC = 0x0800016C.

НО!
0x0800016C+36 = 0x08000190. Хотя компилятор в комментарии указывает другой адрес - на 4 байта больше. И в самом деле обращение идет по адресу 0x08000194. Как получилась такая разница? Сначала инкрементируется счетчик команд на 4 (переход к след. команде), а потом выполняется сложение и пр?
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
obi wan
сообщение Jun 15 2016, 13:31
Сообщение #2





Группа: Участник
Сообщений: 5
Регистрация: 26-02-13
Пользователь №: 75 792



The Definitive Guide to the ARM Cortex-M3 by Joseph Yiu Chapter 3
"Program Counter R15
R15 is the program counter. You can access it in assembler code by either R15 or PC. Due to
the pipelined nature of the Cortex-M3 processor, when you read this register you will find that
the value is different than the location of the executing instruction by 4. For example:
0x1000 : MOV R0, PC ; R0 = 0x1004
Writing to the program counter will cause a branch (but link registers do not get updated).
Since an instruction address must be half word aligned, the LSB (bit 0) of the program
counter read value is always 0. However, in branching, either by writing to PC or using branch
instructions, the LSB of the target address should be set to 1 because it is used to indicate
the Thumb state operations. If it is 0, it can imply trying to switch to the ARM state and will
result in a fault exception in the Cortex-M3."
Наверно в тему.
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 20th July 2025 - 09:43
Рейтинг@Mail.ru


Страница сгенерированна за 0.01361 секунд с 7
ELECTRONIX ©2004-2016