OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [core/] [9x8/] [doc/] [tips_and_tricks.html] - Blame information for rev 11

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sinclairrf
<!-- Copyright 2012, Sinclair R.F., Inc. -->
2
<html>
3
<title>
4
9x8 Tips and Tricks
5
</title>
6
<body>
7
Copyright 2012, Sinclair R.F., Inc.<br/><br/>
8
This file lists some tips and tricks for efficiently using the 9x8 instructions
9
  set.<br/><br/>
10
<h1>Multi-Byte Numeric Operations</h1>
11
The 9x8 core does not have built-in multi-byte instructions, however, common
12
  operations such as incrementing and decrementing multi-byte counts easily fit
13
  in the provided instruction set.<br/><br/>
14
  <h2>Incrementing and Decrementing multi-byte values</h2>
15
    If the top two bytes of the data stack are
16
      <tt>(&nbsp;u_16_LSB&nbsp;u_16_MSB&nbsp;)</tt>, then this value can be
17
      incremented by the following 6&nbsp;instructions: This increments the LSB
18
      of the two-byte value and, if the resulting LSB is zero, subtracts
19
      <tt>-1</tt> from the MSB.<br/><br/>
20
      <tt>&nbsp;&nbsp;swap&nbsp;1+&nbsp;swap&nbsp;over&nbsp;0=&nbsp;-</tt><br/><br/>
21
    Incrementing a 3&nbsp;byte or larger value is similar, except that the MSBs
22
      must be pushed onto the return stack instead of using the <tt>swap</tt>
23
      instruction.  For example, to increment a 24-bit count, use the following
24
      11&nbsp;instructions:<br/><br/>
25
      <tt>&nbsp;&nbsp;&gt;r&nbsp;swap&nbsp;1+&nbsp;swap&nbsp;over&nbsp;0=&nbsp;-&nbsp;r&gt;&nbsp;over&nbsp;0=&nbsp;-</tt><br/><br/>
26
    Adding larger increments can be done similarly.  For example to add four to
27
      a two-byte multiple of four, change the "<tt>1+</tt>" increment operations
28
      to the two instruction "<tt>4&nbsp;+</tt> sequence:<br/><br/>
29
      <tt>&nbsp;&nbsp;swap&nbsp;4&nbsp;+&nbsp;swap&nbsp;over&nbsp;0=&nbsp;-</tt><br/><br/>
30
      If the count is not guaranteed to be a multiple of four, use the
31
      following:<br/><br/>
32
      <tt>&nbsp;&nbsp;swap&nbsp;4&nbsp;+&nbsp;swap&nbsp;over&nbsp;0xFC&nbsp;&amp;&nbsp;0=&nbsp;-</tt><br/><br/>
33
    Decrementing multi-byte values is similar.  For example, to decrement a
34
      two-byte count, use the following: This decrements the LSB of the two-byte
35
      value and, if the resulting LSB is <tt>0xFF</tt>, adds <tt>-1</tt> to the
36
      MSB.<br/><br/>
37
      <tt>&nbsp;&nbsp;swap&nbsp;1-&nbsp;swap&nbsp;over&nbsp;-1=&nbsp;+</tt><br/><br/>
38
    A&nbsp;function to add a power of two to a two-byte quantity could be
39
      implemented as follows.  This works by adding the increment to the LSB and
40
      then masking the new LSB with <tt>256-u_increment</tt>.  As&nbsp;an
41
      example, the value <tt>4</tt> can be added to the two-byte value on the
42
      top of the data stack through
43
      "<tt>.call(u16_add_power_of_2,4)</tt>".<br/><br/>
44
      <tt>&nbsp;&nbsp;;&nbsp;Add&nbsp;a&nbsp;power&nbsp;of&nbsp;2&nbsp;to&nbsp;a&nbsp;two-byte&nbsp;value:&nbsp;&nbsp;u_16_new&nbsp;=&nbsp;u_16&nbsp;+&nbsp;u_increment<br/>
45
      &nbsp;&nbsp;;&nbsp;(&nbsp;u_16_LSB&nbsp;u_16_MSB&nbsp;u_increment&nbsp;-&nbsp;u_16_new_LSB&nbsp;u_16_new_MSB&nbsp;)<br/>
46
      &nbsp;&nbsp;.function&nbsp;u16_add_power_of_2<br/>
47
      &nbsp;&nbsp;&nbsp;&nbsp;&gt;r&nbsp;swap&nbsp;r@&nbsp;+&nbsp;swap&nbsp;over&nbsp;0&nbsp;r&gt;&nbsp;-&nbsp;&amp;&nbsp;0=<br/>
48
      &nbsp;&nbsp;.return(-)</tt><br/><br/>
49
</body>
50
</html>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.