Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 尝试显示字符串的代码中出现错误_Linux_String_Macros_Nasm_32 Bit - Fatal编程技术网

Linux 尝试显示字符串的代码中出现错误

Linux 尝试显示字符串的代码中出现错误,linux,string,macros,nasm,32-bit,Linux,String,Macros,Nasm,32 Bit,我正在编写一个nasm程序,它使用预处理器的指令和宏简单地打印字符串。代码如下: %define hello "Hello, world!" %strlen size_h hello %macro print 2 mov eax, 4 mov ebx, 1 mov ecx, %1 mov edx, %2 int 80h %endmacro section .text global _start _start: print hello, size_h mov ea

我正在编写一个nasm程序,它使用预处理器的指令和宏简单地打印字符串。代码如下:

%define hello "Hello, world!"
%strlen size_h hello

%macro print 2
  mov eax, 4
  mov ebx, 1
  mov ecx, %1
  mov edx, %2
  int 80h
%endmacro

section .text
global _start

_start:
  print hello, size_h
  mov eax, 1
  mov ebx, 0
  int 80h ;exit
我正在使用ld链接器

它向我显示了两个警告:

character constant too long
dword data exceeds bounds

如何更正此问题?

宏只是替换字符串。所以,
print hello,size\u h
将变成

mov eax, 4
mov ebx, 1
mov ecx, "Hello World!"
mov edx, 13
int 80h
你看,你试图用一个字符串加载
ECX
,因为
int80h/EAX=4
需要一个地址。首先必须存储字符串,然后才能加载带有地址的
ECX
。NASM不会为你这么做的

以下宏将文本存储在
.text
部分(您不能在此处更改):

此宏切换到
.data
部分并返回到
.text

%macro print 2
    section .data
    %%string: db %1
    section .text
    mov eax, 4
    mov ebx, 1
    mov ecx, %%string
    mov edx, %2
    int 80h
%endmacro
%macro print 2
    section .data
    %%string: db %1
    section .text
    mov eax, 4
    mov ebx, 1
    mov ecx, %%string
    mov edx, %2
    int 80h
%endmacro