News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

loading adress from constant

Started by GouShou, December 27, 2006, 08:25:07 PM

Previous topic - Next topic

GouShou

Hi everybody!

Like my question most likely reveals I'm very new to assembler.

This code works absolutely fine:
mov ebx, Nr
mov ebx, [ebx*4+55E0B8h]
                invoke wsprintf, addr text, CTEXT("Nr: %d"), addr Byte PTR DS: [ebx]


While this displays only nonsense on the screen:

.const
BA dd 55E0B8h
;...
.code
;...
mov ebx, Nr
mov ebx, [ebx*4+BA]
                invoke wsprintf, addr text, CTEXT("Nr: %d"), addr Byte PTR DS: [ebx]


So how do I put the adress 55E0B8 into a constant, while it works like i did not?

I tried google and everything, but didn't find help.
I appreciate any help. :)

TNick

Hello, GouShou, and welcome at board!!
You don't have to declare BA as a constant. Use an EQU instead:


BA   EQU   55E0B8h

mov ebx, Nr
mov ebx, [ebx*4+BA]
.
.
.


This works fine. Take this advice , too, from Donkey!

If you want to use a variable, you can do this:

.DATA
BA dd 55E0B8h

.CODE
mov ebx, Nr
mov eax, BA
mov ebx, [ebx*4+eax]
.
.
.


Regards,
Nick

GouShou

Works! Thank you a lot.  :bg

I take the second version, as recommended. :)

TNick

As you wish, but, if you don't need to change the value of BA with some calculation, I would recommend the first choice, because second one needs one more instruction..

Regards,
Nick

GouShou

Yeah, you are right, I didn't think about that.

So I'll stick to the EQU version. :)