Scrap Mechanic

Scrap Mechanic

Not enough ratings
TimCPU original
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
1.161 MB
9 Dec, 2021 @ 9:36pm
20 Dec, 2021 @ 3:40am
4 Change Notes ( view )

Subscribe to download
TimCPU original

In 1 collection by smailovtimofey
TimCPU and other machines
23 items
Description
Programmable CPU
https://github.com/timofey260/ScrapCPU CPU compiller

Buttons
pwr - power. if power off, code not be read
rst - go counter to 0
hrst - go counter to 0 and reset all registers(pwr need to be off)
next - increase counter by 1 (can press every 2 seconds max)
prev - decrease counter by 1 (can press every 2 seconds max)

err - error sign. lighrs if you try to add register to itself

code understanding

programm accept 4 bytes: OPCODE, ARG1, ARG2, RESULT

last two bytes in OPCODE control ARG1 and ARG2
00 - Both bytes be register values
01 - ARG1 be a register value, ARG2 be a value
10 - ARG2 be a register value, ARG1 be a value
11 - Both bytes be a values

register order:
000 - reg0
001 - reg1
010 - reg2
011 - reg3
100 - reg4
101 - reg5
110 - counter
111 - input/output

Math

first three bytes in OPCODE is math operation choice

000 - add
001 - sub
010 - and
011 - or
100 - not(get only ARG1)
101 - xor
110 - Shift left(if ARG2 = 1 then Shift right)

EXAMPLE:11000000 00000011 00000001 00000001 - add 3 + 1 and return to reg1
EXAMPLE:01000001 00000000 00000011 00000011 - sub reg0 + 3 and return to reg3
EXAMPLE:00000010 00000000 00000001 00000010 - reg0 and reg1 and return to reg2


logic

if 6th bit(32) in OPCODE is on, computer do condition

fitst three bytes is condition:
000 - ==
001 - !=
010 - <
011 - <=
100 - >
101 - >=

if condition is true, counter is set by result

EXAMPLE:11100000 00000011 00000001 00000001 - if 3 == 1 then jump to 0 code line
EXAMPLE:01100001 00000000 00000011 00000011 - if reg0 != 3 then jump to third code line
EXAMPLE:00100010 00000000 00000001 00000010 - if reg0 < reg1 then jump to second code line