News:

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

Please help: Define a structure in GAS ...

Started by James Ladd, October 14, 2006, 12:00:37 AM

Previous topic - Next topic

James Ladd

All,

Please help me define a structure in GAS so that I can use the field labels as offset in my
calls. I have an exmaple of how to define a structure / chunk of memory but I need
something to help with addressing the offsets to fields within the structure.

For example:

    mov eax, offset myrect
    mov [eax +myrect.bottom], 128


I know that myrect.bottom is offset 16 (field 4) but I dont want to have to work out all the offsets
to the structure fields myself. Especially if I add fields, which would make me have to recalculate
everything.

I hope this is enough info for someone to help.

Rgs, James.

James Ladd

Ok, I think I have made some progress and here it is:

# Unalterable data.
.section .text

.struct 0
RECT_START:
RECT.left:
        .struct RECT.left + 4
RECT.top:
        .struct RECT.top + 4
RECT.right:
        .struct RECT.right + 4
RECT.bottom:
        .struct RECT.bottom + 4
RECT_END:
RECT_SIZE = RECT_END - RECT_START


# Alterable data.
.section .data

rectTemp: .space RECT_SIZE


In the top section I define the structure that we all know and love, RECT.
In the bottom section I define space for a rect structure that I can write data to and read from.

When I do this:

        mov eax, RECT.left
        mov eax, RECT.top
        mov eax, RECT.right
        mov eax, RECT.bottom


and inspect the assembly I get:


        mov eax, 0x0
        mov eax, 0x4
        mov eax, 0x8
        mov eax, 0xc


Which is correct as far as I can tell.


Rgs, James.
   

sw337

Hi !

I knew that you will be going to have this problem in GAS :wink

Do you make use of CPP (the C Preprocessor) along with GAS ?

If yes, you can do this (i do) ...


#define RECT_left         0
#define RECT_top         4
#define RECT_right       8
#define RECT_bottom   12
#define sizeof_RECT      16

#define D dword ptr

# RECT instance declaration...

rect1 .space sizeof_RECT

# ...

# Referring the elements of RECT.

mov D [rect1+RECT_left], 1
mov D [rect1+RECT_top], 2
mov D [rect1+RECT_right], 3
mov D [rect1+RECT_bottom], 4



May be without CPP you can follow similar approach.

Mark_Larson


  James, off topic.  Have you ever thought of trying fasm, yasm, or nasm or even masm via wine?  I haven't done a lot of linux asm programming but gas always annoyed me.
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

James Ladd

I have looked at those and even tried some.
I like GAS and it works really well. I just dont know all the things I need, but Im getting there.
I have resolved the structure issue as outlined up top.

drhowarddrfine

I'm following this, James.  I tried some simple examples a few months ago and I, too, like how it works.  Haven't had the chance to get back to it though.

Mark_Larson

Quote from: James Ladd on October 17, 2006, 09:55:43 PM
I have looked at those and even tried some.
I like GAS and it works really well. I just dont know all the things I need, but Im getting there.
I have resolved the structure issue as outlined up top.


  I actually used it quite a number of years ago.  I'll give it another go.  I just installed Ubuntu Linux on my system becuase my Kernel ate itself and I didn't want to deal with doing another Windows install.  So far everything I had on the Windows side I have similar stuff on this side.  Excel Spreadsheet (Open Office). Yahoo IM ( gaim), WoW ( wine), etc.  I installed the 32-bit version of Ubuntu instead of 64-bit, because I heard Wine has issues with 64-bit.  Anyone get it to work?  I have to play my World of Warcraft :)

BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

James Ladd

Mark,

Thats what I did - lol

I run Ubuntu as main OS with Windows XP in Virtual Machine and boot to it only to play games or really test what Im doing.
I run cygwin under windows to be able to use the same toolchain on both.
So the code and the makefiles are essentially the same but for a few API's which can be wrapped in macros.

See, you so should help me with my project :)

BTW - WOW Linux version is coming soon I believe.

Mark_Larson

Quote from: James Ladd on October 18, 2006, 06:31:40 AM
Mark,

Thats what I did - lol

I run Ubuntu as main OS with Windows XP in Virtual Machine and boot to it only to play games or really test what Im doing.
I run cygwin under windows to be able to use the same toolchain on both.
So the code and the makefiles are essentially the same but for a few API's which can be wrapped in macros.

See, you so should help me with my project :)

BTW - WOW Linux version is coming soon I believe.

  I had never tried Ubuntu before, this is my first time.  I was really amazed at how easy it was to install.  Past linux installs required a lot more intervention on my part.  It auto-detected all the hardware without incident.  I've hooked up various USB hard drives, and just had them work, and I didn't have to do anyting special.  I'm using Firefox which I had used under Windows.

I can't run Windows stuff since my Windows stuff fried.  But I do have a work computer that I can test stuff on.  I had a Linux development environment under Windows that I had been using ( no cygwin, it uses Mingw), before my kernel ate itself.  I had been using Dev-cpp.  I did that to write my PI program in.  GCC does a better job of optimizing than VC++.  You still use the full Win32 API.  So you still include <windows.h> and use the appropriate Win32 libraries, which I thought was cool.  You can also use Linux libraries as well.  You just have to compile them first.

  If anyone is curious here is a link to Dev-Cpp.  It has multiple things you can download with it.  Debugger,C compiler, C++ compiler, Profiler, package manager,etc.

http://www.bloodshed.net/devcpp.html
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm