forked from mountainstorm/Subleq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello-world.slq
66 lines (53 loc) · 962 Bytes
/
hello-world.slq
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
;
; hello-world.slq
; subleq
;
; Created by R J Cooper on 10/09/2011.
; Copyright 2011 Mountainstorm. All rights reserved.
;
; a basic test of the assembler/machine but with some basic
; processor features added e.g registers
;
; it will derive the address of printf, then call it to
; print "Hello World"
;
jmp main
.fill 1024
stack:
main:
; setup sp
mov .offset stack, sp
;
; find printf - dysym(RTLD_DEFAULT, "printf")
;
; push real address of "printf"
mov .offset printfStr, r0
add bar, r0
push r0
; push RTLD_DEFAULT
push -2
; push address and call out to it
push dlsym
callc
mov [sp], printf
; reset sp
mov .offset stack, sp
;
; call printf - printf("Hello World")
;
; push helloStr
mov .offset helloStr, r0
add bar, r0
push r0
; push address and call out to it
push printf
callc
halt
Z: .int 0
r0: .int 0
sp: .int 0
bar: .int 0
dlsym: .int 0
printf: .int 0
helloStr: .ascii "Hello World"
printfStr: .ascii "printf"