News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Help a beginner [addressing modes]. . . .

Started by xponential, March 08, 2014, 02:53:47 AM

Previous topic - Next topic

xponential

Good day Everyone! I'm not sure what i'm doing wrong but here is the little piece of code thats giving me problem:
.386
.model flat, stdcall
option casemap: none
include windows.inc
include kernel32.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.data
Data_Items dd 12, 15
.data?
Item dd ?
.code
start:
mov edx, Data_Items
mov ecx, 4
mov eax, [edx+ecx]
push eax
pop character
invoke StdOut, addr character
invoke ExitProcess, 0
end start

anytime i assembly this, the program opens and crashes immediately, my aim is to output '15'. Please whats wrong with the code? I even used:
mov character, eax
instead of push, pop but i get same error, thanks.

qWord

For MASM data labels represent the variable and not the address. To get the address use the OFFSET operator:
mov edx,OFFSET Data_Items
Remarks that you can also directly use the label as memory operand:
mov ecx, 4
mov eax, Data_Items[ecx]

or
mov eax, Data_Items[4]

MREAL macros - when you need floating point arithmetic while assembling!

xponential


jj2007

Quote from: xponential on March 08, 2014, 03:41:21 AM
Thanks buddy, it now works :)

Surprising - there were some other issues ;-)

Here is one more form of indirect addressing:

mov edx, offset Data_Items

mov ecx, 4
mov eax, [edx+ecx]  ; = [edx+4], see qWord's post

mov ecx, 1
mov eax, [edx+4*ecx]  ; = [edx+4*1]

xponential

^ Thanks for the additional info, much appreciated. On the other hand, how do i output numbers as their decimal value rather than ASCII?

jj2007

include \masm32\include\masm32rt.inc

.code
start:
   mov eax, 12345
   MsgBox 0, str$(eax), "A number:", MB_OK
   exit

end start


Have a look at the \Masm32\Help folder...

Gunther

Hi xponential,

and welcome to the forum.

Gunther
You have to know the facts before you can distort them.

dedndave

the str$ macro will do it for you, as Jochen mentioned
if you are curious, you can always look at the macros, as well as the functions they call
the \masm32\help\hlhelp.chm file will give you some info on using the macros

another thing worth mentioning...
Quoteanytime i assembly this, the program opens and crashes immediately

we often place an "inkey" (another macro) before the ExitProcess
that way, you can see the results before the console window closes

xponential