在 NASM 中创建字符串地址(数据元素)数组?

Create array of string addresses (data elements) in NASM?

假设我在 NASM

中有一个 3 元素数组

strings: dw 0x00, 0x00, 0x00

,我想用字符串地址填充,也在 .data 部分中定义,例如

hello_word: db "HelloWorld!", 0.

strings: dw hello_world, 0x00, 0x00 是一个语法错误。

如何用地址填充数组,以便我可以在运行时遍历它,每次递增索引?

这对我有用:

segment data
 prompt_msg db "Input a string: ",0
 output_msg db "The reverse is: ",0

 stringPtr dw prompt_msg
           dw output_msg

 -->

0734:0100  49 6E 70 75 74 20 61 20-73 74 72 69 6E 67 3A 20 Input a string:
0734:0110  00 54 68 65 20 72 65 76-65 72 73 65 20 69 73 3A .The reverse is:
0734:0120  20 00 00 00 11

at 0x121: 00 0000 11 是指向字符串

的两个指针

啊,“-f coff”!使您的地址 dd 而不是 dw.

您还可以使用 LEA 指令 (x86) 在运行时加载字符串的有效地址:

lea eax, [_str1]
mov [_s_table], eax
lea eax, [_str2]
mov [_s_table + 0x04], eax
lea eax, [_str3]
mov [_s_table + 0x08], eax

但是,弗兰克科特勒的方法可能更好。