Implement the named labels for assembly
JavaScript (ES6), 96 bytes
Uses @label for a declaration and %label for a reference.

s=&gt;s.replace(o=/^\s*@(.+)/gm,(_,s)=&gt;':'+(o[s]=++n),n=0).replace(/&quot;.*?&quot;|%(\w+)/g,(s,x)=&gt;x?o[x]:s)

Try it online!
Commented
(alternate slash characters are used below to prevent the SE syntax highligter from going mad)
s =&gt;                  // s = input string
  s.replace(          // 1st pass:
    o =               //   assign the regex object to o; we'll use it to store the labels
    ∕^\s*@(.+)∕gm,    //   look for [start] + [optional whitespace] + '@' + [label]
    (_, s) =&gt;         //   replace with:
      ':' +           //     ':' + label ID
      (o[s] = ++n),   //     increment n and store the label in o
    n = 0             //   start with n = 0
  )                   // end of replace()
  .replace(           // 2nd pass:
    ∕&quot;.*?&quot;|%(\w+)∕g,  //   look for either &quot;.*?&quot; (non-greedily) or %label
    (s, x) =&gt;         //   replace with:
      x ? o[x]        //     o[label] if x is defined,
        : s           //     or the original string otherwise
  )                   // end of replace()