SDRAM C to Assembler Code review Topic is solved

If you have a simple question and just want an answer.
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

SDRAM C to Assembler Code review

Post by mon2 »

Hi. Reviewing the SDRAM module and not clear on the following:

sdram_block_write_PINOUT_V1_IS42S16400F:

    //r0    adjusted buffer pointer
    //r1    jump amount
    //r2    resource id of dq
    //r3    resource id of we
    //sp[1] resource id of ras
    //sp[2] stop time

    stw r4, sp[0]

 

From the XMOS ABI, the first 3 parameters in the calling C routine are passed via r0..r3 and the rest through the stack. Agree with the first 3 registers being passed correctly. However, would the starting stack pointer not be sp[0] ? (rather than sp[1])

Specifically, what is the first location on the stack for passed parameters ?

Should this be:

r0

r1

r2

r3

sp[0]  // resource id of ras

sp[1] // stop time

Or my misunderstanding ? To further add to my confusion, r4 is stored onto the stack at sp[0] ? (which is not free - should that be sp[2]). Will attempt to review the assembler (compiled) code of C routines to better understand this new topic on our side.

 

Hi. Reviewing the SDRAM module and not clear on the following:

sdram_block_write_PINOUT_V1_IS42S16400F:

    //r0    adjusted buffer pointer
    //r1    jump amount
    //r2    resource id of dq
    //r3    resource id of we
    //sp[1] resource id of ras
    //sp[2] stop time

    stw r4, sp[0]

 

From the XMOS ABI, the first 3 parameters in the calling C routine are passed via r0..r3 and the rest through the stack. Agree with the first 3 registers being passed correctly. However, would the starting stack pointer not be sp[0] ? (rather than sp[1])

Specifically, what is the first location on the stack for passed parameters ?

Should this be:

r0

r1

r2

r3

sp[0]  // resource id of ras

sp[1] // stop time

Or my misunderstanding ? To further add to my confusion, r4 is stored onto the stack at sp[0] ? (which is not free - should that be sp[2]). Will attempt to review the assembler (compiled) code of C routines to better understand this new topic on our side.

 



View Solution
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

On entry to the function the first argument passed on the stack is passed in sp[1] (subsequent arguments are passed in sp[2], sp[3], etc.). No argument is stored in sp[0] but the callee is allowed to write to this location. This means the callee can extend the stack and save off the value of the link register (lr) at the start of the function using the entsp instruction. Although the callee will usually use sp[0] to save off the lr it isn't required to do so and saving off another value such as r4 is perfectly valid.