You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow expressions where immediate values are expected and where a value is expected for numeric directives such as .byte, .half, .word, .dword, etc.
Background
RARS like many other assemblers allows one to define constants with an .eqv, .equ or .define directive. Those constants can be used for immediate values in the assembly code. Consider the following RISC-V assembly code:
.eqv Mask 0xf.text li a0, Mask
RARS processes .eqv directive for Mask which results in the replacement of Mask with its value 0xf. After .eqv processing the RISC-V assembly code becomes:
.eqv Mask 0xf.text li a0,0xf
and is then compiled to executable form.
While developing an application there are times where you may need to combine values from different constants to generate an immediate value at assembly/compile time. Consider the following:
.eqv BytesPerWord 4.eqv NumWords 2.eqv Mask1 0x00f.eqv Mask2 0xf00.eqv Mask3 ~ ( Mask1 | Mask2 ) .text li a0, Mask1 | Mask2 # does not work in RARS li a0, Mask3 # does not work in RARS li a0, BytesPerWord * NumWords # does not work in RARS
This need to calculate values also extends to the definition of numeric directives such as .byte, .half, .word, .dword, etc. There are times where you may want to calculate the size of a chunk of data memory and place that value in a .byte, .half, .word, .dword, etc. at assembly/compile time. Consider the following:
.macro asciib %label%, %string% .data .align4 .byte %label%$end - %label% # does not work in RARS%label%: .ascii %string% .align4%label%$end:.end_macro.macro asciih %label%, %string% .data .align4 .half %label%$end - %label% # does not work in RARS%label%: .ascii %string% .align4%label%$end:.end_macro.macro asciiw %label%, %string% .data .align4 .word %label%$end - %label% # does not work in RARS%label%: .ascii %string% .align4%label%$end:.end_macro
The above technique is applicable for calculating the size of application defined "structures" that are comprised of varying data defining directives.
Basic Proposal
Allow basic C language style expressions, with the same operator precedence, where ever an immediate value is expected or when ever a value is expected for a numeric type directives such as .byte, .half, .word, .dword, etc.:
Allow parentheses for grouping.
Allow unary plus, unary minus, bitwise not (~), logical not (!).
Allow bitwise logical left shift (<<), logical right shift (>>), arithmetic right shift (>>>).
Allow bitwise operator and (&).
Allow bitwise operator xor (^).
Allow bitwise operator or (|).
Extended Proposal
Ideally it would also be nice to include the following C language operators to allow one to create conditional constants at assembly/compile time:
Allow relational operators <, <=, >, >=
Allow relational equality operators ==, !=
Allow logical and (&&).
Allow logical or (||)
Allow ternary conditional (?:)
Proposal Notes
Expression calculations should not occur in the .eqv directive, only when the immediate value is expected or when a value is expected for a numeric type directive. Consider the following and its implications:
then after .eqv directive processing is complete, the expression is calculated to produce the final 0xfffff0f0 value for the li instruction and evaluate to:
This order of evaluation is necessary because under the proposal the following code, should also produce the same 0xfffff0f0 value for the li instruction when no .eqv directive is used:
.text li a0, ~ ( 0x00f | 0xf00 )
or when .eqv directives are mixed with expression syntax as in the following code, which should also produce the same 0xfffff0f0 value for the li instruction:
The proposal does not imply that the semantics of the .eqv directive change. Currently the application of the .eqv directive would have evaluated to the following code, then RARS would have issued an error in the messages pane since the immediate value for the li instruction was not a decimal or hexadecimal number.
Enhancement Request
Allow expressions where immediate values are expected and where a value is expected for numeric directives such as
.byte
,.half
,.word
,.dword
, etc.Background
RARS like many other assemblers allows one to define constants with an
.eqv
,.equ
or.define
directive. Those constants can be used for immediate values in the assembly code. Consider the following RISC-V assembly code:RARS processes
.eqv
directive forMask
which results in the replacement ofMask
with its value0xf
. After.eqv
processing the RISC-V assembly code becomes:and is then compiled to executable form.
While developing an application there are times where you may need to combine values from different constants to generate an immediate value at assembly/compile time. Consider the following:
This need to calculate values also extends to the definition of numeric directives such as
.byte
,.half
,.word
,.dword
, etc. There are times where you may want to calculate the size of a chunk of data memory and place that value in a.byte
,.half
,.word
,.dword
, etc. at assembly/compile time. Consider the following:The above technique is applicable for calculating the size of application defined "structures" that are comprised of varying data defining directives.
Basic Proposal
Allow basic C language style expressions, with the same operator precedence, where ever an immediate value is expected or when ever a value is expected for a numeric type directives such as
.byte
,.half
,.word
,.dword
, etc.:~
), logical not (!
).*
), division (/
), remainder (%
).+
), subtraction (-
).<<
), logical right shift (>>
), arithmetic right shift (>>>
).&
).^
).|
).Extended Proposal
Ideally it would also be nice to include the following C language operators to allow one to create conditional constants at assembly/compile time:
<
,<=
,>
,>=
==
,!=
&&
).||
)?:
)Proposal Notes
Expression calculations should not occur in the
.eqv
directive, only when the immediate value is expected or when a value is expected for a numeric type directive. Consider the following and its implications:The proposal implies that the above code first expand the
.eqv
directive forMask3
and evaluate to:then expand the
.eqv
directive forMask1
andMask2
and evaluate to:then after
.eqv
directive processing is complete, the expression is calculated to produce the final0xfffff0f0
value for theli
instruction and evaluate to:This order of evaluation is necessary because under the proposal the following code, should also produce the same
0xfffff0f0
value for theli
instruction when no.eqv
directive is used:or when
.eqv
directives are mixed with expression syntax as in the following code, which should also produce the same0xfffff0f0
value for theli
instruction:The proposal does not imply that the semantics of the
.eqv
directive change. Currently the application of the.eqv
directive would have evaluated to the following code, then RARS would have issued an error in the messages pane since the immediate value for theli
instruction was not a decimal or hexadecimal number.The text was updated successfully, but these errors were encountered: