[英]How do I write to files in ARM assembly?
I am learning ARM assembly on my raspberry pi, and I am trying to write to a file called "user_data.txt".我正在我的树莓派上学习 ARM 程序集,我正在尝试写入一个名为“user_data.txt”的文件。 I do know how to create a file, like so...
我确实知道如何创建文件,就像这样......
.data
.balign 1
file_name: .asciz "user_data.txt"
.text
.global _start
_start:
MOV R7, #8
LDR R0, =file_name
MOV R1, #0777
SWI 0
_end:
MOV R7, #1
SWI #0
...but, as I said, I can't figure out how I would write to this file. ...但是,正如我所说,我不知道如何写入该文件。 I have looked at other tutorials, but none that I looked at explain what each line does.
我看过其他教程,但我看过的都没有解释每一行的作用。 I understand that I would move 4 into R7, in order to call the sys_write system call, but how would I tell ARM the file name I want to write to?
我知道我会将 4 移到 R7 中,以便调用 sys_write 系统调用,但是我如何告诉 ARM 我要写入的文件名?
Can anyone give some code which clearly shows and explains some ARM that writes to a file?谁能给出一些代码来清楚地显示和解释一些写入文件的 ARM 吗?
Thanks,谢谢,
So you wanted code:所以你想要代码:
.data
.balign 1
file_name: .asciz "user_data.txt"
.text
.global _start
_start:
MOV R7, #8
LDR R0, =file_name
MOV R1, #0777
SWI 0
MOV R7, #4 ;write(int fd, void* buf, int len)
LDR R1, =file_name ;buf
MOV R2, #9 ;len
SWI 0
MOV R7, #6 ;close(int fd)
SWI 0
_end:
MOV R7, #1
SWI #0
This will (for simplicity) write 9 chars of file_name (user_data) into the file and close it.这将(为简单起见)将文件名(user_data)的 9 个字符写入文件并关闭它。 Note that R0 always holds fd.
请注意,R0 始终保持 fd。
The manpages ( https://linux.die.net/man/2/creat , https://linux.die.net/man/2/write ) and this table ( https://syscalls.w3challs.com/?arch=arm_thumb ) are useful resources I often consult.手册页 ( https://linux.die.net/man/2/creat , https://linux.die.net/man/2/write ) 和这个表 ( Z5E056C500A1C3challs875.com/?B50D807BADE5Z://linux.die.net/man/2/write ) arch=arm_thumb )是我经常查阅的有用资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.