flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > WHAT IZ MACRO PLIZ

Author
Thread Post new topic Reply to topic
bit_banger



Joined: 03 Nov 2013
Posts: 3
bit_banger
Looking for a little assistance here, I've been using Debug in XP Windows for my programming,... er, what is a "MACRO"? In Debug the only 'anything' you use outside of the machine code(assembly language) used is "DB, DW, wo, by".... "WHAT IZ MACRO PLIZ" Crying or Very sad
Post 07 Dec 2013, 05:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17664
Location: In your JS exploiting you and your system
revolution
Moved to 'Macroinstructions'
Post 07 Dec 2013, 05:51
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671
system error
In a way, a macro can be likened to a script. It works on the source rather than on the programming 'problem'. Just like a perl or css to an html document. That's just one way to put it. a Debug is a non-symbolic kind of assembler/disassembler. "db,dw" are all macros defined by symbolic macro assemblers like FASM,MASM,NASM.
Post 20 Dec 2013, 09:58
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
bit_banger wrote:
Looking for a little assistance here, I've been using Debug in XP Windows for my programming,... er, what is a "MACRO"


1. AFAIK no version of DOS- or DOS-like- DEBUG supports macro's.

2. MACRO is a preprocessing feature of advanced assemblers (FASM, NASM, ...)

3. RTFM: http://flatassembler.net/docs.php?article=manual#2.3.3
Post 20 Dec 2013, 16:36
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
In essence, a macro is a sequence of code that is replaced before (and while) instructions are converted. It is like Search>Replace with parameters. For example, this movx macro can accept 2 m,m operands:
Code:
macro movx a, b {
 if a eqtype [0] & \ ; if both a+b are [memory] operands
  b eqtype [0]
   push b            ; use push+pop
   pop a
 else                ; standard mov
   mov a, b
 end if
}    
Use of this macro will output push+pop or mov. Usage is replaced with the macro's body/definition.
Code:
movx [x], [y]       ; push+pop
movx eax, 1         ; mov    
It could've been named "mov" to override the default behavior of mov - in this case, the mov after else would have its normal definition - but redefining instructions is frowned upon unless there's a good reason to (example: Universal ASM).

A common obstacle for beginners is mixing if/else with equates and not understanding that they are processed on separate levels. Example:

Problem: if+equ always executes:
Code:
b equ -1  ; create equate
a=1
if a=0    ; preprocessor skips this initially
  b equ 7 ; < always processed
end if    
Solution: b must be a numeric constant.
Code:
b=-1   ; create numeric constant
a=1
if a=0
  b=7  ; < not processed
end if    
For equates, use match instead of if.
Post 23 Dec 2013, 12:17
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
Just wanted to ask a little question here,
Do macros affect binary size, does using macros mean that the
size of the binary will be larger when I use macros or would it be
smaller? Or no change?
Post 13 Jan 2014, 13:35
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
Depends on the size of the macros, how much data+code they produce and how you use them. An incorrect use of macros can produce tons of unnecessary code (example: DexOS). If you think that a macro is "something like a function" (wrong) and you're writing routines as macros - when they should be one call to a proc/function - you'll end up with TONS of additional code. But proper use of macros by experienced programmers will make no difference in the binary size.

Macros are not for beginners. Make sure you know ASM well before learning how to use and/or write macros.
Post 13 Jan 2014, 19:49
View user's profile Send private message Reply with quote
CampTheBoss



Joined: 02 Feb 2015
Posts: 42
Location: A chair
CampTheBoss
Quote:
Macros are not for beginners. Make sure you know ASM well before learning how to use and/or write macros.


I have used FASM for quite a while, but only just started win32 programming (done it for 6 months) after a good 2 years of DOS. About 2 weeks ago, i started using macros and they are easy. So what is hard about them?
Post 17 Feb 2015, 19:19
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17664
Location: In your JS exploiting you and your system
revolution
Macros are only as difficult as you wish to make them. They can be for beginners and experts. I see no reason to scare people away from such things. We learn best by trying.
Post 18 Feb 2015, 02:17
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
I second it. Macros can be blessing or curse, whatever you prefer.
Post 20 Feb 2015, 19:46
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.