Next: The Heap Allocator
Up: Hardware Components
Previous: The Processor
Contents
Index
- (CORE/MEMORY.JAVA,
- CORE/SAMMEMORY.JAVA)
Memory is responsible for data storage. It is capable of storing data
of size Memory.UNIT_SIZE bits in each of Memory.MEMORYLIMIT locations.
It is implemented in SamMemory as an array of integers. SaM memory
is typed - it supports associating a data type with each memory location.
This functionality can be used for error checking, presentation clarity,
or other purposes. Internally, type and data information alternate
locations, but this is not visible to the end user. The API provides
methods for setting and getting data and type separately, or simultaneously,
using the Memory.Data wrapper object. SaM memory is divided into two
zones - stack and heap. The boundary between them is fixed at Memory.STACKLIMIT
(the last stack location).
Types
The following data types are supported:
- Integer (INT)
When an integer value is requested as an integer, a standard Java
integer containing the value should be returned.
- Floating Point (FLOAT)
When a floating point value is requested as an integer, an IEEE 754
representation of the floating point number should be returned.
- Character (CH)
When a character is requested as an integer, the ASCII value of the
character should be returned.
- Memory Address (MA)
When a memory address is requested as an integer, its location in
memory should be returned as an integer.
- Program Address (PA)
When a program address is requested as an integer, the location should
be returned as an integer.
General Access
All memory locations can be accessed using the following methods:
- Data getMem (int pos) - retrieve the Data object at this location
- int getValue (int pos) - retrieve the value at this location
- Type getType (int pos) - retrieve the type at this location
- void setMem (int pos, Memory.Data data) - store a Data object at this
location
- void setMem (int pos, int data, Memory.Type type) - store a (type,
value) pair at this location
- void setValue (int pos, int data) - set the value at this location
- void setType (int pos, Memory.Type type) - set the type at this location
Stack Zone
The stack can be manipulated specifically using the following functions:
- void push (Memory.Data data) - pushes a Data object on the stack
- void push (int value, Memory.Type type) - pushes the value and type
separately
- void pushINT (int i) - pushes value with type integer
- void pushCH (char ch) - pushes value with type character
- void pushMA (int ma) - pushes value with type memory address
- void pushPA (int pa) - pushes value with type program address
- void pushFLOAT (float fl) - pushes value with type floating point
- Memory.Data pop () - pops a Data object off the stack
- int popValue () - pops a value as an integer off the stack
- int popINT () - pops an integer value off the stack
- char popCH () - pops a character value off the stack
- int popMA () - pops a memory address value off the stack
- int popPA () - pops a program address value off the stack
- float popFLOAT () - pops a floating point value off the stack
- public List<Memory.Data> getStack () - retrieves the entire stack
as a list of Data objects
Heap Zone
The heap zone is manipulated using a HeapAllocator. It is used for
dynamic allocation of memory space. Memory provides the following
methods for working with the heap zone:
- HeapAllocator getHeapAllocator () - obtain the heap allocator
- void setHeapAllocator (HeapAllocator heap) - set the heap allocator
- public List<Memory.Data> getAllocation (HeapAllocator.Allocation alloc)
- retrieves a heap memory allocation as a list of Data objects
Next: The Heap Allocator
Up: Hardware Components
Previous: The Processor
Contents
Index
David Levitan
2006-02-12