0

can't open a file ("filename.gray") in assembly Risc v, assume that the path to the file, either being absolute or relative is correct (i'm not having issues with null terminated strings) long story short , i have a snippet of code :

li a7, 1024 la a0, filename # filename is store in a variable called filename in the data store segment as an .asciz value of "name.gray" li a1, 0 ecall mv s0, a0 # retrieve file pointer

I tried booting the code in linux, i tried changing the system file permissions to read and write to all users, i tried creating fresh directories to check if that was the issue, tried changing the path and names to reduce typing errors or wrong directories. i tried typing a fopen system call in all different sorts and ways but from what i know (fopen syscall gets 2 inputs resumed -> a0 : filename ; a1 -> filemode : 0 for rb and 1 for wb ; and of course the li a7, 1024 to do the instruction

i also made the entire program in C and it runs just fine : snippet : unsigned char* read_image(const char* filename, int width, int height) {

FILE *file = fopen(filename, "rb");
unsigned char* image = (unsigned char*)malloc(width * height); 
4
  • Are you using RARS? Commented Jun 1, 2024 at 17:02
  • yes, i am using RARS 1.6 @ErikEidt Commented Jun 1, 2024 at 17:57
  • Ok, sometimes the file has to go in the same folder as the rars.jar file. Another thing to try is to create some file using RARS ecalls and see where it winds up. Commented Jun 1, 2024 at 18:08
  • Lastly, if you launch rars.jar using a command line batch file (e.g. containing command java -jar C:\...rars1_6.jar for windows), you can set the working directory as you like, while using an (absolute) path to the .jar file. Commented Jun 2, 2024 at 15:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.