Source Code: hello.s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
        .data
.L0     .string "hello\n"


        .text
        .equ    SP,         1
        loadz   0,          %SP

        call    main,       %2
        halt    0

// function foo
foo:
        subq    8,          %SP,        %SP
        movq    %2,         (%SP)
        // begin of function body

        .equ    p,          2
        .equ    ch,         3
        loadz   .L0,        %p
.while:
        movzbq  (%p),       %ch
        subq    0,          %ch,        %ch
        jz      .done
        putc    %ch
        addq    1,          %p,         %p
        jmp     .while
.done:

        // end of function body
        movq    (%SP),      %2
        addq    8,          %SP,        %SP
        ret     %2

// function main
main:
        subq    8,          %SP,        %SP
        movq    %2,         (%SP)
        // begin of function body

        call    foo,        %2

        // end of function body
        movq    (%SP),      %2
        addq    8,          %SP,        %SP
        ret     %2