Question: Topic: Macros All macros must be specified in NASM format. Show each macro definition and also give an example of the macro call and macro

Topic: Macros

All macros must be specified in NASM format.

Show each macro definition and also give an example of the macro call and macro expansion.

Use the C library.

Example:

%macro mWrite 1 ; ; Writes a string literal to standard output with newline. ; Receives: a string enclosed in single or double ; quotes (null terminator not required). ; Uses puts ;------------------------------------------------------ segment .data %%string: db %1,10,0 segment .text push dword %%string call puts add esp,4 %endmacro

Macro call:

mWrite I love assembly language!

Expansion:

segment .data %%string: db I love assembly language!,10,0 segment .text push dword %%string call puts add esp,4

(NASM listing doesn't show the generated labels.)

1. Write a macro PrintHxDc that prints the contents of a given memory location, first in hex and then in decimal. Parameter is the memory address (label).

2. Write a macro CopyBlock that copies a block of memory. Parameters are source address, destination address and length.

3. Write a macro PrintTime that prints the current time. No parameters. (See example in Duntemann that was discussed in class.)

4. Write a macro that simulates 3-operand instructions by creating a 3-operand add and subtract in the format add3 dest,source1,source2 and sub3 dest,source1,source2 where source1, source2 and dest can be any legal 32-bit location. The macro should use EAX for temporary storage.

Assume all variables are signed 32-bit quantities, except for when you can tell they are characters.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!