Welcome Guest [Log In] [Register]
Add Reply
Win32 Assembly Chapter14
Topic Started: Jan 10 2008, 03:46 PM (286 Views)
astropirate
Member Avatar
Not Lurking
[ * ]
Structure in Assembly




Welcome

Hi! Welcome to the fourteenth chapter of this series. Now, we're going to discover how we can group several datatypes just like those in high level languages. This grouping is actually done by the assembler, not by the Intel x86 instructions. Assembler will later expand the structure into the variables we know so far. Of course, we don't have to care about the expansion like the one in macros.

Note that the structure in assembly is equivalent to struct in C/C++ or record in Pascal. So, you won't be surprised here. This chapter is going to be a short one.


Defining Structure

Defining structure is just similar to defining subroutines and macros, except now we won't have parameters, of course. Examine the excerpt below:


TASM
Code:
 

struct circle
x dw ?
y dw ?
radius dw ?
ends


MASM
Code:
 

circle struct
x dw ?
y dw ?
radius dw ?
circle ends

That's the structure type definition. To declare the variable is like this:
Code:
 

a circle <0>
b circle <0>

This define a and b as a variable of type circle. Then, we can use the variable as usual. For example:
Code:
 

:
mov [a.x], ax
mov [a.y], bx
mov [word ptr a.radius], 50
:
:

Simple right? Most of the instructions can be applied in structures. The rule of thumb is that if we can apply an instruction into a variable, then we can also apply it into structures. Simple, no?


Memory Map

If we declare these variables:
Code:
 

a circle <0>
b circle <0>

The memory map (see here to refresh) is like this (Suppose the variable a starts at address 100h):


Address Variable
100h a.x
102h a.y
104h a.radius
106h b.x
108h b.y
10Ah b.radius

So, it's similar with having two stacks of x, y and radius, right?


Closing

OK, I think that's all for now. See you next time.


Roby Joehanes © 2001
You will Bow before me!

Posted ImagePosted Image
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Tutorials · Next Topic »
Add Reply