메인 콘텐츠로 건너뛰기
Knowledgebase
Home
Renesas Korea

What does assembler code after PUSH before POP of general register do?

Latest Updated:09/05/2013

Question:

I am using the RL78/78K0R compiler in the CubeSuite+ environment.
When a function call is made within an interrupt function, assembler code is output after PUSH and before POP of a general register. What does this processing do?

Answer:

The output code is for saving or restoring the saddr area which is for parameters used by the compiler to call the runtime library.

[Output code example 1]

<C source file>

#pragma interrupt	INTP0	inter		/*Software interrupt*/
void func(void);
__interrupt void	inter();		/*Prototype declaration*/

__interrupt void	inter()
{
	func();
};

<Generated code>
_inter:
	push	ax
	push	bc
	push	de
	push	hl
	mov	c,#0CH        ; From here
	dec	c
	dec	c
	movw	ax,_@SEGAX[c]
	push	ax
	bnz	$$-6
	mov	a,ES
	mov	x,a
	mov	a,CS
	push	ax          ; Up to here
	call	!!_func
	pop	ax          ; From here
	mov	CS,a
	mov	a,x
	mov	ES,a
	movw	de,#_@SEGAX
	mov	c,#06H
	pop	ax
	movw	[de],ax
	incw	de
	incw	de
	dec	c
	bnz	$$-5         ; Up to here
	pop	hl
	pop	de
	pop	bc
	pop	ax
	reti

Note that the processing time can be shortened by specifying the "-qx1 (Speed precedence)" optimization option. This will increase the number of steps in the code but a saving/restoring code that gives priority to the processing time will be output.

[Output code example 2]

<Generated code>

 _inter:
	push	ax
	push	bc
	push	de
	push	hl
	movw	ax,_@RTARG6      ; From here
	push	ax
	movw	ax,_@RTARG4
	push	ax
	movw	ax,_@RTARG2
	push	ax
	movw	ax,_@RTARG0
	push	ax
	movw	ax,_@SEGDE
	push	ax
	movw	ax,_@SEGAX
	push	ax
	mov	a,ES
	mov	x,a
	mov	a,CS
	push	ax           ; Up to here
	call	!!_func
	pop	ax            ; From here
	mov	CS,a
	mov	a,x
	mov	ES,a
	pop	ax
	movw	_@SEGAX,ax
	pop	ax
	movw	_@SEGDE,ax
	pop	ax
	movw	_@RTARG0,ax
	pop	ax
	movw	_@RTARG2,ax
	pop	ax
	movw	_@RTARG4,ax
	pop	ax
	movw	_@RTARG6,ax      ; Up to here
	pop	hl
	pop	de
	pop	bc
	pop	ax
	reti

Though the number of steps in the code increases in [Output code example 2], compared to [Output code example 1], the execution time of the saving/restoring code at the beginning/end of the interrupt function becomes 1/3.

For details, refer to the following from here.

Interrupt functions (#pragma vect/#pragma interrupt) in
section 3.2.4, Using extended functions,
and
section 3.4, List of saddr Area Labels, in
CubeSuite+ Integrated Development Environment User's Manual: RL78,78K0R Coding

Suitable Products
CS+ (formerly CubeSuite+)
C Compiler Package for RL78 and 78K Families
Compiler for RL78 Family and 78K0R [CA78K0R]