flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > overloaded instructions anyone?
Author
Mercury Knight

Joined: 09 Nov 2008
Posts: 15
Mercury Knight
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
\{
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
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
16 Apr 2009, 09:00
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17865
revolution
Code:
macro push [regs]
{
if ~ regs eq
forward

define ..done 0
match =all , regs
\{
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?
16 Apr 2009, 09:21
Mercury Knight

Joined: 09 Nov 2008
Posts: 15
Mercury Knight
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
16 Apr 2009, 12:55
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17865
revolution
You can make one or both characters capital letters: Ds, dS or DS.
16 Apr 2009, 13:36
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17865
revolution
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.
16 Apr 2009, 13:39
Mercury Knight

Joined: 09 Nov 2008
Posts: 15
Mercury Knight
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...
16 Apr 2009, 14:41
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17865
revolution
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).
16 Apr 2009, 14:57
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum