From e4dea8e6f9d8882df5d8abc34cb85732bf0ff531 Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 25 Nov 2019 14:29:13 +0000 Subject: [PATCH] Add example program for flags --- examples/sort.mima | Bin 0 -> 876 bytes examples/sort.mima-flags | 2 + examples/sort.mima-symbols | 12 +++++ examples/sort.mimasm | 108 +++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 examples/sort.mima create mode 100644 examples/sort.mima-flags create mode 100644 examples/sort.mima-symbols create mode 100644 examples/sort.mimasm diff --git a/examples/sort.mima b/examples/sort.mima new file mode 100644 index 0000000000000000000000000000000000000000..52358784d9a22ced754b9d7667a7349282745a8f GIT binary patch literal 876 zcmZQzWIzRs3=HfH49pA+EDQ{+3=B*R44e!M91IL>sLBQ{k8{wvj5voe{{R16X3=Rqm%>oR~6By+b7+MqX?GFp4NJv@8ILG%a9g{m8&zz|dg8&@_Qj nSO6s0+Q7)RfT3A|0VKNtWJ1#hkltnkhDHU3<_1Ql4-5= 0) { +selection_loop: +LDV selection_index +JMN selection_loop_exit + + ; max_find_index = selection_index; + STV max_find_index ; Prepare loop variable + ; max_index = selection_index; + STV max_index + + ; while (--max_find_index >= 0) { + max_find_loop: + ;; Decrement loop variable + LDV max_find_index + ADD minus_one + ;; If we've reached the end, jump to the end of the loop + JMN max_find_loop_exit + STV max_find_index + + ;; This section calculates the condition for the following if statement and + ;; places it in the accumulator register. + ; tmp = mem[max_find_index]; + LDIV max_find_index + STV tmp + ; acc = -mem[max_index]; + LDIV max_index + NOT + ADD one + ; acc += tmp; + ADD tmp ; contains [max_find_index] + ; Now: acc == mem[max_find_index] - mem[max_index] + + ; if (mem[max_find_index] >= mem[max_index]) { + JMN max_find_loop_no_new_value + + ; max_index = max_find_index; + LDV max_find_index + STV max_index + + ; } + max_find_loop_no_new_value: + + ; } + JMP max_find_loop + max_find_loop_exit: + + ; tmp = mem[selection_index]; + LDIV selection_index + STV tmp + ; mem[selection_index] = mem[max_index]; + LDIV max_index + STIV selection_index + ; mem[max_index] = tmp; + LDV tmp + STIV max_index + + ; selection_index--; + LDV selection_index + ADD minus_one + STV selection_index + +; } +JMP selection_loop +selection_loop_exit: + +; Aaand we're done +HALT +.flagoff er