From 81b171716e75c2b41c3a7747918cc0c560704899 Mon Sep 17 00:00:00 2001 From: phklive Date: Fri, 8 Dec 2023 13:20:15 +0000 Subject: [PATCH 1/6] First commit --- examples/bubble_sort.inputs | 5 ++ examples/bubble_sort.masm | 151 ++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 examples/bubble_sort.inputs create mode 100644 examples/bubble_sort.masm diff --git a/examples/bubble_sort.inputs b/examples/bubble_sort.inputs new file mode 100644 index 00000000..920564a5 --- /dev/null +++ b/examples/bubble_sort.inputs @@ -0,0 +1,5 @@ +{ + "operand_stack": ["0"], + "advice_stack": ["5", "0", "4", "1", "3", "2"] +} + diff --git a/examples/bubble_sort.masm b/examples/bubble_sort.masm new file mode 100644 index 00000000..f462931b --- /dev/null +++ b/examples/bubble_sort.masm @@ -0,0 +1,151 @@ +proc.init + # init `swapped` + mem_store.0 + + # init `i` + push.3 + mem_store.1 + + # init `j` + push.4 + mem_store.2 + + # push advice_tape elements to the stack + adv_push.6 + + # push elements from stack to memory + mem_store.3 + mem_store.4 + mem_store.5 + mem_store.6 + mem_store.7 + mem_store.8 +end + +proc.notSwapped + push.0 + mem_store.0 +end + +proc.swapped + push.1 + mem_store.0 +end + +proc.resetCounters + mem_load.2 + eq.9 + if.true + push.4 + mem_store.2 + push.3 + mem_store.1 + exec.notSwapped + end +end + +proc.incrementCounters + # load `i`, increment and store + mem_load.1 + add.1 + mem_store.1 + + # load `j`, increment and store + mem_load.2 + add.1 + mem_store.2 +end + +proc.loadValues + # load `j` + mem_load.2 + + # load value `b` at index mem[j] + mem_load + + # load `i` + mem_load.1 + + # load value `a` at index mem[i] + mem_load +end + +proc.storeValues + # load `i` + mem_load.1 + + # store value `a` at index mem[i] + mem_store + + # load `j` + mem_load.2 + + # store value `b` at index mem[j] + mem_store +end + +proc.loadAndSort + # load values `a` and `b` + exec.loadValues + + # compare and swap + dup.1 + dup.1 + lt + if.true + swap + exec.swapped + exec.storeValues + else + exec.storeValues + end + + # Increment counters + exec.incrementCounters +end + +proc.sorted + # if ((i == 8 && j == 9) && (swapped == 0)) { + # push.0 + # } else { + # push.1 + # } + # load `i` and load `j` and check if they are 8 and 9 + mem_load.1 + eq.8 + mem_load.2 + eq.9 + and + mem_load.0 + not + and + if.true + push.0 + else + push.1 + end +end + +begin + exec.init + + push.1 + while.true + exec.resetCounters + exec.loadAndSort + exec.sorted + end + + mem_load.8 + mem_load.7 + mem_load.6 + mem_load.5 + mem_load.4 + mem_load.3 +end + +# "advice_stack": ["0", "99", "12", "1", "9", "4"] +# "advice_stack": ["6", "3", "4", "5", "9", "2"] +# "advice_stack": ["7", "1", "8", "4", "3", "5"] +# "advice_stack": ["2", "6", "10", "3", "8", "9"] +# "advice_stack": ["5", "11", "3", "7", "2", "4"] \ No newline at end of file From 57adbde4bad39aa79655ad13831f8788c7d3d6f4 Mon Sep 17 00:00:00 2001 From: phklive Date: Fri, 8 Dec 2023 16:11:08 +0000 Subject: [PATCH 2/6] Able to manage abitrary array length as private input --- examples/bubble_sort.masm | 92 +++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/examples/bubble_sort.masm b/examples/bubble_sort.masm index f462931b..e92d1bc5 100644 --- a/examples/bubble_sort.masm +++ b/examples/bubble_sort.masm @@ -1,25 +1,77 @@ +# Bubble Sort - but provable + proc.init - # init `swapped` + # init `swapped` boolean + push.0 mem_store.0 - # init `i` - push.3 + # init `i` index + push.5 mem_store.1 - # init `j` - push.4 + # init `j` index + push.6 mem_store.2 - # push advice_tape elements to the stack - adv_push.6 - - # push elements from stack to memory + # init `g` counter + push.0 mem_store.3 + + # init `adv` length mem_store.4 - mem_store.5 - mem_store.6 - mem_store.7 - mem_store.8 + + # loop out advice_stack elements + push.1 + while.true + adv_push.1 + mem_load.3 + add.1 + dup + mem_store.3 + mem_load.4 + eq + if.true + push.0 + push.0 + mem_store.3 + else + push.1 + end + end + + push.1 + while.true + # push 5 to the stack + push.5 + + # load `g` counter + mem_load.3 + + # add both values + add + + # store element at that mem[i] + mem_store + + # increment `g` by 1 + mem_load.3 + add.1 + mem_store.3 + + # Check if all elements have been pushed + mem_load.3 + mem_load.4 + + # Stop loop if `g` == `adv` + eq + if.true + push.0 + push.0 + mem_store.3 + else + push.1 + end + end end proc.notSwapped @@ -128,20 +180,6 @@ end begin exec.init - - push.1 - while.true - exec.resetCounters - exec.loadAndSort - exec.sorted - end - - mem_load.8 - mem_load.7 - mem_load.6 - mem_load.5 - mem_load.4 - mem_load.3 end # "advice_stack": ["0", "99", "12", "1", "9", "4"] From 337a509ff9c2b248153c7585bd6c43510a5e1fbd Mon Sep 17 00:00:00 2001 From: phklive Date: Fri, 8 Dec 2023 19:58:51 +0000 Subject: [PATCH 3/6] Added documentation --- examples/bubble_sort.inputs | 4 +- examples/bubble_sort.masm | 301 ++++++++++++++++++++++++++++-------- 2 files changed, 242 insertions(+), 63 deletions(-) diff --git a/examples/bubble_sort.inputs b/examples/bubble_sort.inputs index 920564a5..bb142565 100644 --- a/examples/bubble_sort.inputs +++ b/examples/bubble_sort.inputs @@ -1,5 +1,5 @@ { - "operand_stack": ["0"], - "advice_stack": ["5", "0", "4", "1", "3", "2"] + "operand_stack": ["16"], + "advice_stack": ["7", "1", "8", "4", "3", "5", "19", "13", "0", "4", "7", "2", "5", "1", "5", "7"] } diff --git a/examples/bubble_sort.masm b/examples/bubble_sort.masm index e92d1bc5..2f6c2f2d 100644 --- a/examples/bubble_sort.masm +++ b/examples/bubble_sort.masm @@ -1,149 +1,272 @@ -# Bubble Sort - but provable - -proc.init - # init `swapped` boolean +# Bubble sort - but provable! +# +# Bubble sort is a sorting algorithm that repeatedly steps through the array, +# compares adjacent elements, and swaps them if they are in the wrong order. +# The process is repeated until the array is sorted, with smaller elements "bubbling" to the top of the array. +# +# Time Complexity: +# - Best Case: O(n) (when the array is already sorted). +# - Average Case: O(n^2) (for a randomly ordered array). +# - Worst Case: O(n^2) (when the array is sorted in reverse order). +# +# Space Complexity: +# - O(1), requiring only a constant amount of space regardless of the input size. (generally yes; not the case here) +# +# Benefits: +# - Simplicity: Easy to understand and implement, suitable for small arrays. +# - In-place: Requires only a constant amount O(1) of additional memory space. (generally yes; not the case here) +# - Adaptive: Efficient for datasets that are already substantially sorted, as it can +# detect if the array is already sorted and stop early. +# +# Trade-offs: +# - Inefficiency: Performance degrades quickly with large datasets compared to more +# advanced algorithms like quicksort or mergesort. +# - High Operation Count: Requires multiple passes through the entire array, +# leading to a higher number of overall operations. +# +# Usage Guidelines: +# - Do's: +# - Add the length of the array as the only public input element in the `operand_stack`. +# - Add the array to be sorted as private input elements in the `advice_stack`. +# - Dont's: +# - Avoid running the program without correctly populating the `operand_stack` and `advice_stack`. +# - Do not input a length greater than the actual length of the array. +# - Note that the VM does not support negative numbers. +# - Additional Information: +# - The VM will output only the first 16 elements of your sorted array. +# - The program processes 'n' elements equal to the number added as public input, +# regardless of the actual length of the array. +# +# Example Usage: +# To sort an array of 10 elements, add '10' to the `operand_stack` as public input, +# and add the array elements onto the `advice_stack` as private input. +# Execute the program to get the sorted array as output. + +# initialise() -> void +# +# Initialises the VM by proceeding with these 3 consecutive tasks: +# 1. Initialises variables `swapped`, `i`, `j`, `g` and `adv` in `memory` +# Usage: +# `swapped` : boolean -> [a,b,...] into [b,a,...] +# `i` : counter -> mem[i] +# `j` : counter -> mem[j] +# `g` : counter -> general counter +# `adv`: length -> array length (passed as public input) +# +# 2. Loops over the `advice_stack` to push inputed array to `operand_stack` +# +# 3. Loops over the `operand_stack` to add inputed array to `memory` +# +# After using initialise() the inputed array is ready to be manipulated and sorted +proc.initialise + # initialise `swapped` boolean - initialised at 0 / false push.0 mem_store.0 - # init `i` index + # initialise `i` index - initialised at 5 because mem[5] is the array start index push.5 mem_store.1 - # init `j` index + # initialise `j` index - initialised at 6 because mem[6] is the second array index push.6 mem_store.2 - # init `g` counter + # initialise `g` counter - initialised at 0 push.0 mem_store.3 - # init `adv` length + # initialise `adv` length - initialised as the array length using the public inputs mem_store.4 - # loop out advice_stack elements + # Loop over the `advice_stack` pushing values 1-by-1 on the `operand_stack` push.1 while.true + # Push 1 element from the array into the `operand_stack` adv_push.1 + + # Load and increment `g` counter to keep track of added elements mem_load.3 add.1 dup mem_store.3 + + # Load `adv` array length and check if `g` == `adv`; + # signifying that all elements from array have been added to `operand_stack` mem_load.4 eq if.true + # Stop looping and reset `g` to 0 push.0 push.0 mem_store.3 else + # Continue looping push.1 end end + # Loop over the `operand_stack` pushing values 1-by-1 into memory starting at mem[5] push.1 while.true - # push 5 to the stack + # Offset by 5 considering that we have 5 pre-set variables in `memory` + # and that memory is linear meaning that array starts at mem[5] push.5 - # load `g` counter + # Load `g` counter and add to 5 enabling incremental insertion mem_load.3 - - # add both values add - # store element at that mem[i] + # store element at that mem[5 + g] mem_store - # increment `g` by 1 + # increment `g` by 1 and overwrite `memory` mem_load.3 add.1 mem_store.3 - # Check if all elements have been pushed + # Load `g` counter and `adv` array length; + # check if `g` == `adv; signifying that all elements + # have been placed in `memory` mem_load.3 mem_load.4 - - # Stop loop if `g` == `adv` eq if.true + # Stop looping and reset `g` to 0 push.0 push.0 mem_store.3 else + # Continue looping push.1 end end -end -proc.notSwapped - push.0 - mem_store.0 + # Prepare the `operand_stack` for sort loop + push.1 end -proc.swapped +# swapped() -> void +# +# Sets the `swapped` boolean variable to 1 - true +proc.swapped push.1 - mem_store.0 + mem_store.0 end -proc.resetCounters - mem_load.2 - eq.9 - if.true - push.4 - mem_store.2 - push.3 - mem_store.1 - exec.notSwapped - end +# notSwapped() -> void +# +# Sets the `swapped` boolean variable to 0 - false +# +proc.notSwapped + push.0 + mem_store.0 end +# incrementCounters() -> void +# +# Increments the `i` and `j` counter variables by 1 proc.incrementCounters - # load `i`, increment and store + # load `i` counter, increment it by 1 and store it in mem[1] mem_load.1 add.1 mem_store.1 - # load `j`, increment and store + # load `j` counter, increment it by 1 and store it in mem[2] mem_load.2 add.1 mem_store.2 end +# decrementCounters() -> void +# +# Decrements the `i` and `j` counter variables by 1 +proc.decrementCounters + # load `i` counter, decrement it by 1 and store it in mem[1] + mem_load.1 + sub.1 + mem_store.1 + + # load `j` counter, decrement by 1 and store it in mem[2] + mem_load.2 + sub.1 + mem_store.2 +end + +# resetCounters() -> void +# +# Resets the `i` and `j` counter variables to their initial state if required conditions are met +proc.resetCounters + # It is needed to reset the counters if `i` and `j` + # are pointing the end of the array. Resetting the counters + # enables us to start over from the initial mem[i], mem[j] + + # Load `j` counter and `adv` array length + mem_load.2 + mem_load.4 + + # Offset by 5 considering that we have 5 pre-set variables in `memory` + # and that memory is linear meaning that array starts at mem[5] + add.5 + + # Check if they are equal + eq + if.true + # Reset `i`, `j` counters and `swapped` boolean to their initial values + push.6 + mem_store.2 + push.5 + mem_store.1 + exec.notSwapped + end +end + +# loadValues() -> void +# +# Loads counters `i` and `j` and loads [a,b,...] `operand_stack` elements from mem[i], mem[j] proc.loadValues - # load `j` + # load `j` counter mem_load.2 # load value `b` at index mem[j] mem_load - # load `i` + # load `i` counter mem_load.1 # load value `a` at index mem[i] mem_load end +# storeValues() -> void +# +# Loads counters `i` and `j` and stores [a,b,...] `operand_stack` elements in mem[i], mem[j] proc.storeValues - # load `i` + # load `i` counter mem_load.1 # store value `a` at index mem[i] mem_store - # load `j` + # load `j` counter mem_load.2 # store value `b` at index mem[j] mem_store end -proc.loadAndSort - # load values `a` and `b` +# sort() -> void +# +# Loads values [a,b,...] from `memory` into the `operand_stack` before sorting them +proc.sort + # Load values `a` and `b` into the `operand_stack` exec.loadValues - # compare and swap + # Duplicate and compare them dup.1 dup.1 lt + + # If a > b then swap and store else store values as is if.true swap exec.swapped @@ -152,24 +275,32 @@ proc.loadAndSort exec.storeValues end - # Increment counters + # Increment counters to point to the next two elements of the array exec.incrementCounters end +# sorted() -> bool +# +# Checks if the array has been sorted proc.sorted - # if ((i == 8 && j == 9) && (swapped == 0)) { - # push.0 - # } else { - # push.1 - # } - # load `i` and load `j` and check if they are 8 and 9 - mem_load.1 - eq.8 + # Array is sorted if counters `i` and `j` are at end of array && `swapped` == 0 + # We don't need to load both `i` and `j`, using only `j` is sufficient + # Load `j` counter and `adv` array length mem_load.2 - eq.9 - and + mem_load.4 + + # Offset by 5 considering that we have 5 pre-set variables in `memory` + # and that memory is linear meaning that array starts at mem[5] + add.5 + + # Check if they are equal; signifying end of array + eq + + # Load `swapped` boolean mem_load.0 not + + # Check if both requirements are true and if.true push.0 @@ -178,12 +309,60 @@ proc.sorted end end -begin - exec.init + +# printResult() -> void +# +# Adds the array elements to the `operand_stack` before program completion and output +proc.printResult + push.1 + while.true + # Load the `i` counter; at this moment will be equal to `adv` + mem_load.1 + + # Load from `memory` to `operand_stack` element at location mem[i] + mem_load + + # Load `g` counter and increment by 1; signifying that 1 element + # has been added to the `operand_stack` from `memory` + mem_load.3 + add.1 + mem_store.3 + + # Decrement counters - going through `memory` in reverse order + exec.decrementCounters + + # Load `adv` and `g` + mem_load.4 + mem_load.3 + + # Check if `g` == `adv` meaning that we have added all elements to the `operand_stack` + eq + + # Exits the loop + if.true + push.0 + else + push.1 + end + end end -# "advice_stack": ["0", "99", "12", "1", "9", "4"] -# "advice_stack": ["6", "3", "4", "5", "9", "2"] -# "advice_stack": ["7", "1", "8", "4", "3", "5"] -# "advice_stack": ["2", "6", "10", "3", "8", "9"] -# "advice_stack": ["5", "11", "3", "7", "2", "4"] \ No newline at end of file +begin + # Initialise the VM + exec.initialise + + # Loop over the array and sort recursively + while.true + # If looping has been done over the whole array reset counters to start over from the beginning + exec.resetCounters + + # Sort elements two-by-two recursively + exec.sort + + # Check if the array is sorted if so then stop looping + exec.sorted + end + + # Add array to operand_stack for output - printing result + exec.printResult +end \ No newline at end of file From 206f407c7a011058b14d5bd73777c5bf007478fc Mon Sep 17 00:00:00 2001 From: phklive Date: Fri, 8 Dec 2023 20:24:08 +0000 Subject: [PATCH 4/6] typo --- examples/bubble_sort.masm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/bubble_sort.masm b/examples/bubble_sort.masm index 2f6c2f2d..8028db21 100644 --- a/examples/bubble_sort.masm +++ b/examples/bubble_sort.masm @@ -351,12 +351,12 @@ begin # Initialise the VM exec.initialise - # Loop over the array and sort recursively + # Loop over the array and sort repeatedly while.true # If looping has been done over the whole array reset counters to start over from the beginning exec.resetCounters - # Sort elements two-by-two recursively + # Sort elements two-by-two repeatedly exec.sort # Check if the array is sorted if so then stop looping From e8dea5c9668c091828308e633a9fdb55a67966e3 Mon Sep 17 00:00:00 2001 From: phklive Date: Mon, 15 Jan 2024 14:10:49 +0100 Subject: [PATCH 5/6] Added constants, docs for proc.initialise and changed adv and g --- examples/bubble_sort.masm | 112 ++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 42 deletions(-) diff --git a/examples/bubble_sort.masm b/examples/bubble_sort.masm index 8028db21..66c15658 100644 --- a/examples/bubble_sort.masm +++ b/examples/bubble_sort.masm @@ -42,41 +42,69 @@ # and add the array elements onto the `advice_stack` as private input. # Execute the program to get the sorted array as output. -# initialise() -> void -# -# Initialises the VM by proceeding with these 3 consecutive tasks: -# 1. Initialises variables `swapped`, `i`, `j`, `g` and `adv` in `memory` -# Usage: -# `swapped` : boolean -> [a,b,...] into [b,a,...] -# `i` : counter -> mem[i] -# `j` : counter -> mem[j] -# `g` : counter -> general counter -# `adv`: length -> array length (passed as public input) -# -# 2. Loops over the `advice_stack` to push inputed array to `operand_stack` -# -# 3. Loops over the `operand_stack` to add inputed array to `memory` -# -# After using initialise() the inputed array is ready to be manipulated and sorted +# GLOBAL INPUTS +# ------------------------------------------------------------------------------------------------- + +# The memory address at which the `swapped` boolean is stored +const.SWAPPED_ADDRESS=0 + +# The value initial value of the `swapped` variable +const.SWAPPED=0 + +# The memory address at which the `i_pointer` variable is stored +const.I_POINTER_ADDRESS=1 + +# The value initial value of the `i_pointer` variable +const.I_POINTER=5 + +# The memory address at which the `j_pointer` variable is stored +const.J_POINTER_ADDRESS=2 + +# The value initial value of the `j_pointer` variable +const.J_POINTER=6 + +# The memory address at which the `counter` variable is stored +const.COUNTER_ADDRESS=3 + +# The value initial value of the `counter` variable +const.COUNTER=0 + +# The memory address at which the `length` variable is stored +const.LENGTH_ADDRESS=4 + +#! Initialises memory for sorting. +#! +#! Input: +#! operand_stack: [n, ...] +#! advice_stack: [d0, d1, .., dn] +#! Output: [...] +#! +#! Where: +#! n: is the count of elements to be sorted. proc.initialise # initialise `swapped` boolean - initialised at 0 / false - push.0 - mem_store.0 + push.SWAPPED + push.SWAPPED_ADDRESS + mem_store # initialise `i` index - initialised at 5 because mem[5] is the array start index - push.5 - mem_store.1 + push.I_POINTER + push.I_POINTER_ADDRESS + mem_store # initialise `j` index - initialised at 6 because mem[6] is the second array index - push.6 - mem_store.2 + push.J_POINTER + push.J_POINTER_ADDRESS + mem_store - # initialise `g` counter - initialised at 0 - push.0 - mem_store.3 + # initialise `counter` - initialised at 0 + push.COUNTER + push.COUNTER_ADDRESS + mem_store - # initialise `adv` length - initialised as the array length using the public inputs - mem_store.4 + # initialise `length` - initialised as the array length using the public inputs + push.LENGTH_ADDRESS + mem_store # Loop over the `advice_stack` pushing values 1-by-1 on the `operand_stack` push.1 @@ -84,18 +112,18 @@ proc.initialise # Push 1 element from the array into the `operand_stack` adv_push.1 - # Load and increment `g` counter to keep track of added elements + # Load and increment `counter` to keep track of added elements mem_load.3 add.1 dup mem_store.3 - # Load `adv` array length and check if `g` == `adv`; + # Load `length` array length and check if `counter` == `length` # signifying that all elements from array have been added to `operand_stack` mem_load.4 eq if.true - # Stop looping and reset `g` to 0 + # Stop looping and reset `counter` to 0 push.0 push.0 mem_store.3 @@ -112,26 +140,26 @@ proc.initialise # and that memory is linear meaning that array starts at mem[5] push.5 - # Load `g` counter and add to 5 enabling incremental insertion + # Load `counter` counter and add to 5 enabling incremental insertion mem_load.3 add # store element at that mem[5 + g] mem_store - # increment `g` by 1 and overwrite `memory` + # increment `counter` by 1 and overwrite `memory` mem_load.3 add.1 mem_store.3 - # Load `g` counter and `adv` array length; - # check if `g` == `adv; signifying that all elements + # Load `counter` counter and `length` array length; + # check if `counter` == `length` signifying that all elements # have been placed in `memory` mem_load.3 mem_load.4 eq if.true - # Stop looping and reset `g` to 0 + # Stop looping and reset `counter` to 0 push.0 push.0 mem_store.3 @@ -200,7 +228,7 @@ proc.resetCounters # are pointing the end of the array. Resetting the counters # enables us to start over from the initial mem[i], mem[j] - # Load `j` counter and `adv` array length + # Load `j` counter and `length` array length mem_load.2 mem_load.4 @@ -272,7 +300,7 @@ proc.sort exec.swapped exec.storeValues else - exec.storeValues + drop drop end # Increment counters to point to the next two elements of the array @@ -285,7 +313,7 @@ end proc.sorted # Array is sorted if counters `i` and `j` are at end of array && `swapped` == 0 # We don't need to load both `i` and `j`, using only `j` is sufficient - # Load `j` counter and `adv` array length + # Load `j` counter and `length` array length mem_load.2 mem_load.4 @@ -316,13 +344,13 @@ end proc.printResult push.1 while.true - # Load the `i` counter; at this moment will be equal to `adv` + # Load the `i` counter; at this moment will be equal to `length` mem_load.1 # Load from `memory` to `operand_stack` element at location mem[i] mem_load - # Load `g` counter and increment by 1; signifying that 1 element + # Load `counter` counter and increment by 1; signifying that 1 element # has been added to the `operand_stack` from `memory` mem_load.3 add.1 @@ -331,11 +359,11 @@ proc.printResult # Decrement counters - going through `memory` in reverse order exec.decrementCounters - # Load `adv` and `g` + # Load `length` and `counter` mem_load.4 mem_load.3 - # Check if `g` == `adv` meaning that we have added all elements to the `operand_stack` + # Check if `counter` == `length` meaning that we have added all elements to the `operand_stack` eq # Exits the loop From b7ffea9d32e448e1385b2241344d908011315a64 Mon Sep 17 00:00:00 2001 From: phklive Date: Mon, 15 Jan 2024 14:12:54 +0100 Subject: [PATCH 6/6] Added constants only for addresses --- examples/bubble_sort.masm | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/examples/bubble_sort.masm b/examples/bubble_sort.masm index 66c15658..b5ffd4b2 100644 --- a/examples/bubble_sort.masm +++ b/examples/bubble_sort.masm @@ -48,27 +48,15 @@ # The memory address at which the `swapped` boolean is stored const.SWAPPED_ADDRESS=0 -# The value initial value of the `swapped` variable -const.SWAPPED=0 - # The memory address at which the `i_pointer` variable is stored const.I_POINTER_ADDRESS=1 -# The value initial value of the `i_pointer` variable -const.I_POINTER=5 - # The memory address at which the `j_pointer` variable is stored const.J_POINTER_ADDRESS=2 -# The value initial value of the `j_pointer` variable -const.J_POINTER=6 - # The memory address at which the `counter` variable is stored const.COUNTER_ADDRESS=3 -# The value initial value of the `counter` variable -const.COUNTER=0 - # The memory address at which the `length` variable is stored const.LENGTH_ADDRESS=4 @@ -83,22 +71,22 @@ const.LENGTH_ADDRESS=4 #! n: is the count of elements to be sorted. proc.initialise # initialise `swapped` boolean - initialised at 0 / false - push.SWAPPED + push.0 push.SWAPPED_ADDRESS mem_store # initialise `i` index - initialised at 5 because mem[5] is the array start index - push.I_POINTER + push.5 push.I_POINTER_ADDRESS mem_store # initialise `j` index - initialised at 6 because mem[6] is the second array index - push.J_POINTER + push.6 push.J_POINTER_ADDRESS mem_store # initialise `counter` - initialised at 0 - push.COUNTER + push.0 push.COUNTER_ADDRESS mem_store