+2 votes
99 views
in Computer Architecture by

1 Answer

+1 vote
by
selected by (user.guest)
 
Best answer

we will be using a stand-alone macro processor called m4 for this course. Essentially it is a UNIX filter program that copies its input to its output, checking all alphanumeric tokens to see if they are macro definitions or expansions. Macros may be defined using the define macro. This takes two arguments, the macro name and the text of the definition of the macro. Later in the processing of the input, if the macro name appears in the text it is replaced by the definition. Macros may make use of up to nine arguments, using a $n notation similar to that used in UNIX shell scripts. For example, a macro to define an assembler constant and an example of its use are as follows:

define(const, $1 = $2)

...

const(a2, 7)

When passed through m4 the result would be:

...

a2 = 7

The arguments to a macro are themselves checked to see if they are macros and will be expanded before being substituted for the formal arguments. In addition, macro definitions may be quoted to prevent them from being expanded when the macro is defined but only when it is expanded. This is rather unusual as it uses the open and close single quotes (e.g. ‘hello’—note that the open quote character on most computer keyboards often looks like an accent: `).

To run the macro processor we would typically do something along the following lines:

$ m4 prog.m > prog.s

$ gcc -g prog.s -o prog

Note the convention we use that assembler files containing macro definitions and expansions are given a.m suffix. We will see more of the uses of m4 as we proceed through the course.

Related questions

0 votes
1 answer 18 views
0 votes
1 answer 90 views
+1 vote
1 answer 104 views
+1 vote
1 answer 438 views
+2 votes
1 answer 2.6k views
+1 vote
1 answer 929 views
+2 votes
1 answer 5.8k views
+1 vote
1 answer 322 views
+1 vote
1 answer 2.3k views
+1 vote
1 answer 85 views
+2 votes
1 answer 73 views
+2 votes
1 answer 222 views
+1 vote
1 answer 85 views
asked Oct 6 in Computer Architecture by anonymous
+1 vote
1 answer 211 views
+1 vote
1 answer 244 views
+1 vote
1 answer 173 views
+1 vote
1 answer 139 views
+1 vote
1 answer 116 views
asked Sep 17 in Computer Architecture by anonymous
+1 vote
1 answer 107 views
+1 vote
1 answer 81 views
+1 vote
0 answers 37 views
+1 vote
1 answer 243 views
+1 vote
1 answer 37 views
asked Sep 16 in Computer Architecture by anonymous
+1 vote
1 answer 49 views
+1 vote
1 answer 291 views
asked Sep 16 in Computer Architecture by anonymous
+1 vote
1 answer 132 views
asked Sep 16 in Computer Architecture by anonymous
+1 vote
1 answer 137 views
+1 vote
1 answer 186 views
0 votes
0 answers 222 views
Welcome to CPENTalk.com
Solution-oriented students of computer engineering on one platform to get you that

ONE SOLUTION

...