Pristine Ack-5.5
[Ack-5.5.git] / doc / em / mem.nr
1 .bp
2 .P1 MEMORY
3 .PP
4 The EM machine has two distinct address spaces,
5 one for instructions and one for data.
6 The data space is divided up into 8-bit bytes.
7 The smallest addressable unit is a byte.
8 Bytes are numbered consecutively from 0 to some maximum.
9 All sizes in EM are expressed in bytes.
10 .PP
11 Some EM instructions can transfer objects containing several bytes
12 to and/or from memory.
13 The size of all objects larger than a word must be a multiple of
14 the wordsize.
15 The size of all objects smaller than a word must be a divisor
16 of the wordsize.
17 For example: if the wordsize is 2 bytes, objects of the sizes 1,
18 2, 4, 6,... are allowed.
19 The address of such an object is the lowest address of all bytes it contains.
20 For objects smaller than the wordsize, the
21 address must be a multiple of the object size.
22 For all other objects the address must be a multiple of the
23 wordsize.
24 For example, if an instruction transfers a 4-byte object to memory at
25 location \fIm\fP and the wordsize is 2,
26 \fIm\fP must be a multiple of 2 and the bytes at
27 locations \fIm\fP, \fIm\fP\|+\|1,\fIm\fP\|+\|2 and
28 \fIm\fP\|+\|3 are overwritten.
29 .PP
30 The size of almost all objects in EM
31 is an integral number of words.
32 Only two operations are allowed on
33 objects whose size is a divisor of the wordsize:
34 push it onto the stack and pop it from the stack.
35 The addressing of these objects in memory is always indirect.
36 If such a small object is pushed onto the stack
37 it is assumed to be a small integer and stored
38 in the least significant part of a word.
39 The rest of the word is cleared to zero,
40 although
41 EM provides a way to sign-extend a small integer.
42 Popping a small object from the stack removes a word
43 from the stack, stores the least significant byte(s)
44 of this word in memory and discards the rest of the word.
45 .PP
46 The format of pointers into both address spaces is explicitly undefined.
47 The size of a pointer, however, is fixed for a member of EM, so that
48 the compiler writer knows how much storage to allocate for a pointer.
49 .PP
50 A minor problem is raised by the undefined pointer format.
51 Some languages, notably Pascal, require a special,
52 otherwise illegal, pointer value to represent the nil pointer.
53 The current Pascal-VU compiler uses the
54 integer value 0 as nil pointer.
55 This value is also used by many C programs as a normally impossible address.
56 A better solution would be to have a special
57 instruction loading an illegal pointer value,
58 but it is hard to imagine an implementation
59 for which the current solution is inadequate,
60 especially because the first word in the EM data space
61 is special and probably not the target of any pointer.
62 .PP
63 The next two chapters describe the EM memory
64 in more detail.
65 One describes the instruction address space,
66 the other the data address space.
67 .PP
68 A design goal of EM has been to allow
69 its implementation on a wide range of existing machines,
70 as well as allowing a new one to be built in hardware.
71 To this extent we have tried to minimize the demands
72 of EM on the memory structure of the target machine.
73 Therefore, apart from the logical partitioning,
74 EM memory is divided into 'fragments'.
75 A fragment consists of consecutive machine
76 words and has a base address and a size.
77 Pointer arithmetic is only defined within a fragment.
78 The only exception to this rule is comparison with the null
79 pointer.
80 All fragments must be word aligned.