ucisc 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/core/stdlib.ucisc +101 -0
- data/examples/everest_12bit.ucisc +195 -0
- data/examples/factorial.ucisc +24 -22
- data/examples/fib.ucisc +40 -35
- data/examples/hello_world.ucisc +59 -68
- data/examples/paint_image.ucisc +261 -0
- data/exe/png_to_hex +38 -0
- data/exe/ucisc +8 -5
- data/lib/micro_cisc.rb +30 -7
- data/lib/micro_cisc/compile/compiler.rb +10 -2
- data/lib/micro_cisc/compile/instruction.rb +40 -13
- data/lib/micro_cisc/compile/statement.rb +118 -34
- data/lib/micro_cisc/version.rb +1 -1
- data/lib/micro_cisc/vm/color_lcd_display.rb +115 -0
- data/lib/micro_cisc/vm/device.rb +32 -21
- data/lib/micro_cisc/vm/processor.rb +20 -9
- data/lib/micro_cisc/vm/term_device.rb +4 -8
- data/ucisc.gemspec +2 -0
- data/ucisc.vim +14 -8
- metadata +36 -4
- data/examples/image.ucisc +0 -543
- data/lib/micro_cisc/vm/video.rb +0 -151
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3e72e998af8419f04b938e16106485af9a6d9eecd4eca52c4c9ed47ac6a0df4
|
4
|
+
data.tar.gz: 4201a507834a84d5fc67b2f53a04d404b017ecf6a24f9459bf47ba75d6f85eeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaab2729f733ffa9256500fc358bef442a4c21124774ad39f74d5b88272721f27db95daceb72465244b71a336e3869f96d3e064fc3b23e102fd184231eaaa80c
|
7
|
+
data.tar.gz: 0b527c73e2f4ceaecf5614d07cc49e47daa269340703cda088cc2e62b2b4846cdac8daa3b269a68379851cf437a06bf01084b1f95fc166ab4ae25c9b5955a46c
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ucisc (0.1.
|
4
|
+
ucisc (0.1.4)
|
5
|
+
bundler
|
5
6
|
byebug
|
7
|
+
chunky_png
|
6
8
|
gtk2
|
7
9
|
tty-screen
|
8
10
|
|
@@ -18,6 +20,7 @@ GEM
|
|
18
20
|
cairo-gobject (3.4.3)
|
19
21
|
cairo (>= 1.16.2)
|
20
22
|
glib2 (= 3.4.3)
|
23
|
+
chunky_png (1.3.11)
|
21
24
|
gdk_pixbuf2 (3.4.3)
|
22
25
|
gio2 (= 3.4.3)
|
23
26
|
gio2 (3.4.3)
|
data/core/stdlib.ucisc
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
##########################
|
2
|
+
# Standard uCISC Library #
|
3
|
+
##########################
|
4
|
+
# Contains the following functions:
|
5
|
+
#
|
6
|
+
# * $&device_control <= init_device($device_index)
|
7
|
+
# * mem_copy(&source, &target, $len)
|
8
|
+
#
|
9
|
+
|
10
|
+
################
|
11
|
+
# Syntax Setup #
|
12
|
+
################
|
13
|
+
&stack as 1.reg
|
14
|
+
&pc as 0.reg
|
15
|
+
&banking as 4.reg
|
16
|
+
|
17
|
+
# Conditionals
|
18
|
+
$zero? as 0.eff
|
19
|
+
$not_zero? as 1.eff
|
20
|
+
$negative? as 2.eff
|
21
|
+
|
22
|
+
# Compute Ops
|
23
|
+
$invert as 0x0.op
|
24
|
+
$and as 0x1.op
|
25
|
+
$or as 0x2.op
|
26
|
+
$xor as 0x3.op
|
27
|
+
$increment as 0x4.op
|
28
|
+
$shift_left as 0x5.op
|
29
|
+
$shift_right as 0x6.op
|
30
|
+
$swap_bytes as 0x7.op
|
31
|
+
$high_byte as 0x8.op # zero least significant byte
|
32
|
+
$low_byte as 0x9.op # zero most significant byte
|
33
|
+
$add as 0xA.op
|
34
|
+
$subtract as 0xB.op
|
35
|
+
$multiply as 0xC.op
|
36
|
+
$divide as 0xD.op
|
37
|
+
$add_overflow as 0xE.op
|
38
|
+
$mask_to_overflow as 0xF.op
|
39
|
+
|
40
|
+
################
|
41
|
+
# Main Section #
|
42
|
+
################
|
43
|
+
&stack as copy 0.imm 1.reg
|
44
|
+
|
45
|
+
$stack <= Entry()
|
46
|
+
|
47
|
+
Entry:
|
48
|
+
copy &pc &pc
|
49
|
+
|
50
|
+
# $stack[$&device_control] <= init_device($device_index)
|
51
|
+
#
|
52
|
+
# Takes a device index and caclulates the control word for that device. It
|
53
|
+
# sets the init_device of the targeted device to the current processor, giving
|
54
|
+
# subsequent code the ability to interact with the banked memory and controls.
|
55
|
+
init_device: # $&device_control <= ($device_index)
|
56
|
+
$device_index, $&return, $&device_control = $stack
|
57
|
+
|
58
|
+
&shift_amount as copy 4.imm 2.reg
|
59
|
+
$&control = compute $shift_left &shift_amount $device_index
|
60
|
+
copy $&control $&device_control
|
61
|
+
|
62
|
+
&device_control = copy $&control 2.reg
|
63
|
+
$device_control.init as $device_control 2.imm
|
64
|
+
&self = copy 2.imm 3.reg
|
65
|
+
|
66
|
+
copy 1.imm &banking
|
67
|
+
copy $self $device_control.init
|
68
|
+
copy 0.imm &banking
|
69
|
+
|
70
|
+
copy &&return &stack
|
71
|
+
copy $&return &pc pop
|
72
|
+
|
73
|
+
# $stack <= mem_copy(&source, &target, $len)
|
74
|
+
#
|
75
|
+
# Copies $len words from $source to $target. Note, no changes to banking are
|
76
|
+
# made, so it will respect any banking setup prior to calling the function.
|
77
|
+
mem_copy:
|
78
|
+
$len, $&target, $&source, $&return = $stack
|
79
|
+
|
80
|
+
&source as copy $&source 2.reg
|
81
|
+
&target as copy $&target 3.reg
|
82
|
+
|
83
|
+
compute $add 0.imm $len # sets the flags
|
84
|
+
# Loop over string, copy to $term
|
85
|
+
{
|
86
|
+
copy &pc break.disp &pc $zero?
|
87
|
+
|
88
|
+
{
|
89
|
+
copy $source $target
|
90
|
+
compute $add 1.imm &source
|
91
|
+
compute $add 1.imm &target
|
92
|
+
|
93
|
+
compute 0xB.op/subtract/ 1.imm $len
|
94
|
+
|
95
|
+
copy &pc loop.disp &pc $not_zero?
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
copy &&return &stack
|
100
|
+
copy $&return &pc pop
|
101
|
+
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# 64x48 pixel image
|
2
|
+
image.data:
|
3
|
+
|
4
|
+
% 0024 0024 0024 0024 0024 0024 0024 0024 0024 0024 0024 0024 0024 0024 0024 0024
|
5
|
+
% 0025 0025 0024 0024 0024 0024 0024 0024 0025 0025 0025 0025 0025 0025 0025 0025
|
6
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
7
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
8
|
+
% 0024 0024 0024 0024 0024 0024 0024 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
9
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
10
|
+
% 0025 0025 0025 0025 0025 0026 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
11
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
12
|
+
% 0024 0024 0024 0024 0024 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
13
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0026 0026
|
14
|
+
% 0026 0026 0026 0026 0026 0026 0026 0026 0026 0026 0026 0026 0026 0025 0025 0025
|
15
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
16
|
+
% 0024 0024 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
17
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0026 0026 0026 0026
|
18
|
+
% 0026 0026 0036 0036 0036 0036 0036 0026 0026 0026 0026 0026 0026 0026 0026 0026
|
19
|
+
% 0026 0026 0026 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
20
|
+
% 0024 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
21
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0026 0026 0036 0036 0036 0036 0036
|
22
|
+
% 0036 0036 0036 0036 0036 0036 0036 0036 0036 0036 0036 0036 0036 0036 0036 0036
|
23
|
+
% 0036 0036 0026 0026 0026 0026 0036 0036 0026 0025 0025 0025 0025 0025 0025 0025
|
24
|
+
% 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025 0025
|
25
|
+
% 0025 0025 0025 0025 0135 0035 0135 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
26
|
+
% 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
27
|
+
% 0036 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0036 0035 0035 0025 0025
|
28
|
+
% 0125 0125 0125 0125 0125 0125 0125 0125 0135 0135 0135 0135 0135 0135 0135 0135
|
29
|
+
% 0135 0135 0135 0135 0135 0135 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
30
|
+
% 0136 0137 0137 0136 0137 0137 0137 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
31
|
+
% 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0135 0136 0135 0135
|
32
|
+
% 0135 0125 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135
|
33
|
+
% 0135 0135 0135 0135 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
34
|
+
% 0137 0137 0137 0137 0137 0137 0137 0137 0137 0137 0137 0136 0136 0136 0136 0136
|
35
|
+
% 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
36
|
+
% 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135
|
37
|
+
% 0135 0135 0135 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0147 0147 0147
|
38
|
+
% 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0136
|
39
|
+
% 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
40
|
+
% 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135
|
41
|
+
% 0135 0136 0136 0136 0136 0136 0136 0146 0146 0146 0146 0147 0147 0147 0147 0147
|
42
|
+
% 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147
|
43
|
+
% 0146 0146 0146 0146 0146 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136 0136
|
44
|
+
% 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0136 0136
|
45
|
+
% 0136 0136 0146 0146 0146 0146 0146 0146 0146 0146 0146 0147 0147 0147 0147 0147
|
46
|
+
% 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147 0147
|
47
|
+
% 0147 0146 0146 0146 0146 0146 0146 0146 0146 0136 0136 0136 0136 0136 0136 0135
|
48
|
+
% 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0245 0245 0245 0245 0245 0145
|
49
|
+
% 0245 0245 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246 0247 0247 0247 0247
|
50
|
+
% 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247
|
51
|
+
% 0247 0247 0246 0246 0246 0246 0246 0246 0246 0246 0146 0146 0135 0135 0135 0135
|
52
|
+
% 0235 0235 0235 0235 0235 0245 0245 0245 0345 0245 0245 0245 0245 0245 0245 0245
|
53
|
+
% 0245 0245 0245 0245 0246 0246 0246 0246 0246 0246 0246 0246 0357 0357 0247 0247
|
54
|
+
% 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0246
|
55
|
+
% 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246 0245 0235 0235 0135
|
56
|
+
% 0235 0235 0235 0235 0235 0235 0345 0345 0345 0345 0345 0245 0245 0345 0345 0345
|
57
|
+
% 0245 0245 0245 0245 0245 0245 0245 0245 0246 0246 0245 0124 0566 0BBB 0789 0457
|
58
|
+
% 0357 0247 0247 0247 0247 0247 0247 0247 0247 0247 0247 0246 0246 0246 0246 0246
|
59
|
+
% 0246 0346 0246 0246 0246 0246 0246 0246 0246 0245 0235 0235 0235 0235 0235 0235
|
60
|
+
% 0134 0134 0234 0234 0234 0234 0234 0234 0234 0235 0235 0235 0235 0235 0235 0235
|
61
|
+
% 0235 0235 0235 0235 0235 0235 0235 0235 0235 0134 0113 0012 0556 0AA9 0AAA 0899
|
62
|
+
% 0677 0678 0357 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246 0246
|
63
|
+
% 0246 0246 0246 0246 0246 0246 0235 0235 0235 0235 0235 0235 0235 0235 0235 0134
|
64
|
+
% 0134 0134 0134 0134 0134 0134 0134 0134 0134 0134 0134 0134 0135 0135 0135 0135
|
65
|
+
% 0135 0135 0135 0135 0135 0135 0135 0135 0124 0012 0012 0113 0123 0666 0777 0344
|
66
|
+
% 0123 0445 0AAA 0678 0247 0146 0146 0146 0246 0146 0146 0146 0136 0136 0136 0136
|
67
|
+
% 0136 0136 0136 0236 0136 0136 0235 0135 0135 0135 0135 0135 0135 0135 0134 0134
|
68
|
+
% 0124 0124 0124 0124 0124 0124 0124 0124 0124 0124 0124 0134 0134 0134 0134 0135
|
69
|
+
% 0135 0135 0135 0135 0135 0135 0135 0123 0012 0334 0445 0123 0123 0556 0777 0334
|
70
|
+
% 0012 0012 0455 0888 0999 0779 0247 0146 0136 0136 0136 0136 0136 0136 0135 0135
|
71
|
+
% 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0135 0124 0124 0124 0124
|
72
|
+
% 0124 0124 0124 0124 0124 0124 0124 0124 0134 0123 0123 0123 0123 0123 0234 0234
|
73
|
+
% 0235 0235 0134 0124 0235 0234 0123 0113 0112 0555 0777 0123 0223 0334 0445 0123
|
74
|
+
% 0113 0012 0123 0334 0888 0CCB 0AAA 0789 0457 0246 0136 0136 0136 0135 0135 0135
|
75
|
+
% 0135 0135 0135 0246 0135 0135 0135 0135 0135 0235 0135 0124 0124 0124 0124 0124
|
76
|
+
% 0124 0124 0124 0124 0124 0124 0124 0123 0112 0112 0112 0012 0012 0112 0223 0112
|
77
|
+
% 0666 0666 0233 0112 0223 0455 0233 0445 0233 0344 0666 0123 0112 0334 0223 0344
|
78
|
+
% 0556 0123 0012 0012 0556 0CCB 0DCB 0BBB 0999 0778 0667 0889 0667 0457 0356 0246
|
79
|
+
% 0456 0346 0556 0AA9 0778 0456 0346 0456 0245 0455 0234 0235 0235 0124 0124 0124
|
80
|
+
% 0554 0234 0223 0223 0123 0123 0123 0012 0112 0112 0123 0012 0012 0223 0112 0012
|
81
|
+
% 0666 0998 0666 0223 0223 0223 0234 0666 0455 0666 0777 0666 0223 0344 0223 0344
|
82
|
+
% 0777 0556 0123 0012 0666 0CBB 0DCB 0BBA 0A99 0988 0888 0BAA 0BBA 0999 0777 0456
|
83
|
+
% 0345 0234 0888 0CBA 0CBA 0BBA 0777 0666 0556 0556 0556 0555 0566 0234 0234 0134
|
84
|
+
% 0544 0444 0554 0444 0333 0334 0112 0011 0012 0112 0113 0012 0334 0223 0012 0112
|
85
|
+
% 0887 0DCA 0BB9 0776 0334 0112 0123 0334 0445 0334 0777 0888 0455 0334 0445 0566
|
86
|
+
% 0566 0334 0113 0123 0455 0AA9 0DCB 0CCB 0A99 0999 0999 0999 0AA9 0778 0345 0445
|
87
|
+
% 0234 0345 0BBA 0CBB 0A99 0BAA 0AA9 0777 0556 0666 0666 0777 0776 0555 0445 0344
|
88
|
+
% 0444 0223 0333 0444 0233 0122 0012 0011 0012 0112 0123 0223 0666 0233 0012 0113
|
89
|
+
% 0555 0BA9 0DCA 0BA9 0777 0334 0334 0344 0556 0445 0445 0777 0455 0345 0556 0556
|
90
|
+
% 0556 0224 0124 0556 0234 0455 0BAA 0DCB 0BAA 0999 0BAA 0AA9 0888 0667 0456 0345
|
91
|
+
% 0235 0777 0CCB 0DCB 0AA9 0988 0AA9 0CBA 0777 0556 0555 0445 0555 0666 0555 0444
|
92
|
+
% 0775 0444 0444 0555 0122 0012 0012 0012 0012 0012 0334 0344 0666 0233 0123 0555
|
93
|
+
% 0233 0777 0BA9 0BA9 0998 0777 0666 0556 0666 0887 0445 0666 0555 0455 0666 0556
|
94
|
+
% 0234 0123 0556 0877 0556 0334 0677 0BBA 0CBA 0A99 0AA9 0888 0556 0345 0556 0556
|
95
|
+
% 0345 0BBA 0DCB 0CCB 0AA9 0A99 0888 0AA9 0BA9 0777 0445 0344 0344 0666 0776 0776
|
96
|
+
% 0654 0333 0223 0334 0012 0011 0012 0012 0123 0334 0444 0123 0344 0123 0223 0666
|
97
|
+
% 0334 0445 0988 0998 0987 0887 0988 0566 0556 0998 0666 0666 0345 0234 0556 0234
|
98
|
+
% 0123 0345 0888 0888 0777 0455 0556 0AA9 0BAA 0988 0999 0334 0112 0113 0223 0788
|
99
|
+
% 0778 0A99 0CBA 0CBA 0AA9 0A99 0877 0877 0BB9 0A98 0887 0455 0234 0344 0555 0887
|
100
|
+
% 0554 0333 0222 0122 0012 0012 0012 0112 0444 0555 0444 0223 0223 0112 0123 0334
|
101
|
+
% 0123 0234 0776 0777 0987 0776 0877 0666 0345 0877 0666 0555 0234 0234 0234 0013
|
102
|
+
% 0234 0556 0999 0888 0888 0777 0566 0777 0AA9 0888 099A 0667 0556 0445 0345 0667
|
103
|
+
% 0AAA 0999 0998 0A99 0BBA 0888 0766 0556 0877 0987 0877 0777 0556 0555 0445 0666
|
104
|
+
% 0654 0433 0112 0112 0112 0112 0112 0333 0334 0444 0344 0233 0334 0223 0223 0123
|
105
|
+
% 0012 0234 0666 0666 0766 0666 0655 0766 0555 0776 0777 0666 0666 0666 0334 0234
|
106
|
+
% 0123 0555 0AA9 0888 0998 0887 0776 0334 0334 0334 0CCC 0DDD 0DCD 0DDD 0A9A 0999
|
107
|
+
% 0989 0888 0667 0778 0AA9 0A99 0877 0455 0445 0665 0445 0999 0BBB 0999 0998 0888
|
108
|
+
% 0333 0333 0444 0655 0666 0544 0223 0333 0544 0555 0444 0334 0344 0555 0444 0555
|
109
|
+
% 0334 0555 0555 0334 0555 0555 0766 0877 0555 0444 0665 0777 0666 0666 0888 0445
|
110
|
+
% 0123 0777 0BAA 0888 0BAA 0A99 0988 0444 0012 0334 0DCC 0EEE 0EED 0DDD 0CBB 0BBB
|
111
|
+
% 0A9A 0999 0888 0777 0888 0877 0888 0666 0555 0555 0444 0BBA 0CCB 0BAA 0AA9 0998
|
112
|
+
% 0333 0444 0665 0666 0666 0666 0555 0344 0555 0655 0665 0555 0555 0665 0655 0555
|
113
|
+
% 0655 0444 0333 0333 0665 0444 0776 0766 0334 0223 0444 0444 0223 0223 0877 0334
|
114
|
+
% 0223 0776 0888 0988 0887 0A98 0655 0112 0012 0223 0999 0EDD 0EDD 0DCC 0CCC 0CCC
|
115
|
+
% 0BBB 0AAA 0999 0666 0888 0666 0444 0444 0334 0223 0334 0BAA 0CCB 0BBA 0BBA 0AA9
|
116
|
+
% 0554 0333 0333 0333 0222 0223 0333 0444 0665 0655 0655 0334 0334 0333 0444 0554
|
117
|
+
% 0344 0222 0223 0222 0444 0333 0223 0222 0333 0555 0766 0555 0334 0334 0665 0233
|
118
|
+
% 0222 0344 0566 0987 0444 0334 0112 0012 0112 0112 0566 0CCB 0DDC 0CBB 0BBA 0CBB
|
119
|
+
% 0BBB 0BBB 0BAA 0666 0877 0877 0554 0112 0112 0233 0223 0555 0AA9 0BBA 0BAA 0A99
|
120
|
+
% 0987 0877 0444 0222 0222 0222 0222 0334 0444 0333 0334 0444 0222 0112 0333 0333
|
121
|
+
% 0112 0112 0222 0112 0222 0112 0112 0333 0333 0444 0554 0555 0444 0554 0555 0223
|
122
|
+
% 0222 0333 0233 0444 0223 0012 0011 0012 0223 0112 0667 0888 0998 0BAA 0AAA 0999
|
123
|
+
% 0AAA 0AAA 0BAA 0666 0766 0AA9 0555 0112 0112 0444 0333 0112 0444 0988 0BA9 0AA9
|
124
|
+
% 0987 0987 0876 0444 0333 0222 0444 0554 0655 0444 0333 0333 0112 0112 0444 0333
|
125
|
+
% 0112 0111 0111 0111 0112 0111 0111 0222 0122 0112 0222 0222 0222 0222 0112 0111
|
126
|
+
% 0111 0112 0112 0011 0011 0011 0011 0011 0112 0011 0445 0988 0777 0777 0988 0877
|
127
|
+
% 0777 0AA9 0A99 0777 0444 0988 0666 0122 0122 0444 0223 0111 0112 0444 0666 0988
|
128
|
+
% 0766 0876 0765 0544 0222 0222 0444 0222 0222 0212 0111 0111 0111 0222 0222 0222
|
129
|
+
% 0111 0111 0111 0111 0111 0111 0111 0111 0112 0222 0222 0222 0111 0111 0223 0222
|
130
|
+
% 0011 0011 0011 0011 0001 0011 0011 0011 0011 0112 0334 0A99 0999 0888 0777 0777
|
131
|
+
% 0555 0666 0776 0766 0444 0444 0444 0112 0122 0112 0112 0112 0112 0333 0333 0665
|
132
|
+
% 0665 0554 0655 0665 0443 0111 0222 0111 0111 0111 0011 0011 0011 0111 0111 0111
|
133
|
+
% 0111 0111 0111 0111 0222 0222 0222 0222 0111 0111 0111 0111 0111 0222 0666 0223
|
134
|
+
% 0001 0011 0001 0001 0111 0112 0223 0223 0223 0444 0777 0BAA 0AA9 0888 0777 0877
|
135
|
+
% 0877 0666 0444 0444 0444 0333 0222 0112 0111 0011 0111 0111 0112 0444 0333 0222
|
136
|
+
% 0443 0443 0443 0654 0444 0333 0111 0111 0111 0011 0111 0111 0111 0111 0111 0011
|
137
|
+
% 0111 0011 0111 0111 0222 0222 0111 0111 0001 0111 0111 0111 0111 0122 0222 0222
|
138
|
+
% 0001 0111 0222 0333 0444 0665 0555 0445 0223 0554 0655 0766 0776 0666 0655 0444
|
139
|
+
% 0655 0666 0776 0776 0544 0333 0222 0112 0111 0111 0111 0111 0222 0655 0665 0222
|
140
|
+
% 0111 0221 0222 0554 0765 0776 0544 0111 0111 0001 0111 0111 0111 0111 0111 0111
|
141
|
+
% 0111 0111 0111 0111 0111 0111 0011 0111 0111 0011 0001 0111 0111 0111 0111 0222
|
142
|
+
% 0112 0433 0544 0665 0555 0877 0877 0766 0333 0334 0333 0333 0444 0444 0555 0544
|
143
|
+
% 0233 0334 0433 0443 0665 0554 0233 0111 0011 0111 0222 0112 0333 0554 0877 0555
|
144
|
+
% 0222 0000 0111 0333 0544 0765 0654 0111 0011 0000 0001 0011 0111 0111 0001 0111
|
145
|
+
% 0111 0111 0111 0111 0111 0111 0111 0111 0001 0000 0000 0001 0111 0111 0111 0111
|
146
|
+
% 0122 0322 0333 0444 0333 0444 0555 0555 0444 0444 0333 0222 0222 0222 0222 0333
|
147
|
+
% 0333 0444 0333 0112 0554 0987 0776 0111 0000 0111 0222 0222 0332 0554 0665 0876
|
148
|
+
% 0654 0111 0011 0122 0222 0222 0211 0111 0111 0111 0011 0001 0001 0001 0001 0111
|
149
|
+
% 0111 0111 0111 0111 0111 0111 0111 0010 0000 0000 0000 0000 0111 0222 0544 0333
|
150
|
+
% 0111 0111 0111 0111 0222 0222 0222 0444 0555 0333 0222 0112 0222 0222 0111 0111
|
151
|
+
% 0222 0333 0122 0444 0555 0766 0877 0333 0001 0222 0443 0433 0221 0333 0443 0554
|
152
|
+
% 0332 0111 0011 0222 0222 0222 0111 0111 0111 0112 0112 0111 0111 0011 0001 0000
|
153
|
+
% 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0111 0122 0222 0666
|
154
|
+
% 0433 0444 0444 0333 0222 0111 0332 0877 0A98 0776 0544 0222 0111 0111 0001 0111
|
155
|
+
% 0233 0333 0222 0544 0766 0554 0655 0555 0122 0333 0554 0554 0433 0222 0332 0332
|
156
|
+
% 0111 0011 0000 0111 0112 0122 0111 0111 0111 0112 0222 0111 0011 0001 0000 0000
|
157
|
+
% 0000 0000 0000 0000 0000 0000 0000 0011 0111 0111 0111 0111 0222 0333 0222 0333
|
158
|
+
% 0444 0555 0666 0444 0444 0554 0776 0887 0887 0776 0665 0333 0011 0111 0011 0111
|
159
|
+
% 0333 0444 0222 0222 0666 0665 0655 0445 0444 0334 0443 0433 0433 0222 0222 0111
|
160
|
+
% 0333 0333 0222 0111 0111 0111 0111 0111 0112 0222 0222 0111 0000 0000 0000 0000
|
161
|
+
% 0000 0000 0000 0000 0000 0000 0000 0111 0222 0222 0112 0122 0233 0333 0333 0333
|
162
|
+
% 0444 0555 0555 0222 0333 0776 0887 0877 0555 0344 0345 0344 0333 0233 0234 0222
|
163
|
+
% 0222 0333 0333 0111 0334 0555 0656 0555 0555 0555 0333 0333 0555 0555 0444 0222
|
164
|
+
% 0233 0444 0343 0222 0222 0122 0111 0011 0011 0111 0111 0111 0000 0000 0000 0000
|
165
|
+
% 0000 0000 0000 0000 0000 0000 0000 0011 0111 0111 0111 0111 0111 0333 0443 0222
|
166
|
+
% 0222 0222 0111 0111 0111 0332 0554 0655 0334 0334 0666 0667 0667 0556 0445 0334
|
167
|
+
% 0333 0222 0111 0122 0344 0445 0445 0555 0444 0233 0223 0233 0444 0666 0766 0444
|
168
|
+
% 0333 0555 0555 0555 0444 0444 0444 0222 0111 0011 0000 0000 0000 0000 0000 0000
|
169
|
+
% 0000 0000 0000 0000 0000 0011 0111 0111 0011 0000 0000 0000 0010 0111 0111 0111
|
170
|
+
% 0001 0111 0000 0000 0000 0010 0111 0222 0223 0445 0667 0778 0778 0777 0556 0444
|
171
|
+
% 0344 0333 0122 0122 0223 0334 0444 0656 0555 0444 0223 0222 0333 0544 0555 0444
|
172
|
+
% 0444 0555 0665 0777 0666 0555 0554 0344 0333 0233 0111 0000 0000 0000 0000 0000
|
173
|
+
% 0000 0000 0000 0000 0000 0000 0000 0011 0000 0000 0000 0000 0000 0000 0000 0011
|
174
|
+
% 0111 0011 0000 0000 0000 0000 0111 0123 0344 0556 0667 0777 0667 0666 0555 0444
|
175
|
+
% 0344 0334 0333 0223 0122 0222 0333 0545 0555 0554 0333 0222 0223 0333 0333 0333
|
176
|
+
% 0554 0554 0666 0777 0776 0665 0555 0554 0444 0444 0222 0111 0000 0000 0011 0011
|
177
|
+
% 0011 0011 0011 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
|
178
|
+
% 0000 0000 0000 0000 0000 0011 0112 0234 0556 0778 0888 0778 0666 0555 0344 0334
|
179
|
+
% 0334 0344 0344 0333 0222 0112 0222 0333 0444 0433 0223 0222 0222 0222 0222 0111
|
180
|
+
% 0443 0444 0554 0555 0555 0554 0444 0444 0443 0343 0222 0112 0011 0011 0111 0011
|
181
|
+
% 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
|
182
|
+
% 0000 0000 0000 0000 0112 0234 0234 0334 0556 0667 0778 0778 0667 0666 0445 0444
|
183
|
+
% 0445 0334 0233 0223 0222 0112 0112 0222 0222 0322 0222 0111 0211 0111 0111 0000
|
184
|
+
% 0232 0332 0333 0333 0333 0333 0333 0333 0232 0222 0111 0111 0000 0000 0000 0000
|
185
|
+
% 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
|
186
|
+
% 0111 0111 0122 0223 0334 0455 0566 0666 0666 0556 0556 0566 0556 0455 0444 0344
|
187
|
+
% 0334 0333 0222 0122 0112 0111 0111 0111 0222 0222 0111 0111 0111 0222 0111 0111
|
188
|
+
% 0121 0222 0222 0332 0333 0332 0333 0443 0554 0443 0222 0010 0000 0000 0000 0000
|
189
|
+
% 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0011 0112
|
190
|
+
% 0334 0344 0455 0455 0455 0666 0666 0666 0666 0556 0445 0444 0344 0333 0333 0333
|
191
|
+
% 0223 0122 0111 0111 0111 0011 0000 0000 0111 0111 0222 0111 0111 0111 0111 0111
|
192
|
+
% 0221 0222 0222 0332 0333 0332 0443 0554 0654 0554 0332 0111 0000 0000 0000 0000
|
193
|
+
% 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0010 0000 0000 0111 0122 0223
|
194
|
+
% 0233 0444 0455 0455 0455 0556 0556 0555 0445 0444 0344 0333 0223 0222 0223 0233
|
195
|
+
% 0112 0111 0000 0000 0000 0000 0000 0000 0000 0111 0111 0111 0111 0001 0000 0000
|
data/examples/factorial.ucisc
CHANGED
@@ -2,57 +2,59 @@
|
|
2
2
|
# Inspired by the SubX example near the bottom of this post:
|
3
3
|
# http://akkartik.name/post/mu-2019-1
|
4
4
|
#
|
5
|
-
# The goal is to compare the implementation of the uCISC ISA to x86
|
6
|
-
# as well as roughly see how things line up with SubX and look for
|
7
|
-
# the coming MuCISC goals
|
8
|
-
#
|
9
5
|
# To run:
|
10
6
|
# $ exe/ucisc examples/factorial.ucisc
|
11
7
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# More instructions on the compiler and debugger are in the README.md
|
16
|
-
# Or use GitHub https://github.com/grokthis/ucisc-ruby#usage
|
8
|
+
# Stack result should be:
|
9
|
+
# INFO: Stack: FFFF => 0x0018
|
17
10
|
|
18
|
-
|
11
|
+
################
|
12
|
+
# Syntax Setup #
|
13
|
+
################
|
19
14
|
$stack as 1.mem
|
20
15
|
&pc as 0.reg
|
21
16
|
|
17
|
+
# ALU op codes
|
18
|
+
$subtract as 0xB.op
|
19
|
+
$multiply as 0xC.op
|
20
|
+
|
22
21
|
# Simple conditional syntax sugar
|
23
22
|
$zero? as 0.eff
|
24
23
|
|
25
|
-
|
24
|
+
################
|
25
|
+
# Code Entry #
|
26
|
+
################
|
26
27
|
copy 0.imm &stack
|
27
28
|
|
28
|
-
# Call factorial
|
29
|
-
# Calling convention is to push args to stack, in order then push return address
|
30
|
-
# On return, args and return address are removed, result is in it's place
|
31
29
|
$stack[1] <= factorial(4.imm)
|
32
30
|
|
33
31
|
# halt
|
34
32
|
copy &pc &pc
|
35
33
|
|
34
|
+
################
|
35
|
+
# Main Section #
|
36
|
+
################
|
36
37
|
factorial: # (n)
|
38
|
+
$n, $return, $result = $stack
|
37
39
|
# calculate n - 1, push to stack
|
38
|
-
compute
|
40
|
+
$n_1 = compute $subtract 1.imm $n push
|
39
41
|
{
|
40
42
|
# factorial(1) = 1, copy 1 to result
|
41
|
-
copy $
|
43
|
+
copy $n $result $zero?
|
42
44
|
copy &pc break.disp &pc $zero?
|
43
45
|
|
44
46
|
# compute factorial(n-1)
|
45
|
-
$stack <= factorial($
|
47
|
+
$stack <= factorial($n_1)
|
46
48
|
|
47
49
|
# multiply n * factorial(n-1)
|
48
|
-
compute
|
50
|
+
compute $multiply $n $n_1
|
49
51
|
# Copy answer to result
|
50
|
-
copy $
|
52
|
+
copy $n_1 $result
|
51
53
|
}
|
52
54
|
|
53
|
-
# pop
|
54
|
-
copy &
|
55
|
+
# pop to return address
|
56
|
+
copy &return &stack
|
55
57
|
|
56
58
|
# jump return, pop return address off stack
|
57
|
-
copy $
|
59
|
+
copy $return &pc pop
|
58
60
|
|
data/examples/fib.ucisc
CHANGED
@@ -1,74 +1,79 @@
|
|
1
1
|
# Compute Fibonacci numbers
|
2
2
|
#
|
3
|
-
# By default, computes fib(8) == 21. Change the
|
4
|
-
# to compute other numbers. fib(
|
5
|
-
# will compute correctly. fib(
|
6
|
-
#
|
7
|
-
# number of instructions.
|
3
|
+
# By default, computes fib(8) == 21. Change the immediate value in the fib
|
4
|
+
# function call to compute other numbers. fib(24.imm) is the maximum value that
|
5
|
+
# will compute correctly. fib(25.imm) and up will overflow 16-bits when adding
|
6
|
+
# the final result, but will still terminate.
|
8
7
|
#
|
9
8
|
# To run:
|
10
9
|
# $ exe/ucisc examples/fib.ucisc
|
11
10
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# More instructions on the compiler and debugger are in the README.md
|
16
|
-
# Or use GitHub https://github.com/grokthis/ucisc-ruby#usage
|
11
|
+
# Stack result should be:
|
12
|
+
# INFO: Stack: FFFF => 0x0015
|
17
13
|
|
18
|
-
|
14
|
+
################
|
15
|
+
# Syntax Setup #
|
16
|
+
################
|
19
17
|
$stack as 1.mem
|
20
18
|
&pc as 0.reg
|
21
19
|
|
20
|
+
# ALU op codes
|
21
|
+
$add as 0xA.op
|
22
|
+
$subtract as 0xB.op
|
23
|
+
|
22
24
|
# Simple conditional syntax sugar
|
23
25
|
$zero? as 0.eff
|
24
26
|
$not_zero? as 1.eff
|
25
27
|
$negative? as 2.eff
|
26
28
|
|
27
|
-
|
28
|
-
#
|
29
|
-
|
29
|
+
################
|
30
|
+
# Code Entry #
|
31
|
+
################
|
32
|
+
copy 0.imm &stack
|
30
33
|
|
31
|
-
|
32
|
-
# Then they push the return address, followed by the args. The called function
|
33
|
-
# is expected to remove the return address and args from the stack before returning
|
34
|
-
$stack[1] <= fib(6.imm)
|
34
|
+
$stack[1] <= fib(8.imm)
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
# halt
|
37
|
+
copy &pc &pc
|
38
38
|
|
39
|
+
################
|
40
|
+
# Main Section #
|
41
|
+
################
|
39
42
|
fib:
|
43
|
+
$n, $return, $result = $stack
|
40
44
|
# push n - 1
|
41
|
-
compute
|
45
|
+
$n_1 = compute $subtract 1.imm $n push
|
42
46
|
{
|
43
47
|
# if negative, n == 0
|
44
48
|
copy &pc break.disp &pc $negative?
|
45
49
|
# if zero, n == 1
|
46
50
|
copy &pc break.disp &pc $zero?
|
47
51
|
|
48
|
-
|
49
|
-
# push n - 2
|
50
|
-
compute 0xB.op 1.imm $stack push
|
52
|
+
$n_2 = compute $subtract 1.imm $n_1 push
|
51
53
|
|
52
54
|
# Recurse for fib(n-1) and fib(n-2)
|
53
|
-
$stack[1] <= fib($
|
54
|
-
$stack[1] <= fib($
|
55
|
+
$stack[1] <= fib($n_1)
|
56
|
+
$stack[1] <= fib($n_2)
|
57
|
+
$fib_n_2, $fib_n_1 = $stack
|
55
58
|
|
56
|
-
compute
|
59
|
+
$fib_n = compute $add $fib_n_1 $fib_n_2
|
57
60
|
|
58
|
-
#copy to
|
59
|
-
copy $
|
61
|
+
#copy fib(n) to result
|
62
|
+
copy $fib_n $result
|
60
63
|
|
61
|
-
#
|
62
|
-
copy &
|
64
|
+
# Pop stack to return
|
65
|
+
copy &return &stack
|
63
66
|
|
64
67
|
# Jump return and pop address
|
65
|
-
copy $
|
68
|
+
copy $return &pc pop
|
66
69
|
}
|
70
|
+
# Need reset vars, after block messes with stack
|
71
|
+
$n_1, $n, $return, $result = $stack
|
67
72
|
|
68
73
|
# n == 1 or n == 0, return n
|
69
74
|
# Save result to return
|
70
|
-
copy $
|
71
|
-
copy &
|
75
|
+
copy $n $result
|
76
|
+
copy &return &stack
|
72
77
|
|
73
78
|
# Jump return and pop address
|
74
|
-
copy $
|
79
|
+
copy $return &pc pop
|