Assembly Language Using the Raspberry Pi: A Hardware Software Bridge by Robert Dunne

Assembly Language Using the Raspberry Pi: A Hardware Software Bridge by Robert Dunne

Author:Robert Dunne
Language: eng
Format: azw3, epub, pdf
Publisher: Gaul Communications
Published: 2017-06-15T07:00:00+00:00


.macro ascz8 item

.asciz "\item" @ Name of item in list

.align 3 @ Move to next 8-byte alignment boundary.

.endm

Listing 9.4: Macro ascz8 generate an 8-byte name.

Macros typically generate more than one line of assembler code for each macro call line. Macro processing is performed during a first pass through the assembler source file that expands macro statements before the assembler converts them to machine code. You can think of a macro as a subroutine that is called at assembly time. Instead of performing a calculation using the contents of the registers, it generates lines of assembly language code that will be included in the program. Arguments appear after the macro name and are used to provide differences in the assembly language code that is generated.

For the example in Listing 9.4, the ascz8 macro is called with one argument named “item.” Wherever “item” appears in the text of the macro following a back slash, the value from the macro call line will be substituted. For example, the line “ascz8 add” will generate “.asciz "add"” on one line followed by “.align 3” on the next. The purpose of the “.align 3” line is to start the following instruction or data on the next 8-byte boundary so that all elements in the table are the same length of 8, or 23. If it was necessary to make all table elements 16 bytes long (24), then “.align 4” would be used.

We not only use macros to generate table data, but program instructions as well. As you examine the current dis_dp subroutine, you notice that the program segments displaying each of the mnemonic fields in the instruction being disassembled will be very similar and will perform the following:

Call subroutine v_ascz to display a “field separation character” such as a tab or blank.

Select the desired field within the machine code instruction by removing unwanted bits left of the field.

Finish selecting the field by removing unwanted bits right of the field.

Set R1 pointing to the name to be displayed by adding the address of the beginning of the list of field names to 8 times (i.e., 8 bytes per name) the value found in the field.

Call subroutine v_ascz to display the contents of the field.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.