Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Ассебмлер ARM
Форум разработчиков электроники ELECTRONIX.ru > Микроконтроллеры (MCs) > ARM
Dir
Не пинайте ногами только. Поиском искал ... но не нашел. Встал вопрос скорректировать startup для ADuC7128 и ... понеслось sad.gif

Вот сам код хорошо всем известного startup (v4.42a ... arm\examples\AnalogDevices\ADuC712x\InterruptBlinl\cstartup.s79):

Код
        MODULE    ?RESET
        COMMON    INTVEC:CODE:NOROOT(2)
        PUBLIC  __program_start
        EXTERN    ?cstartup
        EXTERN    undef_handler, swi_handler, prefetch_handler
        EXTERN    data_handler,irq_handler, fiq_handler
        CODE32; Always ARM mode after reset    
        org    0x00
__program_start
        ldr    pc,=?cstartup; Absolute jump can reach 4 GByte
        org    0x04
        ldr    pc,=undef_handler
        org    0x08
;        ldr    pc,=swi_handler
        org    0x0c
        ldr    pc,=prefetch_handler
        org    0x10
        ldr    pc,=data_handler
                org     0x14
                DCD     0x00000000
        org    0x18
        ldr    pc,=irq_handler
        org    0x1c
        ldr    pc,=fiq_handler

; Constant table entries (for ldr pc) will be placed at 0x20
        org    0x20
        LTORG
                ENDMO

Приведен только кусок до метки ?csartup. Но это не важно. Вопрос собственно вот какой: где найти систематизированное описание этого ассемблера? Причем и инструкций компилятора, и самих кодов. Сразу скажу, что help к IAR EWB и pdf Assemler Reference Manual оттуда же прочел. Прочел также ARM Arсhitecture Reference Manual (ARM DDI 0100E). И все равно много вопросов. Вот один из них:
Что такое, например, команда
Код
        org    0x18
        ldr    pc,=irq_handler

Смысл ее в общем то понятен. По этому адресу располагается команда перехода на обработку прерывания IRQ. Но что такое "=" перед irq_handler? Описания такого формата нигде не нашел. Может плохо искал?
Ладно, пусть это адрес irq_handler, который находится где-то в области памяти и этот вдрес получим только после работы линкера. Но почему этото слово должно находиться по адресу 0x18 + 0x20? Т.е. в какой собственно код транслируется эта команда? В формате команд ldr всегда присутствует кроме регистра назначения (pc) еще и регистр, содержащий базовый адрес, а также (часто) смещение. Наверное (мне так кажется) данная конструкция транслируется относительно какого-то базового регистра, содержащего "0" со смещением 0x20, но относительно какого регистра? Или я не прав? А если мне смещение нужно не 0x20, а 0x40, например?

PS. Ну, короче, нихрена я не пойму этой команды. Объясните, плиз.
DASM
Цитата
2.5.3 Loading with LDR Rd, =const
The LDR Rd,=const pseudo-instruction can construct any 32-bit numeric constant in a
single instruction. You can use this pseudo-instruction to generate constants that are out
of range of the MOV and MVN instructions.
The LDR pseudo-instruction generates the most efficient single instruction for a specific
constant:
• If the constant can be constructed with a MOV or MVN instruction, the assembler
generates the appropriate instruction.
• If the constant cannot be constructed with a MOV or MVN instruction, the assembler:
— places the value in a literal pool (a portion of memory embedded in the code
to hold constant values)
— generates an LDR instruction with a program-relative address that reads the
constant from the literal pool.
For example:
LDR rn, [pc, #offset to literal pool]
; load register n with one word
; from the address [pc + offset]
You must ensure that there is a literal pool within range of the LDR instruction
generated by the assembler. See Placing literal pools on page 2-30 for more
information.
See LDR pseudo-instruction on page 4-161 for a description of the syntax of the LDR
pseudo-instruction.

RV_asm.pdf
По-моему исчерпывающе
Слово это может находится совсем не обязательно по какому-то смещению
Грубо говоря
LDR pc, = метка
....
....
метка:
DCD entry
..............
...........
...........
entry:
Dir
Цитата(DASM @ Dec 14 2007, 23:30) *
RV_asm.pdf
По-моему исчерпывающе
Слово это может находится совсем не обязательно по какому-то смещению
Грубо говоря
LDR pc, = метка
....
....
метка:
DCD entry
..............
...........
...........
entry:


Спасибо. А где можно взять этот RV_asm.pdf? Это я так понял из комплекта RealView. А отдельно сей pdf есть где-нибуть? Или все-таки установить?
DASM
В Кейле лежит
Dir
Установил MDK-3.15. Pdf-файла, правда, нет, зато есть armasm.chm. Даже беглого обзора хватило, чтобы оценить, что наверное зря я из-за совместимости с AVR на IAR для ARM подсел. Документация у Keil явно лучше.
zltigo
Цитата(Dir @ Dec 14 2007, 23:25) *
Но что такое "=" перед irq_handler? Описания такого формата нигде не нашел. Может плохо искал?

Очень плохо искали sad.gif, точнее совсем не искали, поскольку непонятно, как можно не найти. В EWARM Assembler Refrence все это естественно есть:
Код
LDR (ARM) LDR{condition} register,=expression1
or
LDR{condition} register,expression2
Parameters
Description
The first form of the LDR pseudo-instruction loads a register with any 32-bit
expression. The second form of the instruction reads a 32-bit value from an address
specified by the expression. Note that there is also a true LDR instruction.
If the value of expression1 is within the range of a MOV or MVN instruction, the
assembler generates the appropriate instruction. If the value of expression1 is not
within the range of a MOV or MVN instruction, or if the expression1 is unsolved, the
assembler places the constant in a literal pool and generates a program-relative LDR
instruction that reads the constant from the literal pool. The offset from the program
location counter to the constant must be less than 4 Kbytes. See also the LTORG
directive in the section Assembler control directives, page 80, for more information.
Example
LDR r1,=0x12345678; => LDR r1,[pc,#4]
; loads 0x12345678 from the
; literal pool into r1
LDR r2,my_data; loads 0xFFEEDDCC into r2
; => LDR r2,[pc,#-4]
DATA
my_data DC32 0xFFEEDDCC
LTORG
condition An optional condition code.
register The register to be loaded.
expression1 Any 32-bit expression.
expression2 A program location counter-relative expression in the range -4087 to
+4103 from the program location counter.


LDR (CODE16) LDR register, =expression1
or
LDR register, expression2
Parameters
Description
As in ARM mode, the first form of the LDR pseudo-instruction in Thumb mode loads
a register with any 32-bit expression. The second form of the instruction reads a 32-bit
value from an address specified by the expression. However, the offset from the
program location counter to the constant must be positive and less than 1 Kbyte.
Example
LDR r1,=ext_label; => LDR r1,[pc,#8]
; loads ext_label from the
; literal pool into r1
NOP
LDR r2,my_data; loads 0xFFEEDDCC into r2
NOP; => LDR r2,[pc,#0]
DATA
my_data DC32 0xFFEEDDCC
LTORG
register The register to be loaded. LDR can access the low registers (R0–R7) only.
expression1 Any 32-bit expression.
expression2 A program location counter-relative expression +4 to +1024 from the
program location counter.


LDR (THUMB) LDR{condition} register,=expression
Parameters
Description
Similar to the LDR (CODE16) instruction, but by using a 32-bit instruction, a larger
value can be loaded directly with a MOV or MVN instruction without requiring the
constant to be placed in a literal pool.
If only 16-bit Thumb instructions are available, see LDR (CODE16), page 104.
By specifying a 16-bit version explicitly with the LDR.N instruction, a 16-bit
instruction is always generated. This may lead to the constant being placed in the
literal pool, even though a 32-bit instruction could have loaded the value directly using
MOV or MVN.
By specifying a 32-bit version explicitly with the LDR.W instruction, a 32-bit
instruction is always generated.
If you do not specify either .N or .W, the 16-bit LDR (CODE16) instruction will be
generated, unless Rd is R8-R15, which leads to the 32-bit variant being generated.
Note: The syntax LDR{condition} register, expression2, as described for
LDR (ARM) and LDR (CODE16), is no longer considered a pseudo-instruction. It is
part of the normal instruction set as specified in the Unified Assembler syntax from
Advanced RISC Machines Ltd.
condition An optional condition code if the instruction is placed after an IT
instruction.
register The register to be loaded.
expression Any 32-bit expression.


и ходить за документацией на Keil совсем незачем.
Dir
Цитата(zltigo @ Dec 15 2007, 01:33) *
Очень плохо искали sad.gif, точнее совсем не искали, поскольку непонятно, как можно не найти. В EWARM Assembler Refrence все это естественно есть:
и ходить за документацией на Keil совсем незачем.


Да, действительно есть. И когда знаешь, что это псевдоинструкция, а не инструкция (смутило одинаковое имя) и искать несложно. Сорри за поднятый дебош.
Hexxx
А что делает вот такая команда:
LDR R3, [ LR, +R3 ]!
Что означает этот самый плюс?
zltigo
Цитата(Hexxx @ Sep 1 2008, 10:24) *
Что означает этот самый плюс?

В r3 offset, посему кто-то для ясности написал еще '+'. В отличии от '-' это ничего не значит.
Можете убрать
Сергей Борщ
Цитата(Dir @ Dec 15 2007, 00:25) *
Но почему этото слово должно находиться по адресу 0x18 + 0x20?
Потому что этот адрес еще попадает в область, которая ремапится у любого ARM.
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Invision Power Board © 2001-2025 Invision Power Services, Inc.