My CPU
Ce petit CPU utilise 3 registres (R1, R2, R3) de 4 bits et un PC de 4 bits.
Une instruction est un quadruplet (OP,RA,RB,VALC) de taille fixe
égale à 16 bits, tel que :
- OP est le code de l'instruction à exécuter, codé sur 4 bits.
- RA et RB sont des numéros de registre codés sur 4 bits (2 bits utiles).
- VALC est la valeur d'une constante optionnelle, codé sur 4 bits.
Les instructions disponibles, inspirées du y86, sont les suivantes :
- OP 0 : NOP
- OP 1 : ADD RA,RB
- OP 2 : SUB RA,RB
- OP 3 : AND RA,RB
- OP 4 : XOR RA,RB
- OP 5 : IRMOV VALC,RB
- OP 6 : RRMOV RA,RB
- OP 7 : JMP VALC
- OP F : HALT
L'horloge est contrôlée manuellement par le bouton CLK
(Clock) qui incrémente le PC, instruction par instruction, et fait
exécuter l'instruction courante par le CPU qui met à jour les
registres.
La ROM (de taille max 16 instructions) contient actuellement un
programme élémentaire de 4 instructions, qui effectue l'addition
de deux registres :
- NOP
- IRMOV 0x6,R1
- IRMOV 0x4,R2
- RRMOV R2,R3
- ADD R1,R3
- JMP 0x1
- HALT
Avant de commencer le programme, il faut activer RST (Reset), et
effecturer une pression de CLK pour effectuer la remise à zéro du PC et des registres. On
décoche ensuite RST et on peut exécuter les instructions une par
une avec CLK. Have fun !
{
"width":800,
"height":600,
"showToolbox":false,
"devices":[
{"type":"4bit7segBus","id":"dev0","x":688,"y":256,"label":"R2"},
{"type":"4bit7segBus","id":"dev1","x":688,"y":344,"label":"R3"},
{"type":"DC","id":"dev2","x":24,"y":104,"label":"DC"},
{"type":"DC","id":"dev3","x":24,"y":168,"label":"DC"},
{"type":"CPU","id":"dev4","x":544,"y":232,"label":"CPU"},
{"type":"4bit7segBus","id":"dev5","x":688,"y":168,"label":"R1"},
{"type":"PushOn","id":"dev6","x":72,"y":168,"label":"CLK"},
{"type":"ROM","id":"dev7","x":296,"y":248,"label":"ROM"},
{"type":"Toggle","id":"dev8","x":72,"y":104,"label":"RST"},
{"type":"4bit7segBus","id":"dev9","x":280,"y":384,"label":"OP"},
{"type":"4bit7segBus","id":"dev10","x":368,"y":384,"label":"RA"},
{"type":"4bit7segBus","id":"dev11","x":456,"y":384,"label":"RB"},
{"type":"4bit7segBus","id":"dev12","x":536,"y":384,"label":"VALC"},
{"type":"pinleft","id":"dev13","x":464,"y":248,"label":""},
{"type":"pinleft","id":"dev14","x":448,"y":176,"label":""},
{"type":"4bit7segBus","id":"dev15","x":192,"y":384,"label":"PC"},
{"type":"4>4","id":"dev16","x":592,"y":152,"label":""},
{"type":"4<4","id":"dev17","x":176,"y":272,"label":""},
{"type":"4>4","id":"dev18","x":176,"y":152,"label":""},
{"type":"pinleft","id":"dev19","x":496,"y":232,"label":""},
{"type":"pinleft","id":"dev20","x":480,"y":112,"label":""}
],
"connectors":[
{"from":"dev0.in0","to":"dev4.out1"},
{"from":"dev1.in0","to":"dev4.out2"},
{"from":"dev4.in0","to":"dev19.out0"},
{"from":"dev4.in1","to":"dev13.out0"},
{"from":"dev4.in2","to":"dev7.out1"},
{"from":"dev4.in3","to":"dev7.out2"},
{"from":"dev4.in4","to":"dev7.out3"},
{"from":"dev4.in5","to":"dev7.out0"},
{"from":"dev5.in0","to":"dev4.out0"},
{"from":"dev6.in0","to":"dev3.out0"},
{"from":"dev7.in0","to":"dev17.out0"},
{"from":"dev8.in0","to":"dev2.out0"},
{"from":"dev9.in0","to":"dev7.out0"},
{"from":"dev10.in0","to":"dev7.out1"},
{"from":"dev11.in0","to":"dev7.out2"},
{"from":"dev12.in0","to":"dev7.out3"},
{"from":"dev13.in0","to":"dev14.out0"},
{"from":"dev14.in0","to":"dev6.out0"},
{"from":"dev15.in0","to":"dev17.out0"},
{"from":"dev16.in0","to":"dev4.out3"},
{"from":"dev17.in0","to":"dev18.out0"},
{"from":"dev18.in0","to":"dev16.out0"},
{"from":"dev19.in0","to":"dev20.out0"},
{"from":"dev20.in0","to":"dev8.out0"}
]
}
Save