https://github.com/akkartik/mu/blob/master/subx/037heap.cc
 1 //: Support for dynamic allocation.
 2 //:
 3 //: Just provide a special label marking the first unused address in the data
 4 //: segment. Then we'll write SubX helpers to make use of it.
 5 
 6 :(before "Begin rewrite_global_variables")
 7 insert_heap_global_variable(p);
 8 :(code)
 9 void insert_heap_global_variable(program& p) {
10   if (SIZE(p.segments) < 2)
11     return;  // no data segment defined
12   // Start-of-heap:
13   p.segments.at(1).lines.push_back(label("Start-of-heap"));
14 }
15 
16 line label(string s) {
17   line result;
18   result.words.push_back(word());
19   result.words.back().data = (s+":");
20   return result;
21 }
22 
23 line imm32(const string& s) {
24   line result;
25   result.words.push_back(word());
26   result.words.back().data = s;
27   result.words.back().metadata.push_back("imm32");
28   return result;
29 }