diff options
author | FreeArtMan <dos21h@gmail.com> | 2021-06-22 07:56:43 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2021-06-22 07:56:43 +0100 |
commit | 64fe9c50d7c78a1a5b4b0b5d22612a2225c3a3c8 (patch) | |
tree | d940d34460f1b4d97f0cfbd22ef2729e39ab3571 /md/writeup | |
parent | 495c13b6993d5e7efdf5180a9e3de07c1f0c7fe8 (diff) | |
download | md-content-64fe9c50d7c78a1a5b4b0b5d22612a2225c3a3c8.tar.gz md-content-64fe9c50d7c78a1a5b4b0b5d22612a2225c3a3c8.zip |
Update publish arm64 hello world
Diffstat (limited to 'md/writeup')
-rw-r--r-- | md/writeup/arm64_assembly_hello_world.md | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/md/writeup/arm64_assembly_hello_world.md b/md/writeup/arm64_assembly_hello_world.md index 5601b89..f3bc452 100644 --- a/md/writeup/arm64_assembly_hello_world.md +++ b/md/writeup/arm64_assembly_hello_world.md @@ -10,7 +10,7 @@ is how to compile hello world for raspberry pi 4, as its supports ARMv8 instruction set. Second example is how to run assembly on Apple M1 chip that also supports ARMv8 instruction set -Two assembly examples are equivalent to C code +The two assembly examples are equivalent to C code ```c int main() { @@ -29,7 +29,7 @@ os run command uname ``` -Architecture shown as aarch64 good enoughs to indicate that os ir 64bit +Architecture shown as aarch64 enoughs to indicate that os ir 64bit ``` Linux raspberrypi 5.4.42-v8+ #1319 SMP PREEMPT Wed May 20 14:18:56 BST 2020 aarch64 GNU/Linux ``` @@ -39,9 +39,9 @@ Linux raspberrypi 5.4.42-v8+ #1319 SMP PREEMPT Wed May 20 14:18:56 BST 2020 aarc .data /* Data segment: define our message string and calculate its length. */ -msg: +helloworld: .ascii "Hello, ARM64!\n" -len = . - msg +helloworld_len = . - helloworld .text @@ -49,21 +49,21 @@ len = . - msg .globl _start _start: /* syscall write(int fd, const void *buf, size_t count) */ - mov x0, #1 /* fd := STDOUT_FILENO */ - ldr x1, =msg /* buf := msg */ - ldr x2, =len /* count := len */ - mov w8, #64 /* write is syscall #64 */ - svc #0 /* invoke syscall */ + mov x0, #1 /* fd := STDOUT_FILENO */ + ldr x1, =helloworld /* buf := msg */ + ldr x2, =helloworld_len /* count := len */ + mov w8, #64 /* write is syscall #64 */ + svc #0 /* invoke syscall */ /* syscall exit(int status) */ - mov x0, #0 /* status := 0 */ - mov w8, #93 /* exit is syscall #1 */ - svc #0 /* invoke syscall */ + mov x0, #0 /* status := 0 */ + mov w8, #93 /* exit is syscall #1 */ + svc #0 /* invoke syscall */ ``` ### Compile -Too compile check if there is installed gnu gcc, other compilers such as clang also +Too compile check if you have installed gnu gcc, other compilers such as clang also should work perfectly fine. ```makefile @@ -78,24 +78,23 @@ should work perfectly fine. ```asm .global _start // Provide program starting address to linker -.align 2 // Make sure everything is aligned properly +.align 2 // Make sure everything is aligned properly -// Setup the parameters to print hello world -// and then call the Kernel to do it. +/* syscall write(int fd, const void *buf, size_t count) */ _start: - mov X0, #1 // 1 = StdOut + mov X0, #1 // 1 = StdOut adr X1, helloworld // string to print - mov X2, #13 // length of our string - mov X16, #4 // Unix write system call - svc #0x80 // Call kernel to output the string + mov X2, helloworld_len // length of our string + mov X16, #4 // Unix write system call + svc #0x80 // Call kernel to output the string -// Setup the parameters to exit the program -// and then call the kernel to do it. - mov X0, #0 // Use 0 return code - mov X16, #1 // System call number 1 terminates this program - svc #0x80 // Call kernel to terminate the program +/* syscall exit(int status) */ + mov X0, #0 // Use 0 return code + mov X16, #1 // System call number 1 terminates this program + svc #0x80 // Call kernel to terminate the program -helloworld: .ascii "Hello World!\n" +helloworld: .ascii "Hello, ARM64!\n" +helloworld_len = . - helloworld ``` ### Compile |