We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Crawssembly/Mandelbrot
The following is a Crawssembly implementation of a Mandelbrot set renderer by User:Craw. It uses the virtual machine's graphical framebuffer to display the Mandelbrot set, with colours determined by the number of iterations required for each point to escape.
As Crawssembly does not have native floating-point arithmetic or multiplication instructions, the calculations are performed using fixed-point integer arithmetic.
Implementation
The Mandelbrot set is defined by the recurrence relation:
- zn+1 = zn² + c, where z0 = 0
where c is a complex number corresponding to a point on the display.
Separating the real and imaginary components gives:
- xn+1 = xn² − yn² + cx
- yn+1 = 2xnyn + cy
For each pixel, the program repeatedly evaluates these equations until either
- xn² + yn² > 4
or a predetermined iteration limit is reached.
Fixed-point arithmetic
Since Crawssembly operates on signed 32-bit integers, fractional values are represented by scaling integers by a power of two:
- X = ⌊x × 2k⌋
Multiplication of two fixed-point values therefore requires the resulting product to be shifted right by k bits to restore the original scale.
This allows the Mandelbrot set to be calculated using integer arithmetic, bitwise shifts and conditional control flow.
Rendering
Each pixel of the framebuffer is mapped to a coordinate on the complex plane. The escape iteration count determines the colour assigned to that pixel.
The resulting image is displayed using Crawssembly's screen device.
Source code
; MANDELBROT EXPLORER
; 128x128 screen / Q10 / 64 iterations
; arrows = pan, + = zoom in, - = zoom out
; R = reset, Esc = exit
; Run: craw mandelbrot_zoom_128.craw --tui --screen 128x128
; Q10 escape squared = 2^22
sav 1 r30
sav 22 r28
cal shl r30 r28
sav r01 r30
cal not r30 rff
cal add 1 r01
sav r01 r31
; framebuffer dimension
sav 1 r43
sav 7 r28
cal shl r43 r28
sav r01 r43
sav 6 r45 ; half-width shift
sav 5 r46 ; quarter-width shift
sav 48 r47 ; largest permitted pixel step
; reset viewport
90
sav -64 r40
sav 3 r28
cal shl r40 r28
sav r01 r40 ; center real = -512 = -0.5
sav 0 r41 ; center imaginary = 0
sav 24 r42 ; step per pixel in Q10
jmp 80
80 ; draw / redraw
io screen clear rff
sav 0 r11
sav r42 r28
sav r45 r29
cal shl r28 r29
cal not r01 rff
cal add 1 r01
cal add r41 r01
sav r01 r15 ; top imaginary
1 ; row
sav 0 r10
sav r42 r28
sav r45 r29
cal shl r28 r29
cal not r01 rff
cal add 1 r01
cal add r40 r01
sav r01 r14 ; left real
2 ; pixel
io screen x r10
io screen y r11
sav r14 r12
sav r15 r13
sav 0 r0e
sav 0 r0d
sav 0 r0f
3 ; iterate
cal add -64 r0f
jmz 41
sav r0e r02
sav r0e r03
sav 50 r05
fgo 100
50
sav r02 r20
sav r0d r02
sav r0d r03
sav 60 r05
fgo 100
60
sav r02 r21
cal add r20 r21
sav r01 r23
cal add r31 r23
jmg 40
sav r0e r02
sav r0d r03
sav 70 r05
fgo 100
70
sav r02 r22
cal not r21 rff
cal add 1 r01
cal add r20 r01
sav 10 r28
cal sar r01 r28
cal add r12 r01
sav r01 r16
sav 9 r28
cal sar r22 r28
cal add r13 r01
sav r01 r17
sav r16 r0e
sav r17 r0d
cal add 1 r0f
sav r01 r0f
jmp 3
; ocean-to-sunrise palette, signed RGB
40
cal add -2 r0f
jml 51
cal add -4 r0f
jml 52
cal add -6 r0f
jml 53
cal add -9 r0f
jml 54
cal add -13 r0f
jml 55
cal add -18 r0f
jml 56
cal add -25 r0f
jml 57
cal add -36 r0f
jml 58
cal add -49 r0f
jml 59
jmp 65
41 ; inside or unresolved
sav -128 r07
sav -128 r08
sav -128 r09
jmp 42
51 ; midnight blue
sav -124 r07
sav -112 r08
sav -68 r09
jmp 42
52 ; cobalt
sav -114 r07
sav -99 r08
sav 30 r09
jmp 42
53 ; electric blue
sav -99 r07
sav -65 r08
sav 119 r09
jmp 42
54 ; ultraviolet
sav -43 r07
sav -91 r08
sav 127 r09
jmp 42
55 ; magenta
sav 35 r07
sav -78 r08
sav 104 r09
jmp 42
56 ; coral
sav 119 r07
sav -24 r08
sav 15 r09
jmp 42
57 ; amber
sav 127 r07
sav 45 r08
sav -43 r09
jmp 42
58 ; pale gold
sav 127 r07
sav 112 r08
sav 35 r09
jmp 42
59 ; icy cyan
sav 13 r07
sav 113 r08
sav 127 r09
jmp 42
65 ; distant blue
sav -58 r07
sav 31 r08
sav 127 r09
42
io screen r r07
io screen g r08
io screen b r09
io screen pixel rff
cal add 1 r10
sav r01 r10
cal add r42 r14
sav r01 r14
cal not r43 rff
cal add 1 r01
cal add r01 r10
jml 2
cal add 1 r11
sav r01 r11
cal add r42 r15
sav r01 r15
cal not r43 rff
cal add 1 r01
cal add r01 r11
jml 1
io screen present rff
200 ; keyboard handler
sav 0 r01
io keyboard poll r01
jmz 200
sav r01 r44
cal add -27 r44
jmz 999 ; Esc
cal add -43 r44
jmz 201 ; +
cal add -61 r44
jmz 201 ; = also zooms in
cal add -45 r44
jmz 202 ; -
cal add -114 r44
jmz 90 ; r reset
cal add -82 r44
jmz 90 ; R reset
cal add 1 r44
jmz 203 ; up
cal add 2 r44
jmz 204 ; down
cal add 3 r44
jmz 205 ; left
cal add 4 r44
jmz 206 ; right
jmp 200
201 ; zoom in, centre fixed
sav 1 r28
cal sar r42 r28
jmz 200 ; cannot resolve smaller than 1/1024
sav r01 r42
jmp 80
202 ; zoom out
sav 1 r28
cal shl r42 r28
sav r01 r48
cal not r47 rff
cal add 1 r01
cal add r48 r01
jmg 200 ; larger than maximum step
sav r48 r42
jmp 80
203 ; move upward
sav r46 r28
cal shl r42 r28
cal not r01 rff
cal add 1 r01
cal add r41 r01
sav r01 r41
jmp 80
204 ; move downward
sav r46 r28
cal shl r42 r28
cal add r41 r01
sav r01 r41
jmp 80
205 ; move left
sav r46 r28
cal shl r42 r28
cal not r01 rff
cal add 1 r01
cal add r40 r01
sav r01 r40
jmp 80
206 ; move right
sav r46 r28
cal shl r42 r28
cal add r40 r01
sav r01 r40
jmp 80
999
stp
;;;;;;;;;;;;;;;;;;;;;;;;;
; Signed multiplier ;
; r02 * r03 -> r02 ;
; returns via r05 ;
;;;;;;;;;;;;;;;;;;;;;;;;;
100
sav 0 r24
sav 0 r27
sav 1 r28
sav r02 r01
ifl 101
cal not r02 rff
cal add 1 r01
sav r01 r02
sav 1 r24
rmv 101
sav r03 r01
ifl 102
cal not r03 rff
cal add 1 r01
sav r01 r03
cal xor 1 r24
sav r01 r24
rmv 102
103
sav r03 r01
jmz 104
cal and 1 r03
ifg 105
cal add r02 r27
sav r01 r27
rmv 105
cal shl r02 r28
sav r01 r02
cal shr r03 r28
sav r01 r03
jmp 103
104
sav r27 r02
sav r24 r01
ifg 106
cal not r02 rff
cal add 1 r01
sav r01 r02
rmv 106
sav r05 r01
fgo 0
Output
The viewer allows the user to navigate and magnify the Mandelbrot set. The maximum useful magnification is limited by the precision of the fixed-point representation used for complex coordinates. Beyond this limit, neighbouring pixels can no longer be assigned distinct coordinates.



