https://github.com/akkartik/mu/blob/master/apps/raytracing/2.mu
1
2
3
4
5
6
7
8
9 fn main -> _/ebx: int {
10 print-string 0, "P3\n256 256\n255\n"
11 var _four/edx: int <- copy 4
12 var four/xmm1: float <- convert _four
13 var one-fourth/xmm1: float <- reciprocal four
14 var max/edx: int <- copy 0xff
15 var image-size/xmm2: float <- convert max
16 var j/ecx: int <- copy 0xff
17 {
18 compare j, 0
19 break-if-<
20 var i/eax: int <- copy 0
21 {
22 compare i, 0xff
23 break-if->
24 var c: rgb
25
26 var tmp/xmm0: float <- convert i
27 tmp <- divide image-size
28 var r-addr/edx: (addr float) <- get c, r
29 copy-to *r-addr, tmp
30
31
32
33
34 tmp <- convert j
35 tmp <- divide image-size
36 var g-addr/edx: (addr float) <- get c, g
37 copy-to *g-addr, tmp
38
39 var b-addr/edx: (addr float) <- get c, b
40 copy-to *b-addr, one-fourth
41
42 var c-addr/edx: (addr rgb) <- address c
43 print-rgb 0, c-addr
44 i <- increment
45 loop
46 }
47 j <- decrement
48 loop
49 }
50 return 0
51 }
52
53 type rgb {
54
55 r: float
56 g: float
57 b: float
58 }
59
60
61 fn print-rgb screen: (addr screen), _c: (addr rgb) {
62 var c/esi: (addr rgb) <- copy _c
63 var n/ecx: int <- copy 0xff
64 var xn/xmm1: float <- convert n
65
66 var result/xmm0: float <- copy xn
67 var src-addr/eax: (addr float) <- get c, r
68 result <- multiply *src-addr
69 var result-int/edx: int <- convert result
70 print-int32-decimal screen, result-int
71 print-string screen, " "
72
73 src-addr <- get c, g
74 result <- copy xn
75 result <- multiply *src-addr
76 result-int <- convert result
77 print-int32-decimal screen, result-int
78 print-string screen, " "
79
80 src-addr <- get c, b
81 result <- copy xn
82 result <- multiply *src-addr
83 result-int <- convert result
84 print-int32-decimal screen, result-int
85 print-string screen, "\n"
86 }