This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Why is it different for the compiler output with pdf example?

Hi,

I see that below ,,,line example from spru187t.pdf. It(*SP--(12) is different from my hello.c compiler output in the SP--(16)

Second, there is

"STW .D2 A10,*+SP(8)" in spru187t.pdf example.

I am just curious about it.

Thanks,

 

 

//////////////////////////////////LIST file from hello.c with V7.4.2 compiler, C64 DSP

           STW     .D2T2   B3,*SP--(16)  ; |6|

.dwcfi cfa_offset, 16

.dwcfi save_reg_to_mem, 19, 0

.dwpsn file

"../hello.c",line 7,column 2,is_stmt

$C$DW$5 .dwtag  DW_TAG_TI_branch

.dwattr $C$DW$5, DW_AT_low_pc(0x00)

.dwattr $C$DW$5, DW_AT_name("_printf")

.dwattr $C$DW$5, DW_AT_TI_call

           CALL    .S1     _printf          

; |7|

           MVKL    .S2     $C$SL1+0,B4

           MVKH    .S2     $C$SL1+0,B4

           STW     .D2T2   B4,*+SP(4)       

; |7|

           ADDKPC  .S2     $C$RL0,B3,1      

; |7|

$C$RL0:    ; CALL OCCURS {_printf} {0}       ; |7|

.dwpsn file

"../hello.c",line 9,column 2,is_stmt

ZERO    .L1     A4                ; |9|

.dwpsn file

"../hello.c",line 10,column 1,is_stmt

           LDW     .D2T2   *++SP(16),B3     

; |10|

NOP             4

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,example from Page 60, spru187t.pdf

_main:

STW .D2 B3,*SP--(12)

STW .D2 A10,*+SP(8)

;------------------------------------------------------------------------------

; 5 | printf("Hello, world\n");

;------------------------------------------------------------------------------

B .S1 _printf

NOP 2

MVKL .S1 SL1+0,A0

MVKH .S1 SL1+0,A0

|| MVKL .S2 RL0,B3

STW .D2 A0,*+SP(4)

|| MVKH .S2 RL0,B3

RL0: ; CALL OCCURS

;------------------------------------------------------------------------------

; 6 | return 0;

;------------------------------------------------------------------------------

ZERO .L1 A10

MV .L1 A10,A4

LDW .D2 *+SP(8),A10

LDW .D2 *++SP(12),B3

NOP 4

B .S2 B3

NOP

  • Speaking at a higher level ... That example from the manual is probably about 15 years old.  Over that much time, compiler output can be expected to change, even for an example as simple as this.

    Speaking at a lower level ...

     

    Robert W said:
    *SP--(12) is different from my hello.c compiler output in the SP--(16)

    That is how the local stack frame is allocated.  The older compiler allocates 12 worlds, while the newer allocates 16 words.  My memory on this is fuzzy, but I'm pretty sure this is because the newer compiler keeps the SP aligned to 8 byte boundaries.

    Robert W said:
    Second, there is "STW .D2 A10,*+SP(8)" in spru187t.pdf example.

    This instruction preserves the register A10 on the local stack frame.  The older compiler uses A10 as part of returning 0 from main.  The newer compiler handles that better, and zeros A4 directly.  Thus there is no code to preserve A10.

    Thanks and regards,

    -George