Created
September 14, 2016 03:44
-
-
Save tranch/9dcad56ec41065e525071f96c4ce083c to your computer and use it in GitHub Desktop.
Human Resource Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def inbox | |
| @register = @inbox.shift | |
| end | |
| def outbox | |
| @outbox.push @register | |
| end | |
| def add(addr) | |
| @register = @register + @ram[addr] | |
| end | |
| def sub(addr) | |
| @register = @register - @ram[addr] | |
| end | |
| def copyto(addr) | |
| @ram[addr] = @register | |
| end | |
| def copyfrom(addr) | |
| @register = @ram[addr] | |
| end | |
| def neg() | |
| @register < 0 | |
| end | |
| @inbox = Array.new(8) { rand -99...99 } | |
| @outbox = Array.new(0) | |
| @ram = Array.new(6) | |
| @register = nil | |
| printf "Inbox: %s\n", @inbox.join(', ') | |
| while not @inbox.empty? | |
| inbox | |
| outbox | |
| end | |
| printf "Outbox: %s\n", @outbox.join(', ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment