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 is just similar to defining subroutines and macros, except now we won't have parameters, of course. Examine the excerpt below:
TASM | MASM |
---|---|
struct circle x dw ? y dw ? radius dw ? ends | circle struct x dw ? y dw ? radius dw ? circle ends |
That's the structure type definition. To declare the variable is like this:
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:
: 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?
If we declare these variables:
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?
OK, I think that's all for now. See you next time.
Chapter 15
News Page
x86 Assembly Lesson 1 index
Contacting Me
Roby Joehanes © 2001