Skip to content

Instantly share code, notes, and snippets.

@milesrout
Last active July 23, 2019 02:01
Show Gist options
  • Save milesrout/521deaabf4124c0e0d7924557bce3a7b to your computer and use it in GitHub Desktop.
Save milesrout/521deaabf4124c0e0d7924557bce3a7b to your computer and use it in GitHub Desktop.
; %n - fp register n
; @n - int register n
; $n - lit int n
initial f32 top, left, bottom, right, 16.0f;
final f32 result[256];
ld %0,$0 ; %0 = top
ld %1,$1 ; %1 = left
ld %2,$2 ; %2 = bottom
ld %3,$3 ; %3 = right
ld %4,$4 ; %4 = 16.0f
sub %2,%0 ; %2 = height (bottom - top)
sub %3,%1 ; %3 = width (right - left)
div %2,%4 ; %2 = height increase per iteration ((bottom - top)/16)
div %3,%4 ; %3 = width increase per iteration ((right - left)/16)
zero @0 ; @0 = output pointer
set @1,$16 ; @1 = iterations top-to-bottom
set @2,$16 ; @2 = iterations left-to-right
mov %4,%0 ; %4 = F_Y
L5: mov %5,%1 ; %5 = F_X
L6: set @3,$1 ; @3 = iteration count
L1: mov %6,%4
mul %6,%6
mov %7,%5
mul %7,%7
add %6,%7
st @0,%2
push @0
ld1 %2
add %2,%2
add %2,%2
lt @0,%6,%2
sub %6,%7
sub %6,%7
jc @0,L2
pop @0
ld %2,@0
ld0 %4
ld1 %5
L3: add %4,%5
loop @3,L3
st @0,%4
jmp L7
L2: pop @0
ld %2,@0
mov %7,%4
add %7,%7
mul %7,%5
add %6,%0
add %7,%1
mov %4,%6
mov %5,%7
inc @3
push @3
cmp @3,$MAX_ITERATIONS
jc L4
pop @3
jmp L1
L4: pop @3
ld0 %4
st @0,%4
jmp L7
L7: inc @0
add %1,%3
loop @2,L6
set @2,$16
L8: sub %1,%3 ; yikes!
loop @2,L8
set @2,$16
add %0,%2
loop @1,L5
halt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment