td4sim

package module
v0.0.0-...-7022733 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 1 Imported by: 0

README

td4sim

This is 4bit CPU Simulator made using only NAND and Latch. See Japanese book "How to make CPU" (ISBN4-8399-0986-5) for details.

TD4とは『CPUの創りかた - IC10個のお手軽CPU設計超入門 初歩のデジタル回路動作の基本原理と製作』で 説明されている4bitCPU。これを NAND と Latch から始めて 各IC部品の動作を組み立て、最終的にTD4として動くように作った。

How to use

td4sim [OPTIONS]

If there is no option, a demo instruction add 1 to register A and B is loaded.
And the clock advances automatically.

  OPTIONS:
    -load=FILE  ... load memory image text.
    -dipsw=0000 ... load dipsw initial status.
    -manual     ... clock ticking by hand.
-load=FILE

  プログラムメモリを記述したテキストファイルを読む
  テキストファイルは一行に8bit分、改行区切りで16行分
  8bitは最上位ビットが先頭、最下位ビットが最後になる
  0 または 1 を並べて記述する、スペースは無視される
  #は以降はコメント
  指定しない場合は、A,Bレジスタに交互に1をADDする
  プログラムがロードされる

-dipsw=0000

  ロード時のDIPスイッチの状態を0または1を並べて4bit分記述する
  4bitは最上位ビットが先頭、最下位ビットが最後になる
  指定しない場合は 0000 となる

-manual

  クロックを手動で動かす
  指定しない場合は 1Hz で自動でクロックが動く

Demo

repeat ADD A,0b0001 and ADD B,0b0001 endlessly.

Instructions

Memory is 8bit x 16words. There is also a 4bit DIPSW for input.

High     Low      Input 
7 6 5 4  3 2 1 0  dipsw carry | mnemonic
------------------------------|------------
0 0 1 1  d a t a  ----  -     | MOV A,data
0 1 1 1  d a t a  ----  -     | MOV B,data
0 0 0 1  0 0 0 0  ----  -     | MOV A,B
0 1 0 0  0 0 0 0  ----  -     | MOV B,A
0 0 0 0  d a t a  ----  -     | ADD A,data
0 1 0 1  d a t a  ----  -     | ADD B,data
0 0 1 0  0 0 0 0  data  -     | IN  A,data(dipsw)
0 1 1 0  0 0 0 0  data  -     | IN  B,data(dipsw)
1 0 1 1  d a t a  ----  -     | OUT data == MOV C,data
1 0 0 1  0 0 0 0  ----  -     | OUT B    == MOV C,B
1 1 1 1  d a t a  ----  -     | JMP data
1 1 1 0  d a t a  ----  c     | JNC data (jump if carry==0)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Counter4

func Counter4(d0, d1, d2, d3, load, clear *Line) []*Line

func Decoder

func Decoder(op0, op1, op2, op3, ncflg *Line) (sela, selb *Line, nload [4]*Line)

func IC74HC153

func IC74HC153(c10, c11, c12, c13, c20, c21, c22, c23, a, b *Line) (y1, y2 *Line)

IC74HC153 is Selector

func IC74HC161C

func IC74HC161C(d0, d1, d2, d3, nload, nclear *Line) (q []*Line)

func IC74HC161R

func IC74HC161R(d0, d1, d2, d3, nload, nclear *Line) (q []*Line)

func IC74HC283

func IC74HC283(a0, a1, a2, a3, b0, b1, b2, b3, c0 *Line) (s [4]*Line, c4 *Line)

IC74HC283 is 4bit full adder

func IC74HC74

func IC74HC74(d, nclear *Line) (q, nq *Line)

IC74HC74 is D-type flip-flop

func Initialize

func Initialize()

func ROM

func ROM(memory [][]*Line, in []*Line) (out []*Line)

ROM is 8bit x 16word memory. Looping 8 times after enabling one of the selectors to retrieve memory contents. For example, if you want to get the last memory:

Input          Selector     Memory
                            +---------------+  <-+
(H,H,H,H)      s[0] ---->   | 8bit          |    |
                    (L)     +---------------+    |
[4]in          s[1] ---->   | ....          |    | 16
  |                 (L)     +---------------+    | word
  +-> BDec ->  s[n] ---->   | ....          |    |
                    (L)     +---------------+    |
               s[15] --->   | 8bit (Target) |    |
                    (H)     +---------------+  <-+
                               |
                               | x 8times loop
                               |
                               +---> [8]out

func Register4

func Register4(d0, d1, d2, d3, load, clear *Line) []*Line

func TickTock

func TickTock()

func ToString

func ToString(list []int) string

Types

type CPUInfo

type CPUInfo struct {
	// contains filtered or unexported fields
}

func MakeTD4

func MakeTD4(image [][]int, dipsw []int) *CPUInfo

func (*CPUInfo) ChangeDIPSW

func (c *CPUInfo) ChangeDIPSW(sw int)

func (*CPUInfo) GetStateOfCarryFlag

func (c *CPUInfo) GetStateOfCarryFlag() []int

func (*CPUInfo) GetStateOfDIPSW

func (c *CPUInfo) GetStateOfDIPSW() []int

func (*CPUInfo) GetStateOfMemory

func (c *CPUInfo) GetStateOfMemory() [][]int

func (*CPUInfo) GetStateOfProgramCounter

func (c *CPUInfo) GetStateOfProgramCounter() []int

func (*CPUInfo) GetStateOfRegisterA

func (c *CPUInfo) GetStateOfRegisterA() []int

func (*CPUInfo) GetStateOfRegisterB

func (c *CPUInfo) GetStateOfRegisterB() []int

func (*CPUInfo) GetStateOfRegisterC

func (c *CPUInfo) GetStateOfRegisterC() []int

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL