Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to parse statements like .data or .asciz? #201

Open
gustavogutierrezutp opened this issue Mar 12, 2024 · 3 comments
Open
Labels

Comments

@gustavogutierrezutp
Copy link

Hi,

I have all the instructions of my architecture already parsed and the produced binary looks fine. How ever I was wonderin if it is possible to also parse the section code like

.global symbol
.asciz "hello"

and to produce the corresponding binary output.

@MineRobber9000
Copy link
Contributor

#d "hello", 0

Not sure what .global symbol does but .asciz can be done with this. You could even use a function:

#fn asciz(s) => ascii(s) @ 0`8
#d asciz("hello")

@ggutierrez
Copy link

Here is an example of what I'm trying to achieve. When .data is parsed then I know that whatever is declared after it goes in the memory as static values. That is why I want to make a rule for it.

#subruledef registerName {
  x0 => 0`5
  x1 => 1`5
  x2 => 2`5
  x3 => 3`5
  x4 => 4`5
}

#ruledef {
  add {rdest: registerName},{rs1: registerName},{rs2: registerName} =>  0x00`7 @ rs2`5 @ rs1`5 @ 0`3 @ rdest`5 @ 0b0110011
}

#ruledef {
  .data => 0`4
}

.data
argument: .word   7
str1:     .string "something1"
str2:     .string " something2 "

.text
main:
add x3, x3, x3

@MineRobber9000
Copy link
Contributor

I'm not sure what "static values" means in this context-- all values outputted to the ROM are static, it's just a matter of how those values are encoded. Your .data section here can be written as:

argument:
#d32 7 ; or d16 for that size
str1:
#d "something1" ; assuming string vs asciz means it's not null terminated, add ", 0" if I'm wrong
str2:
#d " something2 " ; again, add ", 0" for null termination

Of course, if you wanted to codify these as instructions you could easily add them (though you'd need to get rid of the leading dot, since customasm assumes something with a leading dot is a local label):

#ruledef {
    word {n: u32} => n
    string {s} => s
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants