flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > overloaded instructions anyone?

Author
Thread Post new topic Reply to topic
Mercury Knight



Joined: 09 Nov 2008
Posts: 15
Mercury Knight 16 Apr 2009, 09:00
Maybe its darn late at night, or maybe my brain is fuzzed from all that studying in Calculus A, College Physics I, and Circuit Theory II, but I am having darn major trouble trying to figure out why my push (and its opposite pop) macro refuses to work for segment registers:

Code:
macro push [regs]
{
   if ~ regs eq
      forward

      define ..done 0
      match =all , regs
      \{
         pushad
         define ..done 1
      \}
      match =flags , regs
      \{
         pushfd
         define ..done 1
      \}
      match =0 , ..done
      \{
         push regs ; was pushd regs
      \}

      common
   end if
}
    


It is very straightforward, allows one to to change

Code:
    push eax
    push ebx
    pushfd
    pushad
    push dword 1000h
    


into

Code:
   push eax,ebx,flags,all,dword 1000h
    


(dword 1000h is due to my changing the last push in the macro from 'pushd regs' to 'push regs')

If you try to do

Code:
   push ds ; or any other segment registers
    


you get

Code:
test.asm [42]:
        push    ds
stdmacros.mac [72] push [22]:
         push ds
error: reserved word used as symbol.
    


I've been wracking my brains, but I haven't yet figured out why its telling me that. Does anyone know why the macro would fail on segment registers but would not fail on other registers passed to it?

Thanks!

MK
Post 16 Apr 2009, 09:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 16 Apr 2009, 09:21
Your code works for me:
Code:
macro push [regs]
{
   if ~ regs eq
      forward

      define ..done 0
      match =all , regs
      \{
         pushad
         define ..done 1
      \}
      match =flags , regs
      \{
         pushfd
         define ..done 1
      \}
      match =0 , ..done
      \{
         push regs ; was pushd regs
      \}

      common
   end if
}

push ds    
Quote:
flat assembler version 1.67.38 (100000 kilobytes memory)
1 passes, 1 bytes.
It must be something else in your code. Do you have another push macro before the one you show above? Have you redefined ds somewhere?
Post 16 Apr 2009, 09:21
View user's profile Send private message Visit poster's website Reply with quote
Mercury Knight



Joined: 09 Nov 2008
Posts: 15
Mercury Knight 16 Apr 2009, 12:55
I feel so stupid! DS was indeed redefined, I forgot about it.

Code:
struc ds [data]
{
   common

   db data,0
   alignb 4
}

; you use it like...
StrMess1 ds "This is the first string"
StrMess2 ds "This is the second string"
    


Its a simple macro which stands for "define string". You use this instead of db or du, and it automatically appends a null terminator at the end of the string so you dont have to. Any strings (or other data) defined afterwards is automatically aligned on the next 4 byte alignment. I use this in my windows macros, this particular macro is for the ASCII version of Windows, the Unicode version uses "du data,0". This allows me to define a string one time, and if I needed to change from Unicode to ASCII or vice versa, I simply define WINASCII to use the ASCII version and reassemble the code. Much easier than searching throughout the source code for all of the strings and changing db to du or vice versa.

Unless I find a way to keep this, I'm going to have to go through the code I've written so far and change all of the macro ds to something else so that it does not conflict with the segment register ds. I never thought to look at it until you asked, because my code was pushing ds first, then es, fs, and gs. Any ideas what I should rename the macro ds as? Or hopefully you have any tricks up your sleeve that will let me keep ds as a macro and still use it as a segment register as well?

Thanks for pointing me in the right direction.

MK
Post 16 Apr 2009, 12:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 16 Apr 2009, 13:36
You can make one or both characters capital letters: Ds, dS or DS.
Post 16 Apr 2009, 13:36
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 16 Apr 2009, 13:39
Actually since it is for Windows then why do you need to bother with pushing/popping DS? Or any of the segment registers? Windows uses flat addressing so all segments can access the entire 4G memory.
Post 16 Apr 2009, 13:39
View user's profile Send private message Visit poster's website Reply with quote
Mercury Knight



Joined: 09 Nov 2008
Posts: 15
Mercury Knight 16 Apr 2009, 14:41
Sorry, I forgot to tell you: This isn't for Windows, although the macro itself was originally written for Windows programming. I, like who knows how many others, am writing an operating system (32 bits even tho I have an Athlon XP 64-X2), and I also write DOS programs as well, although I haven't in the past couple of years (busy with school and a certain large Windows program...). I have an alpha-level kernel written in nasm, and I have been porting it over to fasm since nasm's updates shattered most of my macros to tiny little pieces. It was the IRQ handlers that brought ds to my attention...

I was programming for Windows when I was first learning how fasm's preprocessor works. The macros in the sysmacros.mac file was moved from Windows and is designed to be platform-independent, so that the same set of macros can work whether programming for Windows or another OS. Thus I forgot that my ds macro was also the name of the segment register, because like you said, we use flat addressing in Windows...
Post 16 Apr 2009, 14:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 16 Apr 2009, 14:57
BTW: Windows uses the TCHAR name to define strings. The standard fasm macros also use this name and will morph their behaviour to byte or word depending upon the included file (win32ax or win32wx).
Post 16 Apr 2009, 14:57
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.