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.

commented: Thread marked as solved 3+ years ago -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.