1

Thanks for taking the time to read this.

I'm atempting to create a text file using ARM Assembly.

I have found various tutorials on how to acheive this in x86 (see here) but as of yet have been unable to find any information on how to do this with the ARM instruction set.

foaf
  • 121
  • 1
  • 2
  • 8
  • Why don't you write it in c and compile to ARM? – Leeor Nov 20 '14 at 19:32
  • Which operating system? There are no instructions in the ARM instruction set alone that can open or create files. I would imagine most OSs have `SWI`s that you can use for this purpose, but exactly which SWIs you call and with what register values depends entirely on the OS. – Luke Woodward Nov 20 '14 at 19:49
  • Hi Leeor, thanks for replying. Compiling C to ARM is not something i'm familiar with - to date all I have done is write my assembly directly in Notepad++. That said, I would not be opposed to using this method to see what instructions the C is compiled to for this situation. Could you recommend some material to get me started on compiling C to ARM? – foaf Nov 20 '14 at 19:51
  • Hi Luke, I'm not using an operating system. I am executing my assembly directly on a pi by having my instructions in the kernel.img, similar to the method used here in [BakingPi](http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html) – foaf Nov 20 '14 at 19:56
  • 2
    Without an operating system, you're going to be writing a whole heap of code to talk to whatever device your files are stored on, and a whole other heap of code to interpret the raw bytes off that device as a filesystem. In other words, a significant chunk of an operating system. The x86 tutorial you linked is about making _MS-DOS system calls_ from assembly - with all the code in the PC BIOS and DOS itself that's a _long_ way from bare-metal. – Notlikethat Nov 20 '14 at 20:27

1 Answers1

1

The x86 code you reference relies on a BIOS being available to perform this task for you. Your ARM environment contains no BIOS, so without an operating system you are simply out of luck.

See This Question for a little but more information about what your x86 example actually does.

Another Question is a more descriptive one of the work you need to do to achieve what you ask, once you are within an operating system. It also has an answer with some links in it.

Community
  • 1
  • 1
unixsmurf
  • 5,852
  • 1
  • 33
  • 40
  • Thanks for the reply unixsmurf. It makes sense that I would need an underlying filesystem/BIOS. I dont know why that didn't occur to me. I'm happy to mark this as the answer. As a follow up question, though, I mentioned i've been writing assembly and executing it directly on a Pi without an operating system installed. An alternative solution would be to run my assembly inside an OS environment, say from the terminal in Raspbian. Do you know if this is possible? – foaf Nov 20 '14 at 20:43
  • 1
    Absolutely - the only restriction is that if you write a userspace program, you will not have access to privileged instructions/operations. If that becomes a problem, you can always turn your code into a kernel module. http://peterdn.com/post/e28098Hello-World!e28099-in-ARM-assembly.aspx is a short example, but you can also just create a main function in assembly, and make use of the system C library to simplify things. – unixsmurf Nov 20 '14 at 20:48
  • Hi @unixsmurf - sorry to dig this thread back up but i am revisiting this problem. ive asked a smiliar question here (http://stackoverflow.com/questions/28817574/write-to-file-in-arm-assembly), could you maybe take a look if you have a chance? – foaf Mar 02 '15 at 19:12