https://github.com/akkartik/mu/blob/main/315stack-debug.subx
1
2
3 == code
4
5 check-stack:
6
7 55/push-ebp
8 89/<- %ebp 4/r32/esp
9
10 50/push-eax
11
12 89/<- %eax 4/r32/esp
13 81 7/subop/compare %eax 0x48600/imm32
14 {
15 7f/jump-if-> break/disp8
16 (abort "stack overflow")
17 }
18 $check-stack:end:
19
20 58/pop-to-eax
21
22 89/<- %esp 5/r32/ebp
23 5d/pop-to-ebp
24 c3/return
25
26 show-stack-state:
27
28 55/push-ebp
29 89/<- %ebp 4/r32/esp
30
31 50/push-eax
32 51/push-ecx
33 52/push-edx
34
35 89/<- %edx 4/r32/esp
36
37 (cursor-position 0)
38
39 (set-cursor-position 0 0x70 0)
40 (draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0 %edx 0xf 0xc)
41
42 (set-cursor-position %eax %ecx)
43 $check-stack:end:
44
45 5a/pop-to-edx
46 59/pop-to-ecx
47 58/pop-to-eax
48
49 89/<- %esp 5/r32/ebp
50 5d/pop-to-ebp
51 c3/return
52
53
54
55
56 debug-print:
57
58 55/push-ebp
59 89/<- %ebp 4/r32/esp
60
61 {
62 81 7/subop/compare *Really-debug-print 0/imm32/false
63 74/jump-if-= break/disp8
64 (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+8) *(ebp+0xc) *(ebp+0x10))
65 }
66 $debug-print:end:
67
68 89/<- %esp 5/r32/ebp
69 5d/pop-to-ebp
70 c3/return
71
72 == data
73 Really-debug-print:
74 0/imm32/false