EPOC   SDK Home Glossary   Previous Next Up

How OPL stores values


Contents

OPL stores its variables’ data in memory in a specific format; this topic details the sequences of memory bytes used for different data types.

Usually you would find out the byte address with the ADDR function. For example, if var% has the value 7, PEEKW(ADDR(var%)) returns 7.

See also the PEEK and POKE commands and ADDR. See also 32-bit addressing.

MARM, WINS

Under both the WINS and MARM platforms, the byte with the lower address is the least significant — MARM and WINS are both little-endian.

Future EPOC devices may use a different machine word format.


Integers

Integers are stored in two bytes. The first byte is the least significant byte, for example:

    1   0            = 1
    0   1            = 256

ADDR returns the address of the first (least significant) byte.


Long integers

Long integers are stored in four bytes, the least significant first and the most significant last, for example:

    0   0   1   0      = 65536

ADDR returns the address of the first (least significant) byte.


Strings

Strings are stored with one character per byte, with a leading byte containing the string length, e.g.:

    3   65  66  67      = "ABC"

Each letter is stored as its character code - for example, A as 65.

For example, if var$="ABC", PEEK$(ADDR(var$)) will return the string ABC. ADDR returns the address of the length byte.


Floating-point values

Floating-point numbers are stored in IEEE format across eight bytes. PEEKF automatically reads all eight bytes and returns the number as a floating-point. For example if var=1.3 then PEEKF(ADDR(var)) returns 1.3.


Arrays

You can use ADDR to find the address of the first element in an array, for example ADDR(x%()), you can also specify individual elements of the array, for example ADDR(x%(2)).

The length of the array is stored in the two bytes immediately before the first element, and can be examined with PEEKW:

    proc demopeek:
          local ar%(42)
          print peekw(addr(ar%()) - 2)
          get
    endp
EPOC       SDK Home Glossary   Previous Next Up