【发布时间】:2023-03-21 10:00:01
【问题描述】:
这个问题主要是如何处理任意长字符串的路径名,在汇编中,没有db 或任何类似的助手。我见过几个例子,例如this,它显示:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
;create the file
mov eax, 8
mov ebx, file_name
mov ecx, 0777 ;read, write and execute by all
int 0x80 ;call kernel
section .data
file_name db 'myfile.txt'
但是,我特别想了解如何动态地进行此操作。我想(1)更好地理解文件名在汇编方面的要求(是否需要空终止符等),更重要的是(2)指定文件名不使用 db 或任何汇编程序助手。例如,您可以通过命令行指定文件名,目标文件将不知道其结构。
你是怎么做到的?
【问题讨论】:
-
(1) 是的,字符串需要一个空终止符 (2) 与创建文件无关,更多的是与访问参数有关。
-
与文件名无关,但您的文件模式错误,因为
0前缀并不意味着 nasm 的八进制。请参阅How to represent octal numbers in Assembly? 了解正确的做法。
标签: linux assembly x86 system-calls