<p>I was going through GATE-CS questions, while solving I came across the following question <a href="https://gateoverflow.in/578/gate-cse-1992-question-3-i" rel="nofollow noreferrer">here</a>.</p>
<blockquote>
<p>Write short answers to the following:</p>
<p>Which of the following macros can put a macro assembler into an infinite loop?</p>
<pre><code>.MACRO M1,X
.IF EQ,X  ;if X=0 then
M1 X+1
.ENDC
.IF NE,X  ;IF X≠0 then
.WORD X   ;address (X) is stored here
.ENDC
.ENDM
</code></pre>
<pre><code>.MACRO M2,X
.IF EQ,X
M2 X
.ENDC
.IF NE,X
.WORD X+1
.ENDC
.ENDM 
</code></pre>
<p>Give an example call that does so.</p>
</blockquote>
<p>The actual question I guess had no explanation of what each line of the macro meant, but <a href="https://www.geeksforgeeks.org/gate-gate-cs-1996-question-41/" rel="nofollow noreferrer">here</a> from another site got to know the meaning of the lines apparently.</p>
<p>Please can anyone tell one tell me, what are these types of macros? [I know what are macros in C. Also know that the C processor, substitutes the macros in the actual line of the code. I mean to say that I am not unaware of what macro is but I want to know about it in detail.]</p>
<p>But I want to know what is the syntax of writing these above macros, where are they are used? And the general method/theory of macro expansions. The above question is tagged under &quot;assembler&quot;. What is its connection with assembly language? Are these macros written in some assembly language?</p>
<p>Could anyone recommend me a textbook, which shall help me build concepts on these topics? I could not find myself as I do not know what language are these macros are written in, also I do not know their meaning...</p>

CC BY-SA 4.0
2021-10-27T16:24:45.900Z
I doubt you will find a textbook, but there might be a professional book or two. But if you Google "macros in C" you will find some tutorials and such.
Buffy
CC BY-SA 4.0
2021-10-27T17:00:50.993Z
could you just the professional books
Abhishek Ghosh
CC BY-SA 4.0
2021-10-27T18:23:59.593Z
Sorry, I don't have any to suggest.
Buffy
CC BY-SA 4.0
2021-10-27T18:45:40.750Z
@Buffy ok now issues
Abhishek Ghosh
CC BY-SA 4.0
2021-10-29T16:03:49.627Z
Re, "What is its connection with assembly language?" Just like how macros are part of the "C" programming language, but not some other programming languages; macros are part of _some_ "assembly" languages (Most famously, [Microsoft's MASM language](https://docs.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference?view=msvc-160)), but not others.  Note: I  put "assembly" in scare quotes there because MASM somewhat violates the 1:1 correspondence between source code lines and machine instructions that most of us expect from an assembly language.
Solomon Slow
CC BY-SA 4.0
2021-12-17T22:49:33.350Z
These are macros for an assembler (a tool that translates assembler language to machine code).

You need to find out what assembler language it is, and get the manual for the assembler.

A macro is processed by the assembler pre-processor. It converts each macro to one or more (hence macro: macro=large) assembler instructions.
ctrl-alt-delor
<self-learning><resource-request><textbook><compiling><assembly>
Textbook recommendation for macros and assembler
# Textbook recommendation for macros and assembler

(Asked by: username_0 on 2021-10-27)

I was going through GATE-CS questions, while solving I came across the following question here.

Write short answers to the following:
Which of the following macros can put a macro assembler into an infinite loop?
.MACRO M1,X
.IF EQ,X  ;if X=0 then
M1 X+1
.ENDC
.IF NE,X  ;IF X≠0 then
.WORD X   ;address (X) is stored here
.ENDC
.ENDM

.MACRO M2,X
.IF EQ,X
M2 X
.ENDC
.IF NE,X
.WORD X+1
.ENDC
.ENDM 

Give an example call that does so.

The actual question I guess had no explanation of what each line of the macro meant, but here from another site got to know the meaning of the lines apparently.
Please can anyone tell one tell me, what are these types of macros? [I know what are macros in C. Also know that the C processor, substitutes the macros in the actual line of the code. I mean to say that I am not unaware of what macro is but I want to know about it in detail.]
But I want to know what is the syntax of writing these above macros, where are they are used? And the general method/theory of macro expansions. The above question is tagged under "assembler". What is its connection with assembly language? Are these macros written in some assembly language?
Could anyone recommend me a textbook, which shall help me build concepts on these topics? I could not find myself as I do not know what language are these macros are written in, also I do not know their meaning...

**Tags:** self-learning, resource-request, textbook, compiling, assembly

> **Comments:**
> **username_1**: I doubt you will find a textbook, but there might be a professional book or two. But if you Google "macros in C" you will find some tutorials and such.  
> **username_0**: could you just the professional books  
> **username_1**: Sorry, I don't have any to suggest.  
> **username_0**: @username_1 ok now issues  
> **username_2**: Re, "What is its connection with assembly language?" Just like how macros are part of the "C" programming language, but not some other programming languages; macros are part of _some_ "assembly" languages (Most famously, [Microsoft's MASM language](https://docs.microsoft.com/en-us/cpp/assembler/masm/microsoft-macro-assembler-reference?view=msvc-160)), but not others.  Note: I  put "assembly" in scare quotes there because MASM somewhat violates the 1:1 correspondence between source code lines and machine instructions that most of us expect from an assembly language.  
> **username_3**: These are macros for an assembler (a tool that translates assembler language to machine code).  You need to find out what assembler language it is, and get the manual for the assembler.  A macro is processed by the assembler pre-processor. It converts each macro to one or more (hence macro: macro=large) assembler instructions.  

---

## 0 answers

