This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unable to open disk file for reading using arm64 system calls and assembler

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

svc 0

// terminate program

mov x0,#0

mov w8,#93

svc 0

handle_error:

mov x0,#1

ldr x1,=err

mov x2,#6

mov w8,#64

svc 0

mov x0,#0

mov w8,#93

svc 0

Parents
  • 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.

Reply
  • 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.

Children
No data