Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
命令一覧
halt
nop
add
sub
and
or
xor
not
ld: load
st: store
mv: move register
mvi: move immediate
mvih: move immediate high
sr: shift right
sl: shift left
sra: shift right arithmetic
ceq: compare equal
cgt: compare grater than
cgta: compare grater than arithmetic
bc: branch condition
bl: branch link
ba: branch absolute
オプションの追加命令
in
out
mul
public class SimpleCPU
{ // インストラクション・メモリー
private final int[] mem_i = new int[256]; // データ・メモリー
private final int[] mem_d = new int[256]; // レジスタファイル
private final int[] reg = new int[16];
private int reg_d; // プログラム・カウンター
private int pc; // 入出力ポート
public int port_out;
public int port_in;
// オペコード
private static final int I_HALT = 0x00;
private static final int I_LD = 0x01;
private static final int I_ST = 0x02;
private static final int I_BC = 0x03;
private static final int I_BL = 0x04;
private static final int I_BA = 0x05; // 1 cycle instructions
private static final int I_NOP = 0x40;
private static final int I_ADD = 0x41;
private static final int I_SUB = 0x42;
private static final int I_AND = 0x43;
private static final int I_OR = 0x44;
private static final int I_XOR = 0x45;
private static final int I_NOT = 0x46;
private static final int I_MV = 0x47;
private static final int I_MVI = 0x48;
private static final int I_MVIH = 0x49;
private static final int I_SR = 0x4a;
private static final int I_SL = 0x4b;
private static final int I_SRA = 0x4c;
private static final int I_CEQ = 0x4d;
private static final int I_CGT = 0x4e;
private static final int I_CGTA = 0x4f;
private static final int I_IN = 0x50;
private static final int I_OUT = 0x51;
private static final int I_MUL = 0x52;