From fee1bbd8b4681acca7daba1b3b70ce6d26e52fb4 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 21 Feb 2020 10:05:04 -0800 Subject: 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. --- mu_instructions | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'mu_instructions') 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 -- cgit 1.4.1-2-gfad0