Skip to content

Instantly share code, notes, and snippets.

@jstaursky
Last active August 13, 2020 15:29
Show Gist options
  • Save jstaursky/2a6cb610edd990b6e45fbee95016e614 to your computer and use it in GitHub Desktop.
Save jstaursky/2a6cb610edd990b6e45fbee95016e614 to your computer and use it in GitHub Desktop.
learning to write slaspec
define endian=big;
define  space     ram       type=ram_space       size=4   default;
define  space     register  type=register_space  size=4;
define  register  offset=0  size=1 [ r0 r1 ];

define token instr(8)
op=(0,0) reg=(1,1) mode=(2,2) imm=(3,3)
;
attach variables [ reg ] [ r0 r1 ];

op2: imm is mode=0 & imm { }

:and reg,op2 is op=0x00 & reg & op2 { }

# 0x02 0000_0010 <--> and r1,0x0
#      ^^^^ bits are ignored (b/c they are unspecified in token)

# 0x0a = XXXX_1010  <-> and r1,0x1
# 0x10 = XXXX_1000  <-> and r0,0x1
# 0x02 = XXXX_0010  <-> and r1,0x0
# 0x00 = XXXX_0000  <-> and r0,0x0
# where XXXX means any arbitrary combination of 0's and 1's

Note that specifying

define endian=little;

instead makes no difference here as a token is only 1 byte.

Also note that the semantic section can be empty { } if we are only interested in disassembly.

Multiple subtables

define endian=little;
define  space     ram       type=ram_space       size=4   default;
define  space     register  type=register_space  size=4;
define  register  offset=0  size=1 [ r0 r1 ];

define token instr(8)
op=(0,0) reg=(1,1) mode=(2,2) imm=(3,3)
;
attach variables [ reg ] [ r0 r1 ];

op2: imm is mode=0 & imm {  }
op2: reg is mode=1 & reg {  }


:and reg,op2 is op=0x00 & reg & op2 { }

# Now an input of 0000_1110 gives and r1,r1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment