Hi, i'm currently learning assembly with the nasm assembler and i'm stuck trying to get a memory address into a register. Here is what I have:

[bits 32]
[org 100h]

section .data
msg db "Hello", 0

section .text
mov si, [msg]
;lea si, [msg]

ret

I read the nasm manual and it appear that both instructions should work but they don't. With lea si stays at 0, with mov si gets the wrong address What exactly am I doing wrong here??

Hi, i'm currently learning assembly with the nasm assembler and i'm stuck trying to get a memory address into a register. Here is what I have:

[bits 32]
[org 100h]
 
section .data
msg db "Hello", 0
 
section .text
mov si, [msg]
;lea si, [msg]
 
ret

I read the nasm manual and it appear that both instructions should work but they don't. With lea si stays at 0, with mov si gets the wrong address What exactly am I doing wrong here??

use mov si,msg
to get address of msg into si.
[msg] refers to the content of msg not its address.

the indirect address '[msg] and not the content of the array called 'msg' should be what goes into si. What's there instead? Whatcha doing this for?

the indirect address '[msg] and not the content of the array called 'msg' should be what goes into si. What's there instead? Whatcha doing this for?

It looks like you're kinda mixed up here; 'msg' would be the address, whilst '[msg]' would be the content of that address. We want to load the address of the string into SI, which is why 'msg' should be used.

Comments
Thread marked as solved 3+ years ago
This question has already been answered. Start a new discussion instead.