assembler code

Hi,

I've some newbie questions concerning an assembler code generated for the Infoneon TriCore DSP.

First of all the c-code:

int main() { long long a = 2147483648ll; return a; }

and the corresponding assembler code generated by the tricore-gcc:

[...] .LC0: .word -2147483648 .word 0 .section .text .align 1 .global main .type main,@function main: # arg_overflow_area = 0, pretend = 0 # frame_size = 8, outgoing_args_size = 0 # f_size = 8, frame_pointer_needed = 0 # pool_size = 8 sub.a %SP, 8 # allocate space for locals call __main movh.a %a15, HI:.LC0 lea %a15, [%a15] LO:.LC0 ld.d %e0, [%a15] 0 st.d [%a10] 0, %e0 ld.w %d15, [%a10] 0 mov %d2, %d15 j .L1 .L1: ret

Before I start with my questions, here two definitions from the tricore assembler manual which could be helpful:

"Operand Prefixes

The following operand prefixes are recognized by the TriCore version of as: hi:symbol_or_expression Returns the high part (16 bits) of symbol_or_expression by adding 0x8000 to the

32-bit value of symbol_or_expression and then right-shifting the result 16 bits. If the value of symbol_or_expression isn't known at assemble time, a special relocation entry is generated for the linker to resolve. Example: movh.a %a15,hi:foo.

lo:symbol_or_expression Returns the lower 16 bits of symbol_or_expression. If the 32-bit value of symbol_or_expression isn't known at assemble time, a special relocation entry is generated for the linker to resolve. Example: lea %a15,[%a15]lo:foo. "

My questions:

1) HI:.LC0: How can this operand prefix use .LC0 for any calculations like adding 0x8000 ... Isn't it just a label name represented by a string? Or is it kind of alias which is representing a particular memory address?

2) MOVH.A is an instruction to move the value (here HI:.LC0) to the most- significant half-word of the given address register (here: %a15) and set the least-significant 16-bits to zero. Similar to 1), how can you move a label to some bits? I understand that you can move a constant value or the value of a data register which is representing a value in binary to an address register but I cannot imagine how to move a label.

3) A general question: What is .LC0 representing? A specific value or is it a memory address?

4) Just to make sure: LEA is using the indirect addressing mode to read the memory address stored in memory at address M[%a15], add the offset (LO:.LC0, why LO this time?) and put the result (effective address) in the address register %a15.

Thank you for answering my basic questions.

Chris

Reply to
Christian Christmann
Loading thread data ...

Christian

I'm not familiar with the tricore but ...

This expression is getting the top 16 bits of the address of the label LC0.

You are just taking the address of the label.

LC0 is the label of the memory address that contains your original constant (2147483648ll).

I think that you will find that the TriCore can't load a 32bit number directly. The compiler, therefore, has to do this in several steps.

  • Put the constant somewhere in addressable memory + Get the address of that constant into a register (itself a two part operation) + Load the constant into a register from the address in the (just loaded) register.

Other processors have to do this too (though less painfully): ARM, MIPS

Andrew

Reply to
Andrew Jackson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.