All pastes #97592 Raw Edit

Pikhq

public text v1 · immutable
#97592 ·published 2006-07-23 21:52 UTC
rendered paste body
\documentclass[a4paper,12pt]{report}
\title{PicoCPU, v. 0.1}
\author{Nick Vanderweit and Josiah Worcester}
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
\subsection{What is PicoCPU?}
PicoCPU is a new CPU design which strives for simplicity. Instead of many computers which follow the CISC model, PicoCPU follows
 the RISC model.
While it could be designed so that it would only have one operation, the "subtract and branch if negative" operation, this would
 make it a serious burden on the programmer to implement more complex functions.
Therefore, it has been decided to add certain functions, such as NAND, to the list of operations.
\subsection{What isn't PicoCPU?}
\subsubsection{A practical design}
At the moment, this is mostly built for emulators as a toy. While it may progress into hardware and may branch off into somethin
g that is more than just a fun program, it is currently just that.
\subsubsection{Something big and hefty}
There is a reason for the name. Adding too many operations or too much functionality to the CPU itself would make it too big to
suit the purpose of this CPU design. Every feature added must be necessary.
\subsection{Goals}
PicoCPU, while a slightly frivolous project, has several important goals which make it unique.
\subsubsection{Smaller is better}
While it shouldn't be so small that it's impractical to program, new functionality should not be added without solid reason. If
something can (somewhat) easily be implemented as bytecode which can be run by the CPU, it should not be added as functionality
to the CPU itself.
\subsubsection{Follow the specifications}
This is especially important for reference. If a new person wants to help develop this project, he or she must be familiar with
the design. As such, everything must follow the specifications to give everyone a good idea of the design.

If it is necessary to add functionality to the emulator or a CPU to make it run better, then it is very important to add that to
 this document, which is under the GFDL, a license which permits the distribution and modification of it.
\section{The specification}
In the following, variables will be represented by lower-case letters, and asterisks (*) will denote pointers to locations to me
mory in C-style.
\subsection{Opcodes}
All opcodes are 8 bits.
\subsubsection{NL}
If NL is found where code is to be executed, nothing happens, and the memory address 1 above the NL one is then executed. This i
s good for parts of memory which serve as "placeholders" to be overwritten. By default, all parts of memory are NL. NL takes no
arguments.

Opcode: 0x00
\subsubsection{SBN}
The subtract-and-branch-if-negative operation is, by itself, Turing complete. This makes it very useful in certain cases, like O
ISC, because it can be used as the only operation on a computer.
However, certain things are extremely difficult to implement using only SBN, and that makes it impractical in many cases.

This operation takes the arguments a, b, *c, and *d. Basically, SBN subtracts b from a, stores the result in c, and jumps to d \
emph{only if the result is negative or zero}.

In the event that the result is nonzero and positive, then the next opcode in memory after d is read.

Opcode: 0x01
\subsubsection{NAND}
NAND is important because it can be used to implement many other bitwise operations. It can implement AND, OR, NOR, and XOR. It
takes the arguments a, b, and *c, and does a NAND b. It stores the result in c.

Opcode: 0x02
\subsubsection{ADD, DIV}
Both of these take exactly three arguments: a, b, and *c. a is added to or divided by b, and the result is stored in c.

ADD Opcode: 0x03

DIV Opcode: 0x04
\subsubsection{CPY}
CPY takes two arguments: *a and *b. Memory address a is simply copied to memory address b.

CPY Opcode: 0x05
\subsection{Memory}
PicoCPU takes a unique approach in that almost everything is represented by system memory. The system uses 8-bit addresses and h
as different ``banks'' to store more than that.
\subsubsection{Initial startup}
All memory is automatically set to NL. Machine code then replaces these addresses, and the opcode at 0x0 is run.
\subsubsection{Banks}
There are 255 banks, each holding 255 bytes of data.
The last four bytes in each bank are special, and allow the setting and reading of banks using them.
Bytes 252-255 are these special bytes. Reading byte 252 will return the current bank, and writing to it will set the current ban
k.
For temporary operations between two different banks, byte 253 can be set to a number between 0 and 255 to set a ``temporary'' b
ank.
Byte 254 can then be set to a temporary byte within this bank. After this, reading or writing from byte 255 will act upon the by
te that is set within the bank that is set.
This is so that data can be copied between multiple banks.

All of these banks can be written to and read from.

As an example, if byte 252 is set to 0, then the machine is working with the default bank of memory. Setting 253 to 1 and 254 to
 0 would allow us to access byte 0 on bank 1 using byte 255 to do the task. After some data is written to this bank, we can chan
ge banks to 1 simply by changing byte 252. These four bytes exist in every single bank.

Bank 255 is the "ROM" bank. It contains system information in it, as well as a part of memory for stdio, specifically for the em
ulator version. Bytes 249-251 are used specifically for stdio. 249 is for hex I/O, 250 for decimal, and 251 for ASCII. In the of
ficial implementation, the rest of the bytes are set to 0. Any modified versions should have at least one byte different.

Bank 254 is the ``register'' bank. While this is simply an ordinary bank, it should be used for storing data and \emph{not} opco
des.
\section{Conclusion}
\subsection{Improvements}
Improvements or ideas for the specification should be sent to nickv111@gmail.com so that they can be officially added. Please fe
el free to modify the TeX document itself and send the updated copy to that address if need be.
\subsection{Future releases}
\begin{itemize}
\item Integers, long ints, short ints
\item Floating-point operations (may be a while)
\end{itemize}
\section{Clean code}
Several operations, like ADD, are there specifically to promote cleaner code using less memory. For clean code practice, it is r
ecommended not to use SBN for anything but conditional operations.
\subsection{GNU Free Documentation License}
    Copyright (c)  2006  Nick Vanderweit.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.2
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license can be found at http://www.gnu.org/licenses/fdl.txt
\end{document}