WO2004003732A1 - Method for accessing local variables - Google Patents

Method for accessing local variables Download PDF

Info

Publication number
WO2004003732A1
WO2004003732A1 PCT/EP2002/007132 EP0207132W WO2004003732A1 WO 2004003732 A1 WO2004003732 A1 WO 2004003732A1 EP 0207132 W EP0207132 W EP 0207132W WO 2004003732 A1 WO2004003732 A1 WO 2004003732A1
Authority
WO
WIPO (PCT)
Prior art keywords
data memory
memory unit
local variables
function parameters
pointers
Prior art date
Application number
PCT/EP2002/007132
Other languages
French (fr)
Inventor
Shahar Nahum
Original Assignee
Infineon Technologies Ag
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Infineon Technologies Ag filed Critical Infineon Technologies Ag
Priority to PCT/EP2002/007132 priority Critical patent/WO2004003732A1/en
Publication of WO2004003732A1 publication Critical patent/WO2004003732A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/3004Arrangements for executing specific machine instructions to perform operations on memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30098Register arrangements
    • G06F9/30101Special purpose registers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/34Addressing or accessing the instruction operand or the result ; Formation of operand address; Addressing modes
    • G06F9/35Indirect addressing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The present invention provides a method for accessing local variables and function parameters in a data memory unit (100), where at least one data memory unit (100) is provided, at least one data memory pointer (r0, r1, r2, r3, ..., rn) is provided, the data memory pointers (r0, r1, r2, r3, ..., rn) are initialized to point at at least one local variable (101a - 101m) in the data memory unit (100), a frame size (103) is determined and all data memory pointers (r0, r1, r2, r3, ..., rn) are updated by one machine operation applied to the stack pointers (r0, r1, r2, r3, ..., rn) in response to the determined frame size (103).

Description

Description
Method for accessing local variables
The present invention relates to a method for acessing local variables and function parameters using pointers, and particularly to a method for accessing local variables and function parameters using more than one pointer per memory unit that is used for storing local variables.
Conventional methods for accessing local variables and function parameters in a stack provide an access by means of indexing using an immediate value with one base pointer for all local variables in the stack. An example for this conven- tional technique can be found in C-compliers where one base pointer for all local variables in the stack is employed.
Another concept is to use several pointers pointing at local variables. The present invention takes advantage of this fact and provides more than one pointer per memory unit. Moreover, more than one data memory unit may be provided.
In conventional coding techniques an access to local variables and function parameters in a stack is performed using one base pointer for all variables in the stack which leads to long coding instructions.
A major disadvantage of conventional methods for accessing local variables and function parameters in a stack is that additional code space is required if instructions are employed that use immediate values, e.g. if an immediate index such as * (R+immediate) is required.
It is therefore an object of the present invention to provide an improved method for acessing local variables and function parameters which overcomes the drawbacks of conventional techniques and provides an access to local variables and function parameters without the requirement for a long coding using immediate values.
A major disadvantage of conventional methods for accessing local variables and function parameters is that all these variables and parameters use the same memory unit, i.e. memory space (stack) .
It is therefore an object of the present invention to provide an improved method for accessing local variables and function parameters in different data memory units, i.e. in a data memory areas without the requirement for long coding sequences, i.e. with a reduced overhead or no overhead at all.
This object is solved by a method for accessing local variables and function parameters according to claim 1.
The method according to the present invention gains advantage from the fact that a separation of data memory pointers is a constant value in many cases.
It is thus an advantage of the inventive method that a shorter length of coding is achieved compared to the case where an immediate index such as * (R+immediate) is used. The inventive method provides an access to local variables in a data memory unit by an indirect coding without any immediate indices .
It is a further advantage of the present invention that the inventive method is capable to change the accessing procedure that is used in C-compilers.
Moreover the inventive method is capable to access local variables and function parameters by an adressing scheme that has a shorter length of coding. Each pointer can point at one or more local variables. The method for accessing local variables and function parameters according to the present invention essentially comprises the following steps:
a) providing at least one data memory unit;
b) providing at least one data memory pointer;
c) initializing the data memory pointers to point at at least one local variable in the data memory unit;
d) determining a frame size; and
e) updating all data memory pointers by means of one machine operation applied to the stack pointers in response to the determined frame size.
Furthermore a data memory unit according to the present invention contains local variables which are accessed by using the obove method.
Further avantageous aspects of the present invention are according to the dependent claims.
In accordance with one aspect of the present invention each data memory pointer points at one or more local variables in the data memory unit. It is thus expedient to use more than one data memory pointer per memory unit that is used for storing local variables whereas usually one base pointer for all local variables in a stack is used.
In accordance with another aspect of the present invention one machine operation, i.e. one updating operation, is used to update all data memory pointers whereby the required cod- ing length is advantageously decreased. In accordance with yet another aspect of the present invention the data memory pointers are shifted by the determined frame size whereby the respective distances of the data memory pointers to each other are maintained.
In accordance with yet another aspect of the present invention an activation of the updating operation is performed by means of at least one call-and-return assembly instruction.
In accordance with yet another aspect of the present invention an activation of the updating operation is performed by means of at least one external assembly instruction.
In accordance with yet another aspect of the present inven- tion stack memory is used to store the local variables of a function.
In accordance with yet another aspect of the present invention the memory unit that is used for storing local variables is provided as a standard stack or as additional stacks or as another memory unit that is provided for the storage of local variables .
In accordance with yet another aspect of the present inven- tion at least one data memory unit is provided as a local variables data memory unit.
In accordance with yet another aspect of the present invention coding is provided by means of bitmaps of data memory pointers.
In accordance with yet another aspect of the present invention the frame size of the updating operation, i.e. the one machine operation, is variable, configurable or constant. Preferred embodiments of the present invention are depicted in the figures and will become obvious from the following description.
Fig. 1 is a table representing pointers in a pointers column and a data column which are shown schematically;
Fig. 2 is a table representing pointers in a pointers column and a data column which are shown schematically where the pointers are shifted by means of an updating operation to a status increased by 7 as compared to the status of Fig. 1; and
Fig. 3 is a schematic block diagram of the method for access- ing local variables in a data memory unit according to a preferred embodiment of the present invention.
Figs . 1 and 2 illustrate an updating operation where the data memory pointers rO, rl and r2 are shifted from an initial status of Fig. 1 to a status of Fig. 2.
In this example a frame size 103 of "7" has been adjusted, thus the respective pointers have been "shifted" by seven rows, i.e. rO, rl, r2 have been increased by 7.
In a first embodiment of the present invention a method is presented that provides a CARMEL-like code for using local variables stack. The CARMEL design is described, e.g. in "Henry Davis: The CARMEL DSP, CommsDesign, www.commsdesign.com/main/1999/02/9902feat4.htm.
The proposed method of the present invention may be carried out using several memories, for example:
rO points at memory #0, rl points at memory #1, r2 points at memory #2, Each pointer points at different local variable [s] in a different physical memory area and in a different data memory unit.
Using different memories can increase time efficiency, therefore, in multi-memories architectures, the proposed invention can increase time efficiency of accessing local variables.
This is true also when large local variables and
* (R+immediate) mode are used. In this case, the proposed invention increases time efficiency of accessing local variables but doesn't decrease code-size (as *R, for example, does) .
In the following a preferred embodiment of the present invention is described.
In the following example, instructions Λcall' and 'return' were extended to update also registers that were previously chosen to point at local variables.
code main()
{ /*
It is assumed in this example, that rO, rl, r2, r3 are the registers to be used for pointing at local variables, and that the frame size is fixed to 32-bytes.
For simplicity and efficiency it is assumed that registers r0,rl,r2,r3 are provided for local variables and are not used, in general, for other purposes. Note that local variables are common and provided in C-language.
It is noted that each register might be initialized to a different memory. rO rl r2 r3
/'
Extended call: calls function f and updates chosen registers to point at the next local variables frame;
*/ ext_call f;
} code f ( )
{
// can use r0,rl,r2,r3 to point local variables
*r0 =
Extended return: returns and updates chosen registers to point at the former local variables frame.
*/ ext return;
}
The invention also provides a method for performing parame- ters-to-functions operation. In C language, the parameters- to-functions operation is carried out by a "push' operation.
A schematic description of the contents of a stack for a use of a function in C-language may be provided. It is noted that local variables and parameters-to-function variables are accessed by one pointer ( fp' ) and by the * (fp+immediate) mode. A Λpush' operation will move Λsp' upward.
Figure imgf000009_0001
The present invention allows sending input and output parameters in an efficient and easy way that can be used for C- compilers .
The present invention is more efficient than the standard method because the caller function can use its own local variables for the input and output parameters of the called function, so the access to the input and output parameters is performed by the data memory pointers that are proposed in this invention, and not by a single frame pointer with * (fp+immediate) mode.
In the following example, special instructions are used to update registers that point at local variables: 'local', Λunlocal' .
local (r0,r2) performs: rO rO + FRAME SIZE, r2 = r2 + FRAME SIZE
unlocal (r0,r2) performs: rO = rO - FRAME_SIZE, r2 r2 - FRAME SIZE
The instructions may use bit-maps to indicate the chosen registers, whereby it is possible to have input/output parameters which also can be used even for recursions. code f ( )
In this example it is assumed that rO, rl, r2 , r3 are the registers to be used for pointing at local variables and that frame size is fixed.
In the following instruction only r0,r2 are updated to point at local variables of a current function.
rl,r3 point at local variables of the caller function and are used as input and output parameters ! ! */ local (rO, r2) ;
/*
in this example: rl is used to point at an input parameter (rl points at local variable of the caller function)
*/
... = * (long*) rl ...
/* in this example: *r3 is an output parameter (r3 points at a local variable of the caller function)
*/
*r3 = ...;
unlocal (rO, r2) ; return;
}
In following example, input and output function parameters and local variables are generated with the extended Λcall' assembly instruction and with no time consumption. The local variables are deallocated with the extended ''return' assembly instruction and with no time consumption. Each function parameter is accessed by a different pointer using the *R mode.
code g ( ) {
/* In this example it is assumed that r0,rl,r2,r3 are the registers to be used for pointing at local variables and that the frame size is fixed.
For simplicity and efficiency it is assumed that regis- ters r0,rl,r2,r3 are provided for local variables and are not used, in general, for other purposes. Note that local variables are common and provided in C-language. Note that each register might be initialized to a different memory unit . */
/*
Extended call: calls function f and updates registers r0,r2 to point at the next local variables frame.
Note: In the following instruction only r0,r2 are updated to point at the next function local variables. rl,r3 point at local variables of a current function (function 'g') and are used as input and output parame- ters ! ! */ ext_call f (rO, r2) ;
// r3 points at output parameter of f ... = *r3; code f ( ) {
/* in this example: rl and r3 is used to point at input parameters (rl and r3 point at local variable of the caller function)
*/
... = * (long*) rl ... ... = *r3
/* in this example: *r3 is also used as an output parameter (r3 points at local variable of the caller function)
*/ *r3 = ...;
/*
Extended return: returns and update chosen registers to point at the former local variables frame. */ ext_return (rO , r2 ) ; }
In following assembly instruction example, it is assumed that λfp' points at local variables and at a function parameter by an immediate index mode (standard C-Compiler approach) . The present invention updates in one assembly instruction several data memory pointers to point at the local variables and the function parameters :
local (fp+8, rO, rl, r2, r3) ;
The instruction above performs the following operations: rO = fp+8; rl = rO + VAR_SIZE_1; r2 = rl + VAR_SIZE_2; r3 = r2 + VAR SIZE 3; VAR_SIZE_1, 2, 3 should be pre-defined, may comprise configurable values and may have identical values.
Λfp+8' can point, for example, at the standard stack space that is used for local variables.
After the execution of the instruction in the example,
*rO may point at the 1 St local variable
*(long*)rl may point at the 2nd local variable *r2 may point at the 3rd local variable *r3 may point at the 4th local variable
Fig. 3 represents a block diagram showing schematically the method for accessing local variables in a data memory unit according to a preferred embodiment of the present invention.
In Fig. 3 a number n of data memory pointers rO, rl, r2, r3, ..., rn are used to point at local variables 101a - lOlm in a data memory unit 100 whereby n is not equal m in the general case. An updating operation represented by the arrow 102 may be performed using a given frame size 103.
While preferred embodiments have been shown and described, various modifications and substitutions may be made thereto without departing from the spirit and scope of the invention.
Accordingly it is to be understood that the present invention has been described only by way of illustration and not limitation.
Furthermore the invention is not limited to the specific application areas mention above. List of reference numerals
100, data memory unit
100a
101a - local variables
101m
102 updating operation
103 frame size rO, rl, data memory pointers r2, r3, ..., rn

Claims

Claims
1. Method for accessing local variables and function parameters in a data memory unit (100), comprising the following steps:
a) providing at least one data memory unit (100);
b) providing at least one data memory pointer (rO, rl, r2 , r3, ... , rn) ;
c) initializing the data memory pointer (rO, rl, r2, r3, ..., rn) to point at at least one local variable (101a - 101m) in the data memory unit (100);
d) determining a frame size (103) ; and
e) updating all data memory pointers (rO, rl, r2, r3, ..., rn) by means of one machine operation operation applied to the data memory pointers (rO, rl, r2, r3, ..., rn) in response to the determined frame size (103).
2. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that each data memory pointer (102a - 102n) points at one or more local variables (101a - 101m) in the data memory unit (100) .
3. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1 or 2, c h a r a c t e r i z e d i n that one updating operation is used to update all data memory pointers (rO, rl, r2, r3, ..., rn) .
4. Method for accessing local variables and function parameters in a data memory unit (100) according any preceding claim, c h a r a c t e r i z e d i n 5. that the data memory pointers (rO, rl, r2, r3, ..., rn) are shifted by the determined frame size (103) .
5. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1, 0 c h a r a c t e r i z e d i n that at least one data memory pointer (rO) is used to update the remaining data memory pointers (rl, r2, r3, ..., rn) .
6. Method for accessing local variables and function parame- ters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that an activation of the updating operation is performed by means of at least one call-and-return assembly instruction.
7. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that an activation of the updating operation is performed by means of at least one external assembly instruction.
8. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that data memory unit (100) is used to store the local vari- ables (101a - 101m) of a function.
9. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that the data memory unit (100) is provided as a standard stack, as an additional stack or as another memory unit that is provided for storing local variables.
10. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 9, c h a r a c t e r i z e d i n that the data memory unit (100) is provided as a local variables data memory unit.
11. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that a short or a long indirect coding (*r0, *(long)r0) is performed.
12. Method for accessing local variables and function parame- ters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that coding is provided by means of bitmaps of stack pointers
(rO, rl, r2, r3, ..., rn) .
13. Method for accessing local variables and function parameters in a data memory unit (100) according to claim 1, c h a r a c t e r i z e d i n that the frame size (103) of the updating operation is variable, configurable or constant.
14. Data memory unit (100) containing local variables and function parameters (101a - 101m) being accessed by means of a method according to claims 1 to 13.
PCT/EP2002/007132 2002-06-27 2002-06-27 Method for accessing local variables WO2004003732A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/EP2002/007132 WO2004003732A1 (en) 2002-06-27 2002-06-27 Method for accessing local variables

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/EP2002/007132 WO2004003732A1 (en) 2002-06-27 2002-06-27 Method for accessing local variables

Publications (1)

Publication Number Publication Date
WO2004003732A1 true WO2004003732A1 (en) 2004-01-08

Family

ID=29797101

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/EP2002/007132 WO2004003732A1 (en) 2002-06-27 2002-06-27 Method for accessing local variables

Country Status (1)

Country Link
WO (1) WO2004003732A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100361082C (en) * 2005-08-26 2008-01-09 北京中星微电子有限公司 Method for calling function containing pointer parameter between different operation platforms

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB1233925A (en) * 1967-10-02 1971-06-03
US4649480A (en) * 1984-03-28 1987-03-10 Hitachi, Ltd. Method of procedures linkage control
EP0401745A2 (en) * 1989-06-05 1990-12-12 Matsushita Electric Industrial Co., Ltd. Data processor for high-speed access to stack area data
US5241679A (en) * 1989-07-05 1993-08-31 Hitachi Ltd. Data processor for executing data saving and restoration register and data saving stack with corresponding stack storage for each register
EP0917048A2 (en) * 1997-10-28 1999-05-19 Microchip Technology Inc. Address generator and method for single-cycle indirect addressing

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB1233925A (en) * 1967-10-02 1971-06-03
US4649480A (en) * 1984-03-28 1987-03-10 Hitachi, Ltd. Method of procedures linkage control
EP0401745A2 (en) * 1989-06-05 1990-12-12 Matsushita Electric Industrial Co., Ltd. Data processor for high-speed access to stack area data
US5241679A (en) * 1989-07-05 1993-08-31 Hitachi Ltd. Data processor for executing data saving and restoration register and data saving stack with corresponding stack storage for each register
EP0917048A2 (en) * 1997-10-28 1999-05-19 Microchip Technology Inc. Address generator and method for single-cycle indirect addressing

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100361082C (en) * 2005-08-26 2008-01-09 北京中星微电子有限公司 Method for calling function containing pointer parameter between different operation platforms

Similar Documents

Publication Publication Date Title
EP0517282B1 (en) Register allocation in an information processing apparatus
US5469161A (en) Algorithm for the implementation of Ziv-Lempel data compression using content addressable memory
US6826681B2 (en) Instruction specified register value saving in allocated caller stack or not yet allocated callee stack
US6363436B1 (en) Method and system for loading libraries into embedded systems
US4835734A (en) Address translation apparatus
US8306956B2 (en) Method and apparatus for compressing a data set
US5964861A (en) Method for writing a program to control processors using any instructions selected from original instructions and defining the instructions used as a new instruction set
CN1662904A (en) Digital signal processor with cascaded SIMD organization
EP1462931B1 (en) Method for referring to address of vector data and vector processor
KR20030055467A (en) A method for memory allocation using multi-level partition
JPH06259318A (en) Information storage device
US6253314B1 (en) Instruction set and executing method of the same by microcomputer
WO2004003732A1 (en) Method for accessing local variables
US6886159B2 (en) Computer system, virtual machine, runtime representation of object, storage media and program transmission apparatus
CN115328390A (en) Pointer variable read-write operation method, device, equipment and medium based on C51
WO2010095004A1 (en) Priority search trees
US7421570B2 (en) Method for managing a microprocessor stack for saving contextual data
EP0543032A1 (en) Expanded memory addressing scheme
US20040243788A1 (en) Vector processor and register addressing method
CN1190738C (en) Data processing device and its data read method
US5930505A (en) Method for storing a program into an auxiliary memory
EP0286352B1 (en) Entry point mapping and skipping method and apparatus
AU766777B2 (en) Method and apparatus for element selection exhausting an entire array
US6668285B1 (en) Object oriented processing with dedicated pointer memories
US6415255B1 (en) Apparatus and method for an array processing accelerator for a digital signal processor

Legal Events

Date Code Title Description
AL Designated countries for regional patents

Kind code of ref document: A1

Designated state(s): AT BE CH CY DE DK ES FI FR GB GR IE IT LU MC NL PT SE TR

121 Ep: the epo has been informed by wipo that ep was designated in this application
122 Ep: pct application non-entry in european phase