We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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:
.data
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
.bss
buffer: .space 100
.text
.global _start
_start:
// open the existing file for reading
ldr x0,=path
ldr X1,=filename
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 x0,x19
mov w8,#57 // NR for file close
svc 0
// display the buffer for confirmation
mov x0,#1
ldr x1,=buffer
mov x2,#10 // only 10 bytes
mov w8,#64
// terminate program
mov x0,#0
mov w8,#93
handle_error:
ldr x1,=err
mov x2,#6