intro.nr 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. .BP
  2. .S1 "INTRODUCTION"
  3. EM is a family of intermediate languages designed for producing
  4. portable compilers.
  5. The general strategy is for a program called
  6. .B front end
  7. to translate the source program to EM.
  8. Another program,
  9. .B back
  10. .BW end
  11. translates EM to target assembly language.
  12. Alternatively, the EM code can be assembled to a binary form
  13. and interpreted.
  14. These considerations led to the following goals:
  15. .IS 2 10
  16. .PS 1 4
  17. .PT
  18. The design should allow translation to,
  19. or interpretation on, a wide range of existing machines.
  20. Design decisions should be delayed as far as possible
  21. and the implications of these decisions should
  22. be localized as much as possible.
  23. .N
  24. The current microcomputer technology offers 8, 16 and 32 bit machines
  25. with various sizes of address space.
  26. EM should be flexible enough to be useful on most of these
  27. machines.
  28. The differences between the members of the EM family should only
  29. concern the wordsize and address space size.
  30. .PT
  31. The architecture should ease the task of code generation for
  32. high level languages such as Pascal, C, Ada, Algol 68, BCPL.
  33. .PT
  34. The instruction set used by the interpreter should be compact,
  35. to reduce the amount of memory needed
  36. for program storage, and to reduce the time needed to transmit
  37. programs over communication lines.
  38. .PT
  39. It should be designed with microprogrammed implementations in
  40. mind; in particular, the use of many short fields within
  41. instruction opcodes should be avoided, because their extraction by the
  42. microprogram or conversion to other instruction formats is inefficient.
  43. .PE
  44. .IE
  45. .A
  46. The basic architecture is based on the concept of a stack. The stack
  47. is used for procedure return addresses, actual parameters, local variables,
  48. and arithmetic operations.
  49. There are several built-in object types,
  50. for example, signed and unsigned integers,
  51. floating point numbers, pointers and sets of bits.
  52. There are instructions to push and pop objects
  53. to and from the stack.
  54. The push and pop instructions are not typed.
  55. They only care about the size of the objects.
  56. For each built-in type there are
  57. reverse Polish type instructions that pop one or more
  58. objects from the top of
  59. the stack, perform an operation, and push the result back onto the
  60. stack.
  61. For all types except pointers,
  62. these instructions have the object size
  63. as argument.
  64. .P
  65. There are no visible general registers used for arithmetic operands
  66. etc. This is in contrast to most third generation computers, which usually
  67. have 8 or 16 general registers. The decision not to have a group of
  68. general registers was fully intentional, and follows W.L. Van der
  69. Poel's dictum that a machine should have 0, 1, or an infinite
  70. number of any feature. General registers have two primary uses: to hold
  71. intermediate results of complicated expressions, e.g.
  72. .IS 5 0 1
  73. ((a*b + c*d)/e + f*g/h) * i
  74. .IE 1
  75. and to hold local variables.
  76. .P
  77. Various studies
  78. have shown that the average expression has fewer than two operands,
  79. making the former use of registers of doubtful value. The present trend
  80. toward structured programs consisting of many small
  81. procedures greatly reduces the value of registers to hold local variables
  82. because the large number of procedure calls implies a large overhead in
  83. saving and restoring the registers at every call.
  84. .BP
  85. .P
  86. Although there are no general purpose registers, there are a
  87. few internal registers with specific functions as follows:
  88. .IS 2
  89. .N 1
  90. .TS
  91. tab(:);
  92. l 1 l l.
  93. PC:-:Program Counter:Pointer to next instruction
  94. LB:-:Local Base:Points to base of the local variables \
  95. in the current procedure.
  96. SP:-:Stack Pointer:Points to the highest occupied word on the stack.
  97. HP:-:Heap Pointer:Points to the top of the heap area.
  98. .TE 1
  99. .IE
  100. .A
  101. Furthermore, reverse Polish code is much easier to generate than
  102. multi-register machine code, especially if highly efficient code is
  103. desired.
  104. When translating to assembly language the back end can make
  105. good use of the target machine's registers.
  106. An EM machine can
  107. achieve high performance by keeping part of the stack
  108. in high speed storage (a cache or microprogram scratchpad memory) rather
  109. than in primary memory.
  110. .P
  111. Again according to van der Poel's dictum,
  112. all EM instructions have zero or one argument.
  113. We believe that instructions needing two arguments
  114. can be split into two simpler ones.
  115. The simpler ones can probably be used in other
  116. circumstances as well.
  117. Moreover, these two instructions together often
  118. have a shorter encoding than the single
  119. instruction before.
  120. .P
  121. This document describes EM at three different levels:
  122. the abstract level, the assembly language level and
  123. the machine language level.
  124. .A
  125. The most important level is that of the abstract EM architecture.
  126. This level deals with the basic design issues.
  127. Only the functional capabilities of instructions are relevant, not their
  128. format or encoding.
  129. Most chapters of this document refer to the abstract level
  130. and it is explicitly stated whenever
  131. another level is described.
  132. .A
  133. The assembly language is intended for the compiler writer.
  134. It presents a more or less orthogonal instruction
  135. set and provides symbolic names for data.
  136. Moreover, it facilitates the linking of
  137. separately compiled 'modules' into a single program
  138. by providing several pseudoinstructions.
  139. .A
  140. The machine language is designed for interpretation with a compact
  141. program text and easy decoding.
  142. The binary representation of the machine language instruction set is
  143. far from orthogonal.
  144. Frequent instructions have a short opcode.
  145. The encoding is fully byte oriented.
  146. These bytes do not contain small bit fields, because
  147. bit fields would slow down decoding considerably.
  148. .P
  149. A common use for EM is for producing portable (cross) compilers.
  150. When used this way, the compilers produce
  151. EM assembly language as their output.
  152. To run the compiled program on the target machine,
  153. the back end, translates the EM assembly language to
  154. the target machine's assembly language.
  155. When this approach is used, the format of the EM
  156. machine language instructions is irrelevant.
  157. On the other hand, when writing an interpreter for EM machine language
  158. programs, the interpreter must deal with the machine language
  159. and not with the symbolic assembly language.
  160. .P
  161. As mentioned above, the
  162. current microcomputer technology offers 8, 16 and 32 bit
  163. machines with address spaces ranging from 2\v'-0.5m'16\v'0.5m'
  164. to 2\v'-0.5m'32\v'0.5m' bytes.
  165. Having one size of pointers and integers restricts
  166. the usefulness of the language.
  167. We decided to have a different language for each combination of
  168. word and pointer size.
  169. All languages offer the same instruction set and differ only in
  170. memory alignment restrictions and the implicit size assumed in
  171. several instructions.
  172. The languages
  173. differ slightly for the
  174. different size combinations.
  175. For example: the
  176. size of any object on the stack and alignment restrictions.
  177. The wordsize is restricted to powers of 2 and
  178. the pointer size must be a multiple of the wordsize.
  179. Almost all programs handling EM will be parametrized with word
  180. and pointer size.