https://github.com/akkartik/mu/blob/main/101screen.subx
 1 # Primitives for screen control.
 2 #
 3 # We need to do this in machine code because Mu doesn't have global variables
 4 # yet (for the start of video memory).
 5 
 6 == code
 7 
 8 pixel-on-real-screen:  # x: int, y: int, color: int
 9     # . prologue
10     55/push-ebp
11     89/<- %ebp 4/r32/esp
12     #
13     (pixel-on-screen-buffer *Video-memory-addr *(ebp+8) *(ebp+0xc) *(ebp+0x10) 0x400 0x300)
14 $pixel-on-real-screen:end:
15     # . epilogue
16     89/<- %esp 5/r32/ebp
17     5d/pop-to-ebp
18     c3/return
19 
20 # 'buffer' here is not a valid Mu type: a naked address without a length.
21 pixel-on-screen-buffer:  # buffer: (addr byte), x: int, y: int, color: int, width: int, height: int
22     # . prologue
23     55/push-ebp
24     89/<- %ebp 4/r32/esp
25     # . save registers
26     50/push-eax
27     51/push-ecx
28     # bounds checks
29     8b/-> *(ebp+0xc) 0/r32/eax  # foo
30     3d/compare-eax-and 0/imm32
31     7c/jump-if-< $pixel-on-screen-buffer:end/disp8
32     3b/compare 0/r32/eax *(ebp+0x18)
33     7d/jump-if->= $pixel-on-screen-buffer:end/disp8
34     8b/-> *(ebp+0x10) 0/r32/eax
35     3d/compare-eax-and 0/imm32
36     7c/jump-if-< $pixel-on-screen-buffer:end/disp8
37     3b/compare 0/r32/eax *(ebp+0x1c)
38     7d/jump-if->= $pixel-on-screen-buffer:end/disp8
39     # eax = y*width + x
40     8b/-> *(ebp+0x10) 0/r32/eax
41     0f af/multiply-> *(ebp+0x18) 0/r32/eax
42     03/add-> *(ebp+0xc) 0/r32/eax
43     # eax += location of frame buffer
44     03/add-> *(ebp+8) 0/r32/eax
45     # *eax = color
46     8b/-> *(ebp+0x14) 1/r32/ecx
47     88/byte<- *eax 1/r32/CL
48 $pixel-on-screen-buffer:end:
49     # . restore registers
50     59/pop-to-ecx
51     58/pop-to-eax
52     # . epilogue
53     89/<- %esp 5/r32/ebp
54     5d/pop-to-ebp
55     c3/return