Domanda

Using the -S flag in gcc I created a assembly file from my C code and in order to better understand how memory is used. Here is some assembly from the top of the main function:

main:
    mov r1, r4          ; FP = SP
    add #2, r4          ; FP += 2
    add #llo(-14), r1           ; SP -= 14 ?
    mov #llo(-16), r15          ; ???
    add r4, r15         ; r15 += FP
    add #4, r15

Comments were placed by me as I tried to dissect what is happening. My question is the use of the #llo macro, and how the memory on the stack is being used, and lastly what is going into r15?

For context I have a variables including a structure being placed on the stack at the beginning of main that takes up 14 bytes (7 16bit words). What I don't understand is what is the #llo macro and what is r15 being used for? I know r4 is the frame pointer and r1 is the stack pointer.

È stato utile?

Soluzione

The llo macro returns the lower 16 bits of it's argument. I guess that is needs it to avoid overflow when using a negative number (or the compiler is lazy).

It looks like the code computes the location of some object in R15. It's hard to tell with only part of the code... Also, if R4 isn't use more in the function, this code could be optimized a lot.

The line add #llo(-14), r1 allocates space on the stack.

It would be interesting to see what other compilers do with code like this (gcc for the MSP430 isn't really state of the art).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top