hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/examples/mandelbrot.hdass
diff options
context:
space:
mode:
Diffstat (limited to 'examples/mandelbrot.hdass')
-rw-r--r--examples/mandelbrot.hdass26
1 files changed, 10 insertions, 16 deletions
diff --git a/examples/mandelbrot.hdass b/examples/mandelbrot.hdass
index 9054c15..9a1fd45 100644
--- a/examples/mandelbrot.hdass
+++ b/examples/mandelbrot.hdass
@@ -1,11 +1,6 @@
[entry: main]
[enable: logical_registers]
-// Renders the Mandelbrot set as ASCII art. The evolving z value is kept in a
-// Complex struct on the stack (accessed through its field offsets), while the
-// per-pixel constant c stays in xmm2/xmm3. Uses double-precision floats and the
-// logical_registers extension (r1..r14 name the general-purpose registers).
-
const SYS_WRITE = 1
const SYS_EXIT = 60
const STDOUT = 1
@@ -27,7 +22,7 @@ proc main
stack z[Complex.size]
stack row[W + 1]
- r11 = 0 // py
+ r11 = 0 // py
row_loop:
// ci = py * 0.08 - 1.2
@@ -37,7 +32,7 @@ row_loop:
xmm7 = 1.2
xmm3 -= xmm7
- r12 = 0 // px
+ r12 = 0 // px
col_loop:
// cr = px * 0.04375 - 2.5
@@ -51,12 +46,12 @@ col_loop:
xmm0 = 0.0
r5 = z
r5 += Complex.re
- ^r5 = xmm0 // z.re = 0
+ ^r5 = xmm0 // z.re = 0
r5 = z
r5 += Complex.im
- ^r5 = xmm0 // z.im = 0
+ ^r5 = xmm0 // z.im = 0
- r2 = 0 // iteration count
+ r2 = 0 // iteration count
iter_loop:
// load z into xmm0 (zr) and xmm1 (zi)
@@ -79,12 +74,12 @@ iter_loop:
if xmm6 > 4.0
goto plot
- // new_zi = 2*zr*zi + ci (uses the old zr and zi)
+ // new_zi = 2*zr*zi + ci
xmm6 = xmm0
xmm6 *= xmm1
xmm6 += xmm6
xmm6 += xmm3
- xmm7 = xmm6 // stash new_zi
+ xmm7 = xmm6
// new_zr = zr2 - zi2 + cr
xmm4 -= xmm5
@@ -93,17 +88,17 @@ iter_loop:
// store the new z back into the struct
r5 = z
r5 += Complex.re
- ^r5 = xmm4 // z.re = new_zr
+ ^r5 = xmm4 // z.re = new_zr
r5 = z
r5 += Complex.im
- ^r5 = xmm7 // z.im = new_zi
+ ^r5 = xmm7 // z.im = new_zi
r2 += 1
if r2 < MAX_ITER
goto iter_loop
plot:
- // index = iter * 9 / MAX_ITER, then char = palette[index]
+ // index = iter * 9 / MAX_ITER
r1 = r2
r1 *= 9
r3 = MAX_ITER
@@ -121,7 +116,6 @@ plot:
if r12 < W
goto col_loop
- // terminate the row with a newline and write it
r6 = row
r6 += W
r1 = 10