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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Apoo assembly language</title>
</head>
<body>
<h1><tt>Apoo</tt> assembly language</h1>
<tt>Apoo</tt> has a set of general purpose
registers (32 by default), a data memory area, a program memory
area, a system stack and a program counter register.
<p>All memory cells and registers have 32 bits.</p>
<p>Registers are named R0,R1,R2,R3,R4,R5,R6,R7,...</p>
<h2>Memory Data</h2>
Memory cells are created as needed. We can reserve memory cells
in two ways, using the following pseudo-instructions:
<h2>Pseudo-instructions</h2>
<p>
<table border="1" cellpadding="3">
<tbody>
<tr>
<td align="left"> </td>
<td align="left"> </td>
<td width="170"> </td>
<th width="170"><span class="textbf">Meaning</span></th>
</tr>
<tr>
<td align="left"><tt><Label:></tt></td>
<td align="left"><tt>mem</tt></td>
<td width="170"><tt>n</tt></td>
<td width="170">reserves n memory addresses</td>
</tr>
<tr>
<td align="left"><tt>Label:</tt></td>
<td align="left"><tt>const</tt></td>
<td width="170"><tt>n1</tt></td>
<td width="170">contents of memory address</td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"><tt>const</tt></td>
<td width="170"><tt>n2</tt></td>
<td width="170"><tt>Label</tt> is <tt>n1</tt>, of Label+1 is <tt>n2</tt></td>
</tr>
<tr>
<td align="left"> </td>
<td align="left"> </td>
<td width="170">....</td>
<td width="170"><tt>ni</tt> can be a character <tt>'c'</tt>.</td>
</tr>
<tr>
<td align="left"><tt><Label:></tt></td>
<td align="left"><tt>equ</tt></td>
<td width="170"><tt>n</tt></td>
<td width="170">Allows a symbolic
name for a number</td>
</tr>
<tr>
<td align="left"><tt><Label:></tt></td>
<td align="left"><tt>string</tt></td>
<td width="170"><tt>"seqNWSCharacteres"</tt></td>
<td width="170">Allocates memory
addresses and set them to the correspondent characters ASCII
codes. The characters cannot be whitespaces: use <code>\s</code> for
<tt>space</tt>, <code>\t</code> for <tt>tab</tt> and <code>\n</code> for <tt>newline</tt>.</td>
</tr>
</tbody>
</table>
</p>
<p><tt>Label</tt> is any string beginning 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</p>
<p><span class="textbf">NOTE:</span> Every memory address refered, must have been reserved by
one of the previous pseudo-instructions.</p>
<p>E.g. the instruction <tt>load 3 R2</tt>, will cause an <tt>Out of
Memory</tt> error, if at least <tt>mem 3</tt> or three <tt>const</tt>
pseudo-instructions were not given...
If a <tt>equ</tt> value is used as a memory address, that address must
be already reserved or be a known memory-mapped instruction. The
<tt>string</tt> argument must be quoted and is converted to a sequence of ascii
codes ending with <tt>0</tt>.</p>
<h2>System Stack</h2>
<p>A special memory area used 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 <tt>push</tt> and <tt>pop</tt> instructions.</p>
<h2>Instruction Form</h2>
<pre><Label:> Operation <Operand1> <Operand2><br></pre>
<p><tt>Label</tt> is any string of letters or digits; if exists, must begin in the
first column of a line</p>
<h2>Comments</h2>
<p>A line beginning with # will be ignored by the parser; so it can be
used to write comments of the program</p>
<h2>Instruction Set</h2>
<p>
<table border="1" cellpadding="3">
<tbody>
<tr>
<td style="font-weight: bold;" align="left">Operation</td>
<td style="font-weight: bold;" align="left">Operand1</td>
<td style="font-weight: bold;" align="left">Operand2</td>
<td style="font-weight: bold;" width="227">Meanning</td>
</tr>
<tr>
<td align="left">load</td>
<td align="left">Mem</td>
<td align="left">Ri</td>
<td width="227">loads contents of memory
address Mem into register Ri;
Mem can be a label</td>
</tr>
<tr>
<td align="left">loadn</td>
<td align="left">Num</td>
<td align="left">Ri</td>
<td width="227">loads number Num into register
Ri; Num can be a label</td>
</tr>
<tr>
<td align="left">loadi</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">loads contents of memory
which address is the contents
of Ri into Rj (indirect load)</td>
</tr>
<tr>
<td align="left">store</td>
<td align="left">Ri</td>
<td align="left">Mem</td>
<td width="227">stores contents of Ri at memory
address Mem; Mem can be a label</td>
</tr>
<tr>
<td align="left">storer</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">stores contents of Ri into Rj</td>
</tr>
<tr>
<td align="left">storei</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">stores contents of Ri
into at memory address, which is the
contents of Rj</td>
</tr>
<tr>
<td align="left">add</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">add contents of register Ri to
contents of register Rj, and
stores into Rj (Rj=Ri+Rj)</td>
</tr>
<tr>
<td align="left">sub</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">subtracts contents of register
Rj from contents of register Rj
and stores into Rj (Rj=Ri-Rj)</td>
</tr>
<tr>
<td align="left">mul</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">multiplies contents of register
Ri and contents of register
Rj, and stores into Rj (Rj=Ri*Rj)</td>
</tr>
<tr>
<td align="left">div</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">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)</td>
</tr>
<tr>
<td align="left">mod</td>
<td align="left">Ri</td>
<td align="left">Rj</td>
<td width="227">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)</td>
</tr>
<tr>
<td align="left">zero</td>
<td align="left">Ri</td>
<td align="left"> </td>
<td width="227">the contents of Ri becomes 0 (Ri=0)</td>
</tr>
<tr>
<td align="left">inc</td>
<td align="left">Ri</td>
<td align="left"> </td>
<td width="227">increments by 1 the contents of Ri</td>
</tr>
<tr>
<td align="left">dec</td>
<td align="left">Ri</td>
<td align="left"> </td>
<td width="227">decrements by 1 the contents of Ri</td>
</tr>
<tr>
<td align="left">jump</td>
<td align="left">Addr</td>
<td align="left"> </td>
<td width="227">jumps to instruction address Addr;
Addr can be a Label</td>
</tr>
<tr>
<td align="left">jzero</td>
<td align="left">Ri</td>
<td align="left">Addr</td>
<td width="227">jumps to instruction address Addr,
if contents of Ri is zero;
Addr can be a Label</td>
</tr>
<tr>
<td align="left">jnzero</td>
<td align="left">Ri</td>
<td align="left">Addr</td>
<td width="227"> jumps to instruction address Addr,
if contents of Ri is different
from zero;</td>
</tr>
<tr>
<td align="left">jpos</td>
<td align="left">Ri</td>
<td align="left">Addr</td>
<td width="227">jumps to instruction address Addr,
if contents of Ri is positiv;
Addr can be a Label</td>
</tr>
<tr>
<td align="left">jneg</td>
<td align="left">Ri</td>
<td align="left">Addr</td>
<td width="227">jumps to instruction address Addr,
if contents of Ri is
negativ</td>
</tr>
<tr>
<td align="left">jnzero</td>
<td align="left">Ri</td>
<td align="left">Addr</td>
<td width="227">jumps to instruction address Addr,
if contents of Ri is different
from zero;
Addr can be a Label</td>
</tr>
<tr>
<td align="left">jsr</td>
<td align="left">Addr</td>
<td align="left"> </td>
<td width="227">pushes the PC into the stack and
jumps to instruction address Addr</td>
</tr>
<tr>
<td align="left">rtn</td>
<td align="left"> </td>
<td align="left"> </td>
<td width="227">pops an address from the stack
into the PC</td>
</tr>
<tr>
<td align="left">push</td>
<td align="left">Ri</td>
<td align="left"> </td>
<td width="227">pushes the contents of Ri into the
system stack</td>
</tr>
<tr>
<td align="left">pop</td>
<td align="left">Ri</td>
<td align="left"> </td>
<td width="227">pops at element from the system stack
into Ri</td>
</tr>
<tr>
<td align="left">halt</td>
<td align="left"> </td>
<td align="left"> </td>
<td width="227">stops execution; Every program
must have this instruction in order
to end properly; otherwise an
'Out of Program' error will occur</td>
</tr>
</tbody>
</table>
</p>
<h2>Memory-Mapped Instructions</h2>
<p><tt>Apoo</tt> allows the configuration of a set of memory positions for
special purposes. The memory values and its functionality are given as
a parameter of the Apoo virtual machine.
The default values allow the simulation of input/output:</p>
<table style="text-align: left;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td><span style="font-weight: bold;">Memory Position</span></td>
<td><span style="font-weight: bold;">Load</span></td>
<td width="227"><span style="font-weight: bold;">Store</span></td>
</tr>
<tr>
<td>50000</td>
<td><tt>load 50000 Ri<br>
<br>
</tt>loads 0 in <tt>Ri</tt></td>
<td width="227"><tt>store Ri 50000<br>
<br>
</tt>writes the character which ascii code is
<tt>Ri%256</tt> in the Output Window (in graphical interface) or in stdout,
in text mode.</td>
</tr>
<tr>
<td>50001</td>
<td><tt>load 50001 Ri<br>
<br>
</tt>reads an integer and stores it in Ri</td>
<td width="227"><tt>store Ri 50001<br>
<br>
</tt>writes the contents of Ri as an integer</td>
</tr>
<tr>
<td>50010</td>
<td><tt>load 50010 Ri<br>
<br>
</tt>loads 0 in <tt>Ri</tt></td>
<td width="227"><tt>store Ri 50010<br>
<br>
</tt>writes a CR in the Output Window (in graphical interface) or in stdout,
in text mode.</td>
</tr>
</tbody>
</table>
<p><br>
<br>
Here is an example:
</p>
<pre> loadn 97 R0<br> store R0 50000<br> store R0 50010<br> store R0 50001<br> store R0 50010<br> load 50001 R0<br> loadn 5 R1<br> add R0 R1<br> store R0 50001<br> store R0 50010<br> halt<br></pre>
<hr>
<p>© 1998-2006 Rogerio Reis, Nelma Moreira {rvr,nam}@ncc.up.pt</p>
</body>
</html>
|