Browse Prior Art Database

Optimized Local Variable Addressing for Personal Computers

IP.com Disclosure Number: IPCOM000115991D
Original Publication Date: 1995-Jul-01
Included in the Prior Art Database: 2005-Mar-30
Document File: 4 page(s) / 132K

Publishing Venue

IBM

Related People

Christopher Jr, KW: AUTHOR [+2]

Abstract

Disclosed is a software implementation for Personal Computers (PCs) to provide the ability to optimize local variable addressing. The implementation enables compilers and assembly coders, that use local variables allocated on a stack, to generate smaller and faster code.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 46% of the total text.

Optimized Local Variable Addressing for Personal Computers

      Disclosed is a software implementation for Personal Computers
(PCs) to provide the ability to optimize local variable addressing.
The implementation enables compilers and assembly coders, that use
local variables allocated on a stack, to generate smaller and faster
code.

      The optimization provides distinct advantages in that it allows
generated, or directly written, code to be smaller.  This is because
there are fewer two byte offsets needed to address data on a stack.
The speed of coding is enhanced because the code is smaller,
therefore, is able to execute faster because there are fewer two byte
offsets that are being prefetched into the processor's queue.

      Generally, compilers use a stack for passing parameters to
subroutines and for the allocation of local, or automatic variables.
This technique is useful in the generation of code by means of
compilers as well as assembly language coders.  Data that is put onto
the stack occurs at an unpredictable offset, and therefore, base
register addressing is used to access this type of data.  For typical
microprocessors used in PCs, this involves getting the current stack
pointer value from the SP register into one of four base registers;
BP, BX, SI, and DI.  Because the BP register defaults to the use of
the stack segment, addressed by the SS segment register, this is the
register of choice for accessing data on the stack.

      The other registers can be used as well.  However, since they
default to using the data segment, addressed by the DS segment
register, the use of other registers to address the stack data
requires the use of a stack segment override.  This is because the
override generates a stack segment prefix opcode byte.  Therefore,
using BX, SI, or DI requires additional bytes of code to be generated
causing the compiler to be very large and the code to be slow in
operation.

      When one piece of code calls another code, the parameters to be
passed are pushed onto the stack and the routine is called.  The call
can either be to code within the same code segment (near call) which
places a one word return address on the stack, or to a routine in
another code segment (far call) which places two words of return
address on the stack.  On entry, the routine may put additional data
onto the stack, such as saving of the entry value of the BP register.
At this point, the SP register contains a pointer to the next portion
of the stack to be used.  If a routine is going to allocate local
variables, they will occur below this point in the stack.  Typically,
the BP register is now set to point to the same location as the SP
register enabling the local variables to be allocated on the stack by
way of a SUB SP, immediate-value instruction, where the immediate
value is the site or the local variable pool.

      The Figure shows the format of the stack after allocation of
the local data...