View the step-by-step solution to:

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

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


Please write macros for the following:

1. PrintHxDc that prints the contents of a given memory location, first in hex

and then in decimal. Parameter is the memory address (label).

2. CopyBlock that copies a block of memory. Parameters are source address,

destination address and length.

3. PrintTime that prints the current time. No parameters. (See example in

Duntemann that was discussed in class.)

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

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question