0

Suppose I've an 3-element array in NASM

strings: dw 0x00, 0x00, 0x00

, that I want to fill with addresses of strings, also defined within the .data section, e.g.,

hello_word: db "HelloWorld!", 0.

Writing strings: dw hello_world, 0x00, 0x00 is a syntax error.

How do I populate an array with addresses, so that I can loop over it at runtime, each time incrementing the index?

3 Answers 3

1

Ah, "-f coff"! Make your addresses dd not dw.

Sign up to request clarification or add additional context in comments.

Comments

1

this worked for me:

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 00 and 00 11 are the two pointers to the strings

3 Comments

Weird, I get output: base.asm:30: error: COFF format does not support non-32-bit relocations base.asm:31: error: COFF format does not support non-32-bit relocations
sounds like you try to store 32bit adresses in 16bit values. what OS are you using?
Exactly, that was my problem... Thank you. I use Windows 10.
1

You could also load the effective addresses of the strings at runtime using the LEA instruction (x86):

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

But, probably, Frank Kotler's approach is better.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.