-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelloWorld_manual.msm
89 lines (73 loc) · 1.41 KB
/
HelloWorld_manual.msm
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;; Advanced Hallo-World example, involving basic memory operations
%include "../msmlib/stdlib.mlb"
; Define SPACE ascii code
%define SPACE 32
jmp main ; Skip function definitions
write_mem:
push 0 ; I
swap 1
write_mem_loop:
; Writing one char to the memory at I
swap 1
dup 0
dup 3
write8
; Incrementing the I
push 1
plusi
; Checking if next char is 0
swap 2
push 0
equal
not
; jmp if next char is not 0
; else return
jmpif write_mem_loop
ret
print_mem:
; Given: I
swap 1 ; Swap return addr to the bottom of the stack
print_mem_loop:
; Reading and printing char from I
dup 0
read8
int print_char
; Zeroing memory at I
dup 0
push 0
write8
; Decrement I
push 1
minusi
; Checking if I equal to -1
push -1
dup 1
equal
not
; jmp if I is not -1
; else return
jmpif print_mem_loop
drop ; cleanup I
ret
; Main label
main:
; Pushing 0 terminated str in reverse order as ascii codes to the stack.
push 0 ; null terminate
push 72 ; H
push 101 ; e
push 108 ; l
push 108 ; l
push 111 ; o
push SPACE
push 87 ; W
push 111 ; o
push 114 ; r
push 108 ; l
push 100 ; d
push 33 ; !
push NL
; Writing the str to the memory
call write_mem
; Printing
call print_mem
hlt