flat assembler
Message board for the users of flat assembler.

Index > Main > problem with using a register as a pointer

Author
Thread Post new topic Reply to topic
fatdogs12



Joined: 18 May 2008
Posts: 3
fatdogs12
I have been trying to create my own arrays, I have figured out how to do this, but not using (from what I can tell) traditional means.

for example to create an array I can do:

Code:

mov ebx, 0
mov ebx, 20

mov dword [array1], ebx
mov dword [array1+1], ebx
        

.data
array1 rb 10
    


This will do the trick, but I was hoping I would be able to just throw the address of the array into a register and access it that way. (like a pointer) Is that possible? (something like below):

Code:

mov eax, array1

mov [eax], 20
add eax, 1

mov [eax], 20

    


Thanks in advance
Post 19 May 2008, 01:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
fatdogs12 wrote:
Code:

mov ebx, 0
mov ebx, 20

mov dword [array1], ebx
mov dword [array1+1], ebx
        

.data
array1 rb 10
    
Don't you want to use a different register for the second value? Or do you want both values to be 20, in which case the first 'mov ebx,0' is unnecessary. And since you are writing dwords you might need to make your offset for the second store +4?
fatdogs12 wrote:
Code:

mov eax, array1

mov [eax], 20
add eax, 1

mov [eax], 20

    


Thanks in advance
You need a size identifier to make it assemble. Since you are using an offset of +1 then I assume you want a byte size store:
Code:
mov byte[eax],20    
Post 19 May 2008, 02:06
View user's profile Send private message Visit poster's website Reply with quote
asmrox



Joined: 19 Jan 2008
Posts: 160
asmrox
why dont u u se stack for array?

sub esp,10
mov ebp,esp

mov byte [ebp+9],0
Post 19 May 2008, 07:59
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
difference with stack and arrays:

stack elements are defined at run time ( but can be defined during compile)

arrays elements are defined during compilation ( but can be defined at run time)

stack is in global memory but used for a context-save mechanism.
memory is global, and is general purpose.

the stack frames used in C and hll are what they are: something from an old age.

can you set up a stack like a file?

open file
read file at stack
use this stack reliabily between all procedures?

there are mechanisms in IA 32 to use stack frames in a lot of ways, but none of them is natural or simple.

the simplest is the global memory.
Post 19 May 2008, 09:07
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
stack is in global memory but used for a context-save mechanism.
memory is global, and is general purpose.

what do you mean by this?

Quote:
the stack frames used in C and hll are what they are: something from an old age.

not true anymore. new compilers can live finely without stack frames - something quite hard to do in asm

Quote:
the simplest is the global memory.

But not good for everything. It is okay for small hobby projects, but not for real bigger stuff. With "everything as global" you can't use recursion, position-independent code, shared code, multithreading, etc... eventually you will find out the problem with it (ever wondered why there is no shared DLL version of FASM?)
Post 19 May 2008, 09:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
Quote:

what do you mean by this?

i try to mean that stack is a little part of the possibilities of Global memory.

it i not hard to code without stack frames.

for sure, all "global" is not good, but as global, i assume there are "local" arreas inside the global, like segments, pages and stack frames.

see that stack frames are local, but... they are temporary, not permanent, and they are not able to address variables inside an other stack frame.
then, using stack for arrays is not a good idea.

the global/local addressing is a real problem is OOP, as each object will be charged somewhere in the "Global" memory, and accessed via other objects or code.

y=ax²+bx+c is the equation of the memory problem.
Post 19 May 2008, 09:42
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
i try to mean that stack is a little part of the possibilities of Global memory.

Not true. There are some things only globals can (pre initialized values), but there are many things that locals can and globals can't. See list in previous post.
Post 19 May 2008, 11:09
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.