0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

俺cpuAdvent Calendar 2020

Day 7

windowsでiverilog その44

Last updated at Posted at 2020-07-07

#概要

windowsでiverilogやってみた。
polyphonyでcpu書いてみる。

#俺cpu仕様案

命令長 16ビット
レジスタ 8ビット4本
命令メモリー 8ビット256バイト
データメモリー 8ビット256バイト
命令セット
bit15,bit14 算術命令、転送命令、ジャンプ、アドレスを分ける。
bit13,bit12 上の細分
bit11,bit10 レジスタ指定
bit9,bit8 レジスタ指定
bit7~bit0 アドレス、データ

#俺cpu命令セット案

|ニーモニック|bit15,bit14 |bit13,bit12|bit11,bit10|bit9,bit8|bit7,bit0|説明|
|:--|:--|:--|:--|:--|:--|:--|:--|
|+ |0 |0 |0-3 |0-3 |- |加算|
|- |0 |1 |0-3 |0-3 |- |減算|
|* |0 |2 |0-3 |0-3 |- |乗算|
|/ |0 |3 |0-3 |0-3 |- |除算|
|jmp |1 |0 |- |- |0-255 |ジャンプ|
|if jmp |1 |1 |- |- |0-255 |条件ジャンプ|
|> |1 |2 |0-3 |0-3 |- |条件|
|% |1 |3 |0-3 |0-3 |- |剰余|
|set |2 |0 |0-3 |- |0-255 |レジスタセット|
|set2 |2 |1 |0-3 |0-3 |0-255 |レジスタセット|
|out |2 |2 |0-3 |- |- |出力|
|out2 |2 |3 |- |- |0-255 |出力|
|load |3 |0 |0-3 |- |0-255 |メモリロード|
|save |3 |1 |0-3 |- |0-255 |メモリセーブ|
|load2 |3 |2 |0-3 |0-3 |0-255 |メモリロード|
|save2 |3 |3 |0-3 |0-3 |0-255 |メモリセーブ|

#サンプルコード

				while pc != 0:
					iaddr = pc
					ins = imem[iaddr]
					pc = pc + 1
					op = (ins >> 14) & 0x3
					funct = (ins >> 12) & 0x3
					a = (ins >> 10) & 0x3
					b = (ins >> 8) & 0x3
					data = ins & 0xff
					addr = ins & 0xff
					if op == 0:#keisan
						if funct == 0:
							reg[a] = reg[a] + reg[b]
						elif funct == 1:
							reg[a] = reg[a] - reg[b]
						elif funct == 2:
							reg[a] = reg[a] * reg[b]
						elif funct == 3:
							reg[a] = reg[a] / reg[b]
						else:
							pc = 0
					elif op == 2:#jump
						if funct == 0:
							pc = addr
						elif funct == 1:
							if (reg[a] == 0):
								pc = addr
						elif funct == 2:
							reg[a] = reg[a] < reg[b]
						elif funct == 3:
							reg[a] = reg[a] % reg[b]
						else:
							pc = 0
					elif op == 3:#data
						if funct == 0:
							reg[a] = data
						elif funct == 1:
							reg[a] = reg[b] + data
						#elif funct == 2:
							#reg[a] = reg[b] + 1
						#elif funct == 3:
							#reg[a] = reg[a] < reg[b]
						else:
							pc = 0
					else:#mem
						if funct == 0:
							reg[a] = dmem[addr]
						elif funct == 1:
							dmem[addr] = reg[a]
						elif funct == 2:
							reg[a] = dmem[reg[b] + addr]
						elif funct == 3:
							dmem[reg[b] + addr] = reg[a]
						else:
							pc = 0

#アセンブラ案

a-zをout


  r0set  0
  r0save  0
loop:
  r0load  0
  r1set  26
  r0  <  r1
  if  pass 
  r0load  0
  r1set  97
  r0  +  r1
  r0out 
  r0load  0
  r1set  1
  r0  +  r1
  r0save  0
  jp  loop
pass:

#メモリーに落とす。


imem = [

0x8000,  #r0set  0
0xd000,  #r0save  0
       #loop:
0xc000,  #r0load  0
0x841a,  #r1set  26
0x6100,  #r0  <  r1
0x400f,  #if  pass 
0xc000,  #r0load  0
0x8461,  #r1set  97
0x0100,  #r0  +  r1
0xa000,  #r0out 
0xc000,  #r0load  0
0x8401,  #r1set  1
0x0100,  #r0  +  r1
0xd000,  #r0save  0
0x5002,  #jp  loop
0x500f, #pass:
]


以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?