2022-01-27 07:21:21 +01:00
|
|
|
WHITESPACE = _{ " " | "\t" | "\n" | "\r" | "\x0B" | "\x0C" | "\xA0" | SPACE_SEPARATOR }
|
|
|
|
COMMENT = _{ ";" ~ (!"\n" ~ ANY)* }
|
|
|
|
|
|
|
|
assembly = {
|
|
|
|
SOI ~ (origin | include_bin | data | constant | label | instruction)* ~ EOI
|
|
|
|
}
|
|
|
|
|
|
|
|
origin = {
|
|
|
|
origin_padding |
|
|
|
|
origin_no_padding
|
|
|
|
}
|
|
|
|
origin_padding = { "org.pad" ~ operand_value }
|
|
|
|
origin_no_padding = { "org" ~ operand_value }
|
|
|
|
|
|
|
|
include_bin = { "#include_bin" ~ immediate_str }
|
|
|
|
|
|
|
|
data = {
|
|
|
|
data_byte |
|
|
|
|
data_half |
|
|
|
|
data_word |
|
2022-05-30 09:31:41 +02:00
|
|
|
data_str |
|
|
|
|
data_fill
|
2022-01-27 07:21:21 +01:00
|
|
|
}
|
|
|
|
data_byte = { "data.8" ~ operand_value }
|
|
|
|
data_half = { "data.16" ~ operand_value }
|
|
|
|
data_word = { "data.32" ~ operand_value }
|
|
|
|
data_str = { "data.str" ~ immediate_str }
|
2022-05-30 09:31:41 +02:00
|
|
|
data_fill = { "data.fill" ~ operand_value ~ "," ~ operand_value }
|
2022-01-27 07:21:21 +01:00
|
|
|
|
|
|
|
constant = { "const" ~ constant_name ~ operand_value }
|
|
|
|
constant_name = ${label_name ~ ":"}
|
|
|
|
|
2022-05-19 23:25:29 +02:00
|
|
|
label = { label_kind? ~ label_name ~ ":" }
|
|
|
|
label_kind = {
|
|
|
|
label_external |
|
|
|
|
label_global
|
|
|
|
}
|
2022-01-27 07:21:21 +01:00
|
|
|
label_name = @{ label_name_chars+ }
|
|
|
|
label_name_chars = @{ ASCII_ALPHANUMERIC | "_" }
|
2022-05-19 23:25:29 +02:00
|
|
|
label_external = { "extern" }
|
|
|
|
label_global = { "global" }
|
2022-01-27 07:21:21 +01:00
|
|
|
|
|
|
|
operand = {
|
|
|
|
"[" ~ operand_value_ptr ~ "]" |
|
|
|
|
operand_value
|
|
|
|
}
|
|
|
|
operand_value_ptr = {
|
|
|
|
operand_value
|
|
|
|
}
|
|
|
|
operand_value = {
|
|
|
|
register |
|
|
|
|
immediate_bin |
|
|
|
|
immediate_hex |
|
|
|
|
immediate_dec |
|
|
|
|
immediate_char |
|
|
|
|
label_name
|
|
|
|
}
|
|
|
|
|
|
|
|
size = @{
|
|
|
|
".8" |
|
|
|
|
".16" |
|
|
|
|
".32"
|
|
|
|
}
|
|
|
|
|
|
|
|
condition = @{
|
2022-03-12 21:15:27 +01:00
|
|
|
"ifz" |
|
|
|
|
"ifnz" |
|
|
|
|
"ifc" |
|
|
|
|
"ifnc" |
|
|
|
|
"ifgteq" |
|
|
|
|
"ifgt" |
|
|
|
|
"iflteq" |
|
|
|
|
"iflt"
|
2022-01-27 07:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
instruction = {
|
|
|
|
condition? ~ instruction_conditional
|
|
|
|
}
|
|
|
|
|
|
|
|
instruction_conditional = {
|
|
|
|
instruction_zero |
|
|
|
|
instruction_one ~ size? ~ operand |
|
|
|
|
instruction_two ~ size? ~ operand ~ "," ~ operand
|
|
|
|
}
|
|
|
|
|
|
|
|
instruction_zero = @{
|
|
|
|
"nop" |
|
|
|
|
"halt" |
|
|
|
|
"brk" |
|
|
|
|
"reti" |
|
|
|
|
"ret" |
|
|
|
|
"ise" |
|
2022-08-16 02:22:40 +02:00
|
|
|
"icl" |
|
|
|
|
"mse" |
|
|
|
|
"mcl"
|
2022-01-27 07:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
instruction_one = @{
|
|
|
|
"inc" |
|
|
|
|
"dec" |
|
|
|
|
"not" |
|
|
|
|
"jmp" |
|
|
|
|
"call" |
|
|
|
|
"loop" |
|
|
|
|
"rjmp" |
|
|
|
|
"rcall" |
|
|
|
|
"rloop" |
|
|
|
|
"push" |
|
2022-08-09 10:43:13 +02:00
|
|
|
"pop" |
|
2022-08-16 02:22:40 +02:00
|
|
|
"int" |
|
2022-09-14 02:37:42 +02:00
|
|
|
"tlb" |
|
|
|
|
"flp"
|
2022-01-27 07:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
instruction_two = @{
|
|
|
|
"add" |
|
|
|
|
"sub" |
|
|
|
|
"mul" |
|
|
|
|
"div" |
|
|
|
|
"rem" |
|
|
|
|
"and" |
|
|
|
|
"or" |
|
|
|
|
"xor" |
|
|
|
|
"sla" |
|
|
|
|
"sra" |
|
|
|
|
"srl" |
|
|
|
|
"rol" |
|
|
|
|
"ror" |
|
|
|
|
"bse" |
|
|
|
|
"bcl" |
|
|
|
|
"bts" |
|
|
|
|
"cmp" |
|
|
|
|
"movz" |
|
|
|
|
"mov" |
|
|
|
|
"rta" |
|
|
|
|
"in" |
|
|
|
|
"out"
|
|
|
|
}
|
|
|
|
|
|
|
|
immediate_bin = ${ "0b" ~ body_bin }
|
2022-03-12 20:58:00 +01:00
|
|
|
body_bin = @{ (ASCII_BIN_DIGIT | "_")+ }
|
2022-01-27 07:21:21 +01:00
|
|
|
|
|
|
|
immediate_hex = ${ "0x" ~ body_hex }
|
2022-03-12 20:58:00 +01:00
|
|
|
body_hex = @{ (ASCII_HEX_DIGIT | "_")+ }
|
2022-01-27 07:21:21 +01:00
|
|
|
|
|
|
|
immediate_dec = ${ body_dec }
|
2022-03-12 20:58:00 +01:00
|
|
|
body_dec = @{ (ASCII_DIGIT | "_")+ }
|
2022-01-27 07:21:21 +01:00
|
|
|
|
|
|
|
immediate_char = ${ "'" ~ body_char ~ "'" }
|
|
|
|
body_char = @{ '\x00'..'\x7F' }
|
|
|
|
|
|
|
|
immediate_str = ${ "\"" ~ body_str ~ "\"" }
|
|
|
|
body_str = @{ body_str_chars* }
|
|
|
|
body_str_chars = {
|
|
|
|
!("\"" | "\\") ~ ANY
|
2022-02-22 22:31:51 +01:00
|
|
|
| "\\" ~ body_str_chars
|
2022-01-27 07:21:21 +01:00
|
|
|
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
|
|
|
|
}
|
|
|
|
|
|
|
|
register = ${ "r" ~ register_num }
|
|
|
|
register_num = @{ ASCII_DIGIT+ | "sp" }
|