https://github.com/akkartik/mu/blob/main/shell/int-stack.mu

     1 type int-stack {
     2   data: (handle array int)
     3   top: int
     4 }
     5
     6 fn initialize-int-stack _self: (addr int-stack), n: int {
     7   var self/esi: (addr int-stack) <- copy _self
     8   var d/edi: (addr handle array int) <- get self, data
     9   populate d, n
    10   var top/eax: (addr int) <- get self, top
    11   copy-to *top, 0
    12 }
    13
    14 fn push-int-stack _self: (addr int-stack), _val: int {
    15   var self/esi: (addr int-stack) <- copy _self
    16   var top-addr/ecx: (addr int) <- get self, top
    17   var data-ah/edx: (addr handle array int) <- get self, data
    18   var data/eax: (addr array int) <- lookup *data-ah
    19   var top/edx: int <- copy *top-addr
    20   var dest-addr/edx: (addr int) <- index data, top
    21   var val/eax: int <- copy _val
    22   copy-to *dest-addr, val
    23   add-to *top-addr, 1
    24 }
    25
    26 fn pop-int-stack _self: (addr int-stack) -> _/eax: int {
    27   var self/esi: (addr int-stack) <- copy _self
    28   var top-addr/ecx: (addr int) <- get self, top
    29   {
    30     compare *top-addr, 0
    31     break-if->
    32     return 0
    33   }
    34   subtract-from *top-addr, 1
    35   var data-ah/edx: (addr handle array int) <- get self, data
    36   var data/eax: (addr array int) <- lookup *data-ah
    37   var top/edx: int <- copy *top-addr
    38   var result-addr/eax: (addr int) <- index data, top
    39   var val/eax: int <- copy *result-addr
    40   return val
    41 }
    42
    43 fn int-stack-empty? _self: (addr int-stack) -> _/eax: boolean {
    44   var self/esi: (addr int-stack) <- copy _self
    45   var top-addr/ecx: (addr int) <- get self, top
    46   compare *top-addr, 0
    47   {
    48     break-if-=
    49     return 0/false
    50   }
    51   return 1/true
    52 }
    53
    54 fn int-stack-top _self: (addr int-stack) -> _/eax: int {
    55   var self/esi: (addr int-stack) <- copy _self
    56   var top-addr/ecx: (addr int) <- get self, top
    57   var top/ecx: int <- copy *top-addr
    58   {
    59     compare top, 0
    60     break-if->
    61     return 0
    62   }
    63   top <- decrement
    64   var data-ah/edx: (addr handle array int) <- get self, data
    65   var data/eax: (addr array int) <- lookup *data-ah
    66   var result-addr/eax: (addr int) <- index data, top
    67   var val/eax: int <- copy *result-addr
    68   return val
    69 }