Close

Dealing with macro's duplicates

A project log for Sparkfun RED-V bare metal

I wanted to learn RISC-V, not on an emulator, but on a real bare metal RISC-V processor. Even though Sparkfun RED-V is no longer produced.

olaf-baeyensOlaf Baeyens 11/02/2024 at 20:440 Comments

The compiled expects this syntax to prevent duplicate definitions of macro's

.ifndef TRACE_MACROS_S_INCLUDED
TRACE_MACROS_S_INCLUDED = 1
...
.endif

Example

.ifndef TRACE_MACROS_S_INCLUDED
TRACE_MACROS_S_INCLUDED = 1


.include "./src/include/global_constants.s"

.align 2
.section .rodata

STRINGS_TRACE_START_MSG:        .asciz "[TRACE] "

.section .text
.align 2
# ===============================================================
# TRACE message_ptr 
# ===============================================================
.if TRACE_LEVEL > 0
    .macro TRACE message_ptr
        la      a0, \message_ptr
        jal     puts
        la      a0, CRLF
        jal     puts
    .endm
.else
    .macro TRACE message_ptr
        # No operation when TRACE is disabled
    .endm
.endif

.endif  

Discussions