From 64fe9c50d7c78a1a5b4b0b5d22612a2225c3a3c8 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Tue, 22 Jun 2021 07:56:43 +0100 Subject: Update publish arm64 hello world --- md/writeup.md | 2 ++ md/writeup/arm64_assembly_hello_world.md | 51 ++++++++++++++++---------------- 2 files changed, 27 insertions(+), 26 deletions(-) (limited to 'md') diff --git a/md/writeup.md b/md/writeup.md index a112bd7..39aa8b1 100644 --- a/md/writeup.md +++ b/md/writeup.md @@ -30,6 +30,7 @@ title: Writeup page [Running disk images in QEMU](writeup/running_disk_images_in_qemu.md) [Mqueue IPC example](writeup/mqueue_ipc_example.md) [Swift OCR example](writeup/swift_ocr_example.md) +[ARM64 assembly hello world](writeup/arm64_assembly_hello_world.md) @@ -96,6 +97,7 @@ title: Writeup page [Sauerbraten patching and cheating](writeup/sauerbraten_patching_and_cheating.md) [Scan memory for variable](writeup/scan_memory_for_variable.md) + ### Archive OpenWRT [Building OpenWRT for RTL8196C](writeup/building_openwrt_for_rtl8196c.md) [RTL8196C support for OpenWRT](writeup/rtl8196c_support_for_openwrt.md) 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 -- cgit v1.2.3