1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
--------------------------------------------------------------------------
Apoo Assembly Language
---------------------------------------------------------------------------
All memory cells and registers have 32 bits.
Registers: R0,R1,R2,R3,R4,R5,R6,R7
---------
Memory Data:
-----------
The size of the RAM is predefined (e.g. 1K) and divided into two
areas: static memory and system stack. The static memory, begins at
address 0 and it is allocated when a Apoo program is loaded. Static
memory cells can be reserved in in two ways, using the following
pseudo-instructions:
Pseudo-instructions:
-------------------
Meaning
-------------------------------------------------
<Label:> mem n reserves n memory addresses
-------------------------------------------------
Label: const n2 contents of memory address
const n1 Label is n1, of Label+1 is n2
.
.
. ni can be a character 'c'
------------------------------------------------------------------
Label: equ n Allows a symbolic name for a number
-------------------------------------------------------------------
Label: string "seqNWSCharacteres" Allocates memory addresses
and set them to the
correspondent characters
ASCII codes. The
characters cannot be
whitespaces: use \s for space
\t for tab and \n for newline
----------------------------------------------------------------------
Label is any string begining with a letter and containing only letters
and digits with the exception of legal register names. If exists, must
begin in the first column of a line
NOTE: Every memory address refered, must have been reserved by
one of the previous pseudo-instructions.
E.g. the instruction "load 3 R2", will cause an "Out of Memory" error, if
at least "mem 3" or three "const" pseudo-instructions were not given...
If a "equ" value is used as a memory address, that address must
be already reserved or be a known memory-mapped instruction. The
"string" argument must be quoted and is converted to a sequence of ascii
codes ending with 0.
-----------------------------------------------------------------------
System Stack:
------------
The system stack occupies the rest
of the RAM (growing for higher addresses). Since Apoo version 3.0 it can be used in an
advanced way to implement activation records.
However in can be used in a simpler way to implement subroutines. We can only push
a value to the Stack and pop a value from it (the one in the
top of the Stack). It
is used by the instructions jsr and rtn.
It can be manipulated by means of the push and pop instructions.
-----------------------------------------------------------------------
Memory mapped:
-------------
It is possible to associate to special memory positions a special
effect. Currently this is used for input/output:
store R0 50000 # writes character with ascii code R0%256
load 50000 R0 # loads R0 with 0 (do nothing)
store R0 50001 # writes the contents of R0 as integer
load 50001 R0 # reads an integer and stores it in R0
store R0 50010 # writes a CR
load 50010 R0 # loads R0 with 0 (do nothing)
Instruction form:
----------------
<Label:> Operation <Operand1> <Operand2>
Label is any string of letters or digits; if exists, must begin in the
first column of a line
Comments:
--------
A line beginnig with # will be ignored by the parser; so it can be
used to write comments of the program
Basic Instruction Set:
---------------------
--------------------------------------------------------------------------
Operation Operand1 Operand2 Meanning
--------------------------------------------------------------------------
load Mem Ri loads contents of memory
address Mem into register Ri;
Mem can be a label
--------------------------------------------------------------------------
loadn Num Ri loads number Num into register
Ri; Num can be a label
--------------------------------------------------------------------------
loadi Ri Rj loads contents of memory
which address is the contents
of Ri into Rj (indirect load)
--------------------------------------------------------------------------
store Ri Mem stores contents of Ri at memory
address Mem; Mem can be a label
--------------------------------------------------------------------------
storer Ri Rj stores contents of Ri into Rj
--------------------------------------------------------------------------
storei Ri Rj stores contents of Ri
into at memory address, which is the
contents of Rj
--------------------------------------------------------------------------
add Ri Rj add contents of register Ri to
contents of register Rj, and
stores into Rj (Rj=Ri+Rj)
--------------------------------------------------------------------------
sub Ri Rj subtracts contents of register
Rj from contents of register Rj
and stores into Rj (Rj=Ri-Rj)
--------------------------------------------------------------------------
mul Ri Rj multiplies contents of register
Ri and contents of register
Rj, and stores into Rj (Rj=Ri*Rj)
--------------------------------------------------------------------------
div Ri Rj stores into Rj the quotient of integer
division of contents register
Ri by the contents of register
Rj, and stores into Rj (Rj=Ri/Rj)
--------------------------------------------------------------------------
mod Ri Rj stores into Rj the rest of integer
division of contents of register
Ri by the contents of register
Rj, and stores into Rj (Rj=Ri%Rj)
--------------------------------------------------------------------------
zero Ri the contents of Ri becomes 0 (Ri=0)
--------------------------------------------------------------------------
inc Ri increments by 1 the contents of Ri
--------------------------------------------------------------------------
dec Ri decrements by 1 the contents of Ri
--------------------------------------------------------------------------
jump Addr jumps to instruction address Addr;
Addr can be a Label
--------------------------------------------------------------------------
jzero Ri Addr jumps to instruction address Addr,
if contents of Ri is zero;
Addr can be a Label
--------------------------------------------------------------------------
jpos Ri Addr jumps to instruction address Addr,
if contents of Ri is positiv;
Addr can be a Label
--------------------------------------------------------------------------
jneg Ri Addr jumps to instruction address Addr,
if contents of Ri is negativ
--------------------------------------------------------------------------
jnzero Ri Addr jumps to instruction address Addr,
if contents of Ri is different
from zero
---------------------------------------------------------------------------
jsr Addr pushes the PC into the stack and
jumps to instruction address Addr
--------------------------------------------------------------------------
rtn pops an address from the stack
into the PC
--------------------------------------------------------------------------
push Ri pushes the contents of Ri into the
system stack
--------------------------------------------------------------------------
pop Ri pops at element from the system stack
into Ri
--------------------------------------------------------------------------
halt stops execution; Every program
must have this instruction in order
to end properly; otherwise an
'Out of Program' error will occur
--------------------------------------------------------------------------
Activation Records Management
----------------------------
There are two programmable
registers to address the system stack: stack register and frame
register. They correspond to the last two registers of a Apoo vpu
configuration, Rn-1 and Rn-2, but are aliased to rs
and rf, respectively. The stack register rs
contains the address of the last stack memory cell (or -1 if no static
memory is allocated). The instructions jsr, rtn,
push and pop manipulates the stack in the usual way.
Besides that, the contents of the stack register can be manipulated as
any other register.
The frame register can be
used for the implementation of local information (on the system stack).
It contents should be the first stack address of the current activation
record. Like the stack register it can be manipulated as any other
register, but it is also used in two special instructions:
storeo and loado.
- storeo Ri Num: stores the contents of register
Ri at memory address (rf) + Num, where Num is an integer.
- loadeo Num Ri: loads the contents of memory
address (rf) + Num into register Ri, where Num is an integer.
In both instructions, if Num is non negative it should correspond
to local memory and if it is negative, possibly corresponds to arguments of a
subroutine call.
------------------------- The End ---------------------------------------
|