search
Log In
15 votes
1.2k views

State whether the following statements are True or False with reasons for your answer

  1. A subroutine cannot always be used to replace a macro in an assembly language program.

  2. A symbol declared as ‘external’ in an assembly language program is assigned an address outside the program by the assembler itself.

in Compiler Design
edited by
1.2k views
0
can someone explain in detail ????
3

For part (B) refer ->

https://en.wikipedia.org/wiki/External_variable

If the program is in several source files, and a variable is defined in file1 and used in file2 and file3, then extern declarations are needed in file2 and file3 to connect the occurrences of the variable. The usual practice is to collect extern declarations of variables and functions in a separate file, historically called a header, that is included by #include at the front of each source file. The suffix .h is conventional for header names.

0

Chhotu 

why a is true?Any ref?

0

a)"The macros can take function like arguments, the arguments are not checked for data type"

Macros are preprocessor directive

But subroutine call is like function call, which can call nested function call.

So, subroutine call and macros are works for different objective

https://www.geeksforgeeks.org/interesting-facts-preprocessors-c/

b)The extern keyword means "declare without defining".

So, "program is assigned an address outside the program"- this is a wrong statement

https://en.wikipedia.org/wiki/External_variable

0

So, subroutine call and macros are works for different objective

it is true... but the question is we can replace every Macro by Sub-routine ?

2 Answers

21 votes
 
Best answer
  1. This is true. We can not replace macro entirely using subroutine. Ex -> Macro constant used for renaming.
     
  2. This is false. This is job of Linker.

selected by
0
Can we Say like this, Macros are evaluated at compile time where as subroutine at run time.

Plz correct me if i am wrong.
0
Can some one tell code where macro is used but subroutine  not possible
0
Example to support 1st clause

#define construct cannot be replaced by subroutine.
1
@Ayush

by tp what do u mean?

I cannot understand
0
#include<stdio.h>

#define ch char

int main()

{

   ch a,b;

   return 0;

}

 

There is No function which can do this work instead of macro

ASSEMBLY ==> SUB-Routine

High-Level ===> Function
0
so means we must require coroutine here
1 vote
B is false, as extern will not allocate memory. the memory will be allocated when that variable will be initialized or declared.
0
extern int i ... wat is the meaning of it ??
0
it mean memory is already allocated to this i outside of the function by linker not by assembler itself

Related questions

9 votes
4 answers
1
1.3k views
State whether the following statements are True or False with reasons for your answer: Coroutine is just another name for a subroutine. A two pass assembler uses its machine opcode table in the first pass of assembly.
asked Oct 6, 2014 in Compiler Design Kathleen 1.3k views
29 votes
2 answers
2
5.4k views
Which of the following features cannot be captured by context-free grammars? Syntax of if-then-else statements Syntax of recursive procedures Whether a variable has been declared before its use Variable names of arbitrary length
asked Oct 4, 2014 in Compiler Design Kathleen 5.4k views
14 votes
4 answers
3
2.4k views
A grammar $G$ is in Chomsky-Normal Form (CNF) if all its productions are of the form $A \to BC$ or $A \to a$, where $A,B$ and $C$, are non-terminals and $a$ is a terminal. Suppose $G$ is a CFG in CNF and $w$ is a string in $L(G)$ of length $n$, then how long is a derivation of $w$ in $G$?
asked Oct 6, 2014 in Compiler Design Kathleen 2.4k views
22 votes
4 answers
4
2.3k views
Match the following items ...
asked Oct 4, 2014 in Compiler Design Kathleen 2.3k views
...