diff options
Diffstat (limited to 'ecomp-c/tests/example_insertion_sort.easm')
-rw-r--r-- | ecomp-c/tests/example_insertion_sort.easm | 366 |
1 files changed, 366 insertions, 0 deletions
diff --git a/ecomp-c/tests/example_insertion_sort.easm b/ecomp-c/tests/example_insertion_sort.easm new file mode 100644 index 0000000..cbbf8c0 --- /dev/null +++ b/ecomp-c/tests/example_insertion_sort.easm @@ -0,0 +1,366 @@ +format binary +use32 +org $1000000 +; CONST N -> integer, 10 +; DECL i -> integer, 0 +; DECL j -> integer, 0 +; DECL x -> integer, 0 +; DECL a -> array 10 of integer, array 10 of integer = { ... } +; LET a[0 ] <- 7 +mov eax, 0 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 7 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[1 ] <- 4 +mov eax, 1 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 4 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[2 ] <- 0 +mov eax, 2 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 0 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[3 ] <- 8 +mov eax, 3 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 8 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[4 ] <- 5 +mov eax, 4 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 5 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[5 ] <- 3 +mov eax, 5 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 3 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[6 ] <- 1 +mov eax, 6 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 1 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[7 ] <- 9 +mov eax, 7 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 9 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[8 ] <- 6 +mov eax, 8 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 6 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET a[9 ] <- 2 +mov eax, 9 +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, 2 +push eax +pop eax +pop ebx +mov [ebx], eax +; LET i <- 1 +mov eax, 1 +push eax +pop eax +mov [i], eax +; WHILE i 10 < +__global_0: +mov eax, [i] +push eax +mov eax, 10 +push eax +pop ebx +pop eax +cmp eax, ebx +jb __global_4 +mov eax, 0 +jmp __global_5 +__global_4: mov eax, 1 +__global_5: +push eax +pop eax +mov ebx, 0 +cmp eax, ebx +je __global_2 +jmp __global_3 +__global_2: jmp __global_1 +__global_3: +; LET x <- i [ +mov eax, [i] +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +pop ebx +mov eax, [ebx] +push eax +pop eax +mov [x], eax +; LET j <- i +mov eax, [i] +push eax +pop eax +mov [j], eax +; WHILE j 0 > x j 1 - [ < and +__global_6: +; expr left +mov eax, [j] +push eax +mov eax, 0 +push eax +pop ebx +pop eax +cmp eax, ebx +ja __global_11 +mov eax, 0 +jmp __global_12 +__global_11: mov eax, 1 +__global_12: +push eax +pop eax +mov ebx, 0 +cmp eax, ebx +je __global_10 +; expr right +mov eax, [x] +push eax +mov eax, [j] +push eax +mov eax, 1 +push eax +pop ebx +pop eax +sub eax, ebx +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +pop ebx +mov eax, [ebx] +push eax +pop ebx +pop eax +cmp eax, ebx +jb __global_13 +mov eax, 0 +jmp __global_14 +__global_13: mov eax, 1 +__global_14: +push eax +pop eax +__global_10: +push eax +pop eax +mov ebx, 0 +cmp eax, ebx +je __global_8 +jmp __global_9 +__global_8: jmp __global_7 +__global_9: +; LET a[j ] <- j 1 - [ +mov eax, [j] +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, [j] +push eax +mov eax, 1 +push eax +pop ebx +pop eax +sub eax, ebx +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +pop ebx +mov eax, [ebx] +push eax +pop eax +pop ebx +mov [ebx], eax +; LET j <- j 1 - +mov eax, [j] +push eax +mov eax, 1 +push eax +pop ebx +pop eax +sub eax, ebx +push eax +pop eax +mov [j], eax +jmp __global_6 +__global_7: +; LET a[j ] <- x +mov eax, [j] +push eax +pop eax +mov ebx, 4 +mul ebx +push eax +mov eax, a +pop ebx +add eax, ebx +push eax +mov eax, [x] +push eax +pop eax +pop ebx +mov [ebx], eax +; LET i <- i 1 + +mov eax, [i] +push eax +mov eax, 1 +push eax +pop ebx +pop eax +add eax, ebx +push eax +pop eax +mov [i], eax +jmp __global_0 +__global_1: +hlt +a: dd $00000000 +dd $00000000 +dd $00000000 +dd $00000000 +dd $00000000 +dd $00000000 +dd $00000000 +dd $00000000 +dd $00000000 +dd $00000000 +x: dd $00000000 +j: dd $00000000 +i: dd $00000000 |