Santa Claus — modified 2022-02-25 14:21 (314 days ago) — edit — reply
Zde připojuji svůj program. Používá registry A až S, přestože počet indexů je malý, a to pro návodná pojmenování. Pro optimalizaci by šly použité registry přejmenovat na A-D a registr L vůbec nepoužívat, tak jako tak je pomocná paměť konstantní.
Instruction pointer má být na začátku nastaven na 1.
# length of the array
L := [0]
# currently sorted part of the array
S := 1
outer_loop:
# if the sorted part is at least as big as lenght (smaller only if L=0)
if L <= S then halt
# currently inserted element index
C := S + 1
# inner loop is the insert procedure
inner_loop:
if C = 1 then goto inner_loop_end
# the element before the inserted one for comparison
D := C - 1
if [C] < [D] then goto swap_c_and_d
goto inner_loop_end
return_from_swap:
C := C - 1
goto inner_loop
inner_loop_end:
# sorted area increases
S := S + 1
goto outer_loop
swap_c_and_d:
H := [D]
[D] := [C]
[C] := H
goto return_from_swap