This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Stack

Hello,
I'm working on the XC164X µc and I've a question concerning the storage of registers in stack when interrupt occur.

The function is written in c language

void ItFunc (void) interrupt 14
{ funcCode ();
}

The pre-processor code is as follow:

ItFunc PROC INTERRUPT = 14 GLOBAL ItFunc
; FUNCTION ItFunc (BEGIN RMASK = @0x3FFF)

SCXT DPP3,#3

PUSH DPP0

SCXT MDC,#16

PUSH MDH

PUSH MDL

MOV [-R0],R1

MOV [-R0],R2

MOV [-R0],R3

MOV [-R0],R4

MOV [-R0],R5

MOV [-R0],R6

MOV [-R0],R7

MOV [-R0],R8

MOV [-R0],R9

MOV [-R0],R10

MOV [-R0],R11

MOV [-R0],R12

; line 234: funcCode ();

CALL funcCode

?C0005:

MOV R12,[R0+]

MOV R11,[R0+]

MOV R10,[R0+]

MOV R9,[R0+]

MOV R8,[R0+]

MOV R7,[R0+]

MOV R6,[R0+]

MOV R5,[R0+]

MOV R4,[R0+]

MOV R3,[R0+]

MOV R2,[R0+]

MOV R1,[R0+]

POP MDL

POP MDH

POP MDC

POP DPP0

POP DPP3

RETI

; FUNCTION ItFunc (END RMASK = @0x3FFF)

ItFunc ENDP

?PR?BS_TST ENDS

As shown in this pre-processor code, we use the register R0 to save the registers R1—R12.
I'd like to store the registers using the instruction PUSH R1.
How can I do this? Which directive could I use that the compiler store the registers in stack using the instruction "PUSH R1" and not using "MOV [-R0], R1"

Thanks

Parents
  • I give you an example

    In the document that joost gives to me « http://www.keil.com/support/man/docs/c166/c166_noframe.htm"

    We find this example:

    1 int i1, i2, i3;

    2 3 void intr_func1 (void) interrupt 0x21 {

    4 1 i1 = i2 * i3;

    5 1 } 6

    7 #pragma NOFRAME

    8 void intr_func2 (void) interrupt 0x22 {

    9 1 i1 = i2 * i3;

    10 1 }

    ASSEMBLY LISTING OF GENERATED OBJECT CODE

    ; FUNCTION intr_func1 (BEGIN RMASK = @0x2030)

    ; SOURCE LINE # 3

    0000 C6871000 SCXT MDC,#010H

    0004 EC06 PUSH MDH

    0006 EC07 PUSH MDL

    0008 ECF4 PUSH R4

    000A ECF5 PUSH R5

    ; SOURCE LINE # 4

    000C F2F50000 R MOV R5,i3

    0010 F2F40200 R MOV R4,i2

    0014 0B45 MUL R4,R5

    0016 F2F40EFE MOV R4,MDL

    001A F6070400 R MOV i1,MDL

    ; SOURCE LINE # 5

    001E FCF5 POP R5

    0020 FCF4 POP R4

    0022 FC07 POP MDL

    0024 FC06 POP MDH

    0026 FC87 POP MDC

    0028 FB88 RETI

    ; FUNCTION intr_func1 (END RMASK = @0x2030)

    ; FUNCTION intr_func2 (BEGIN RMASK = @0x2030)

    ; SOURCE LINE # 8

    ; SOURCE LINE # 9

    002A F2F50000 R MOV R5,i3

    002E F2F40200 R MOV R4,i2

    0032 0B45 MUL R4,R5

    0034 F2F40EFE MOV R4,MDL

    0038 F6070400 R MOV i1,MDL

    ; SOURCE LINE # 10

    003C FB88 RETI

    ; FUNCTION intr_func2 (END RMASK = @0x2030)

    ;
    ; ;
    ; ;
    ; ;

    Let's concentrate on function intr_func1

    ;
    ; ;

    1 int i1, i2, i3;

    2

    3 void intr_func1 (void) interrupt 0x21 {

    4 1 i1 = i2 * i3;

    5 1 }

    ASSEMBLY LISTING OF GENERATED OBJECT CODE

    ; FUNCTION intr_func1 (BEGIN RMASK = @0x2030)

    ; SOURCE LINE # 3

    0000 C6871000 SCXT MDC,#010H

    0004 EC06 PUSH MDH

    0006 EC07 PUSH MDL

    0008 ECF4 PUSH R4

    000A ECF5 PUSH R5

    ; SOURCE LINE # 4

    000C F2F50000 R MOV R5,i3

    0010 F2F40200 R MOV R4,i2

    0014 0B45 MUL R4,R5

    0016 F2F40EFE MOV R4,MDL

    001A F6070400 R MOV i1,MDL

    ; SOURCE LINE # 5

    001E FCF5 POP R5

    0020 FCF4 POP R4

    0022 FC07 POP MDL

    0024 FC06 POP MDH

    0026 FC87 POP MDC

    0028 FB88 RETI

    ; FUNCTION intr_func1 (END RMASK = @0x2030)

    ;
    ; ;
    ; ;

    ;
    ;

    We see in that the ASSEMBLY LISTING OF GENERATED
    OBJECT CODE stores the register R4 and R5 using PUSH
    R4 and PUSH R5.

    In my case when I've written the same function intr_func1, that the ASSEMBLY LISTING OF GENERATED OBJECT CODE stores the register R4 using MOV [-R0],R4

    ;
    ; ;
    ;

    intr_func1 PROC INTERRUPT = 33

    GLOBAL intr_func1

    ; FUNCTION intr_func1 (BEGIN RMASK = @0x2030)

    SCXT MDC,#16

    PUSH MDH

    PUSH MDL

    MOV [-R0],R4

    MOV [-R0],R5

    ; line 997:

    ; line 998:

    ; line 999: i1 = i2 * i3;

    MOV R5,WORD i3

    MOV R4,WORD i2

    MUL R4,R5

    MOV WORD i1,MDL

    ; line 1000: }

    MOV R5,[R0+]

    MOV R4,[R0+]

    POP MDL

    POP MDH

    POP MDC

    RETI

    ; FUNCTION intr_func1 (END RMASK = @0x2030)

    intr_func1 ENDP

    ?PR?OS_TEST ENDS

    ;
    ; ;
    ; ;

    So my question is, I'd like to know how in the first case the compiler store R4 in stack using PUSH, and why in my case he store R4 using MOV [-R0],R4

    I hope now is more clear

Reply
  • I give you an example

    In the document that joost gives to me « http://www.keil.com/support/man/docs/c166/c166_noframe.htm"

    We find this example:

    1 int i1, i2, i3;

    2 3 void intr_func1 (void) interrupt 0x21 {

    4 1 i1 = i2 * i3;

    5 1 } 6

    7 #pragma NOFRAME

    8 void intr_func2 (void) interrupt 0x22 {

    9 1 i1 = i2 * i3;

    10 1 }

    ASSEMBLY LISTING OF GENERATED OBJECT CODE

    ; FUNCTION intr_func1 (BEGIN RMASK = @0x2030)

    ; SOURCE LINE # 3

    0000 C6871000 SCXT MDC,#010H

    0004 EC06 PUSH MDH

    0006 EC07 PUSH MDL

    0008 ECF4 PUSH R4

    000A ECF5 PUSH R5

    ; SOURCE LINE # 4

    000C F2F50000 R MOV R5,i3

    0010 F2F40200 R MOV R4,i2

    0014 0B45 MUL R4,R5

    0016 F2F40EFE MOV R4,MDL

    001A F6070400 R MOV i1,MDL

    ; SOURCE LINE # 5

    001E FCF5 POP R5

    0020 FCF4 POP R4

    0022 FC07 POP MDL

    0024 FC06 POP MDH

    0026 FC87 POP MDC

    0028 FB88 RETI

    ; FUNCTION intr_func1 (END RMASK = @0x2030)

    ; FUNCTION intr_func2 (BEGIN RMASK = @0x2030)

    ; SOURCE LINE # 8

    ; SOURCE LINE # 9

    002A F2F50000 R MOV R5,i3

    002E F2F40200 R MOV R4,i2

    0032 0B45 MUL R4,R5

    0034 F2F40EFE MOV R4,MDL

    0038 F6070400 R MOV i1,MDL

    ; SOURCE LINE # 10

    003C FB88 RETI

    ; FUNCTION intr_func2 (END RMASK = @0x2030)

    ;
    ; ;
    ; ;
    ; ;

    Let's concentrate on function intr_func1

    ;
    ; ;

    1 int i1, i2, i3;

    2

    3 void intr_func1 (void) interrupt 0x21 {

    4 1 i1 = i2 * i3;

    5 1 }

    ASSEMBLY LISTING OF GENERATED OBJECT CODE

    ; FUNCTION intr_func1 (BEGIN RMASK = @0x2030)

    ; SOURCE LINE # 3

    0000 C6871000 SCXT MDC,#010H

    0004 EC06 PUSH MDH

    0006 EC07 PUSH MDL

    0008 ECF4 PUSH R4

    000A ECF5 PUSH R5

    ; SOURCE LINE # 4

    000C F2F50000 R MOV R5,i3

    0010 F2F40200 R MOV R4,i2

    0014 0B45 MUL R4,R5

    0016 F2F40EFE MOV R4,MDL

    001A F6070400 R MOV i1,MDL

    ; SOURCE LINE # 5

    001E FCF5 POP R5

    0020 FCF4 POP R4

    0022 FC07 POP MDL

    0024 FC06 POP MDH

    0026 FC87 POP MDC

    0028 FB88 RETI

    ; FUNCTION intr_func1 (END RMASK = @0x2030)

    ;
    ; ;
    ; ;

    ;
    ;

    We see in that the ASSEMBLY LISTING OF GENERATED
    OBJECT CODE stores the register R4 and R5 using PUSH
    R4 and PUSH R5.

    In my case when I've written the same function intr_func1, that the ASSEMBLY LISTING OF GENERATED OBJECT CODE stores the register R4 using MOV [-R0],R4

    ;
    ; ;
    ;

    intr_func1 PROC INTERRUPT = 33

    GLOBAL intr_func1

    ; FUNCTION intr_func1 (BEGIN RMASK = @0x2030)

    SCXT MDC,#16

    PUSH MDH

    PUSH MDL

    MOV [-R0],R4

    MOV [-R0],R5

    ; line 997:

    ; line 998:

    ; line 999: i1 = i2 * i3;

    MOV R5,WORD i3

    MOV R4,WORD i2

    MUL R4,R5

    MOV WORD i1,MDL

    ; line 1000: }

    MOV R5,[R0+]

    MOV R4,[R0+]

    POP MDL

    POP MDH

    POP MDC

    RETI

    ; FUNCTION intr_func1 (END RMASK = @0x2030)

    intr_func1 ENDP

    ?PR?OS_TEST ENDS

    ;
    ; ;
    ; ;

    So my question is, I'd like to know how in the first case the compiler store R4 in stack using PUSH, and why in my case he store R4 using MOV [-R0],R4

    I hope now is more clear

Children