Site Tools


ivss-constant-expressions

Table of Contents

Constant expressions (ivss)

Constant expressions assign computed absolute values to symbols through .equ. They can combine literals and known symbols using arithmetic and bitwise operators:

.section my_data
begin:
    .word 11, 22, 33
finish:
.equ byte_count, finish - begin
.equ word_count, byte_count / 4
.equ mask, (1 << 3) - 1

The labels are twelve bytes apart, so byte_count becomes twelve and word_count becomes three. mask becomes seven, setting its lowest three bits. These definitions do not append bytes to the section.

ivss stores .equ requests while reading source, then evaluates them after discovering labels. Requests are processed in their recorded order, so this example defines byte_count before using it in word_count.

The expression parser handles precedence and parentheses using operator and value stacks. A completed result becomes an absolute symbol. Subtracting offsets from the same section gives a size independent of that section's eventual base address; a label's offset alone is not its final linked address. Use ordinary symbol references when relocation must supply that address.

Source: asembler.c.

ivss-constant-expressions.md · Last modified: by 127.0.0.1