Stack Muster

Reading time ~1 minute

Stack Framework in C

Siehe Veranstaltungsseite

Stack in NASM

global init
global push
global pop
global top
global isEmpty

section .data
c       dq      0x0     ; current element address

section .bss
mem     resq    10      ; memory for stack

section .text
init:
    mov rax     , mem
    mov [c]     , rax
    ret
push:
    mov r8      , [c]
    mov [r8]    , rdi
    add qword[c], 8
    ret
pop:
    sub qword[c], 0x8
    mov r8      , [c]
    mov rax     , [r8]
    ret
top:
    sub qword[c], 0x8
    mov r8      , [c]
    mov rax     , [r8]
    add qword[c], 0x8
    ret
isEmpty:
    mov r8      , mem
    cmp r8      , [c]
    je  empty
    xor rax     , rax
    ret
empty:
    mov rax     , 1
    ret