1

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...

Abhishek Ghosh
  • 585
  • 2
  • 9
  • 2
    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 Oct 27 '21 at 16:24
  • could you just the professional books – Abhishek Ghosh Oct 27 '21 at 17:00
  • 1
    Sorry, I don't have any to suggest. – Buffy Oct 27 '21 at 18:23
  • @Buffy ok now issues – Abhishek Ghosh Oct 27 '21 at 18:45
  • 1
    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 Oct 29 '21 at 16:03
  • 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 Dec 17 '21 at 22:49

0 Answers0