Assembly language practice question help 1 Suppose that a pr

Assembly language practice question help!!!!

1. Suppose that a program\'s data and executable code require 1712 bytes of memory. A new section of code

must be added; it will be used with various values 24 times during the execution of a program. When
implemented as a macro, the macro code requires 56 bytes of memory. When implemented as a procedure,
the procedure code requires 104 bytes (including parameter-passing, etc.), and each procedure call requires
5 bytes.
a. How many bytes of memory will the entire program require if the new code is added as a macro?
b. How many bytes of memory will the entire program require if the new code is added as a
procedure?

Solution

What happens is, that, the values are copied from the macro to where you used the macro during preprocessing. When it comes to the compiler they don\'t even exist, they\'ve been replaced by the preprocessor before they get that far. that is, macros are a preprocessor construct. It\'s not really important that they do consume more space. the sentence in that book seems kinda preposterous but I don\'t think it\'s compulsary for that to be true. It may be(usually is) true but now always.

Now, coming to the war Functions VS. Macros

I have tried to explain everything in a plain and simple and practical manner, it may take some time to gulp done what I\'m gonna say. :P

Macros : In order to understand the difference between macros and functions, you must understand macros well enough

So, in a macro, there two possibilities. ==>

A. They themselves call other functions predefined in libraries or elsewhere.

B. They make the use of operators to create a whole new function(al) macro(if I may say so).

NOTE: If you think about it, whenever you use a macro, you end up calling an operator or another (inbuilt or elsewise) function only.

Lets first dive into A below:

is more like the below to the compiler

So, as you can see from the above, that you finally ended up calling a function to implement something done using macros, its visible that when calling functions within macros, the compiler actually ends up calling the function only, and not the macro (as one may expect) hence there would be an overhead of memory storage of macros and that of functions in preprocessing. This is place one where the macros take more space than the functions due to an overhead.

So, from above situation, its clear that macros calling inbuilt functions will always be more memory demanding.

Now, lets checkout B:

Compare the example above to the one below:

Same thing, right ? Except, in the second, we use a function instead of a macro.

Now think about it. If you make the use of the same function multiple times, you end up using a lot of memory, but then, with the power of functions like malloc() and free() and realloc() we can always put this memory to good use. But, in the case of a macro, you dont get access to any of this. You will end using more memory than you would in a function, because in a function, you can rewrite, reuse, and hence utilise memory better. Moreover, in assembly, loops aren\'t really possible, hence, when you use a macro, a new variable is created everytime you iterate through the loops and hence, even more memory is used.The above example was just signatory but crucial.

You should try writing a lot more code that can show you the other real benefits of macros and functions. Macros have their uses, but functions are better(usually).

TL;DR: Functions are better, read the whole answer to know why. The book makes the statement sound very rigid and like a hard rule, but the fact is it may not be true everytime.

Assembly language practice question help!!!! 1. Suppose that a program\'s data and executable code require 1712 bytes of memory. A new section of code must be a
Assembly language practice question help!!!! 1. Suppose that a program\'s data and executable code require 1712 bytes of memory. A new section of code must be a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site