-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasmhello.S
More file actions
62 lines (53 loc) · 1.25 KB
/
asmhello.S
File metadata and controls
62 lines (53 loc) · 1.25 KB
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
/**
* Basic ARM Unified Assembly Language sample which runs on Neotron OS.
*/
.syntax unified
//
// Functions (.text)
//
.text
// Entry point for our application.
//
// * r0 will contain a pointer to the syscall table.
// * The write function is the third entry (offset 8)
// and takes the arguments r0=handle, r1=pointer, r2=length
.thumb_func
.global app_entry
.func app_entry
app_entry:
// "A subroutine must preserve the contents of the registers r4-r11
// and SP" - and we only use R4
push {r4, lr}
// Fetch write function address
ldr r3, [r0, #8]
// Set up file handle
movs r0, #1
// Get address of string
ldr r1, =message
// Get address of data length
ldr r4, =message_len
// Read data length (might not be aligned, as it follows the string, so only
// read one byte)
ldrb r2, [r4]
// Call write function
blx r3
// Set return value
movs r0, #0
// Exit
pop {r4, pc}
.endfunc
//
// Read Only Data (.rodata)
//
.section .rodata
// The message we want to print
.type message,%object
message:
.ascii "Hello world!\n"
// The length of the string with the label `message`
//
// Must come immediately after `message:`
.type message_len,%object
message_len:
.byte . - message
// End of file