about summary refs log tree commit diff stats
path: root/mu_instructions
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-02-21 10:05:04 -0800
committerKartik Agaram <vc@akkartik.com>2020-02-21 10:09:59 -0800
commitfee1bbd8b4681acca7daba1b3b70ce6d26e52fb4 (patch)
treeceae46b4b130d02eac6de7cc2379ebcd61bf9564 /mu_instructions
parent1837f6117632c80214f45ed94a0d3406810e431f (diff)
downloadmu-fee1bbd8b4681acca7daba1b3b70ce6d26e52fb4.tar.gz
6041 - array indexing starting to work
And we're using it now in factorial.mu!

In the process I had to fix a couple of bugs in pointer dereferencing.

There are still some limitations:
a) Indexing by a literal doesn't work yet.
b) Only arrays of ints supported so far.

Looking ahead, I'm not sure how I can support indexing arrays by non-literals
(variables in registers) unless the element size is a power of 2.
Diffstat (limited to 'mu_instructions')
-rw-r--r--mu_instructions10
1 files changed, 10 insertions, 0 deletions
diff --git a/mu_instructions b/mu_instructions
index 35f9e141..017527b9 100644
--- a/mu_instructions
+++ b/mu_instructions
@@ -205,4 +205,14 @@ loop label                  {.name="loop",            .inouts=[label],
 break                       {.name="break",                                             .subx-name="e9/jump break/disp32"}
 break label                 {.name="break",           .inouts=[label],                  .subx-name="e9/jump",                             .disp32=inouts[0] ":break"}
 
+Array operations
+
+var/reg <- length var2/reg2: (addr array T)
+                            {.name="length",          .inouts=[reg2], .outputs=[reg1],  .subx-name="8b/copy-from",          .rm32="*" inouts[0],                        .r32=outputs[0]}
+var/reg <- index arr/rega: (addr array T), idx/regi: int
+                            {.name="index",           .inouts=[rega, regi], .outputs=[reg], .subx-name="8d/copy-address",   .rm32="*(" inouts[0] "+" inouts[1] "<<2)",  .r32=outputs[0]}
+var/reg <- index arr/rega: (addr array T), n
+compare var, n              {.name="compare",         .inouts=[var, n],                 .subx-name="81 7/subop/compare",    .rm32="*(ebp+" inouts[0].stack-offset ")",                      .imm32=inouts[1]}
+                            {.name="index",           .inouts=[rega, n], .outputs=[reg], .subx-name="8d/copy-address",      .rm32="*(" inouts[0] "+" inouts[1] "<<2)",  .r32=outputs[0]}
+
 vim:ft=c:nowrap
06cbae1895e3b9800124f94e3d7a'>^
4ea0f69a ^

240394a4 ^

712aa449
240394a4 ^

240394a4 ^
7dc8fef8 ^
9e89f023 ^
36e4e71e ^
20ab9343 ^

20ab9343 ^





4ea0f69a ^

240394a4 ^
7dc8fef8 ^
36e4e71e ^

4a383291 ^
78a7d762 ^
e952d6cb ^
78a7d762 ^
e952d6cb ^
4ea0f69a ^

7838675f ^

07069888 ^

07069888 ^
7838675f ^

1891697f ^
755e7df1 ^
a3d5f44b ^
66a8d4ff ^
7838675f ^
7dc8fef8 ^
80a93f0b ^
500cf259 ^

7dc8fef8 ^


80a93f0b ^
240394a4 ^



240394a4 ^
7dc8fef8 ^
240394a4 ^




7dc8fef8 ^
240394a4 ^



e5fb3d74 ^
240394a4 ^

240394a4 ^
7dc8fef8 ^



7b33b517 ^

176e8a68 ^
7b33b517 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99