I am unable to open and then read a simple text file using the arm64 syscalls. I am new to arm assembler programing and not an experienced programmer.
My environment is using Termux shell on an android phone and compiling using GAS as and ld.
I am attempting to open and existing file and read the text contents to a buffer, Then display the buffer as confirmation. The buffer always appears empty.
The code I am using is:
filename: .ascii "test.txt" // my existing test file
path: .ascii "../gas" // the path where my file lives
err: .ascii "error\n" // error message if file handle is zero
buffer: .space 100
// open the existing file for reading
mov x2,#3 // read and write access ???
mov x3,#0666 // mode or permissions??
mov w8,#56 // NR for openat
svc 0 // x0 is now supposed to have the disk handle
cbz x0,handle_error // branch to error message if handle is zero
mov x19,x0 // tuck the handle value in x19
// now read the existing text file
mov x0,x19 // restore the handle
ldr x1,=buffer // location for the file text
mov x2,#10 // only read 10 bytes as a test
mov w8,#63 // NR for read
svc 0 // the buffer should now have the file text
// close the file
mov w8,#57 // NR for file close
// display the buffer for confirmation
mov x2,#10 // only 10 bytes
// terminate program
If you are working on an Android phone as the development environment, the generated executable of your assembly code will run as the Android/Linux user space application. If the phone is not rooted, your executable may not have the necessary execution permissions.