LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing an assembler in LabVIEW

Hi all,

 

I'm writing a simulator for a favorite uC, the LC3. I've got the state machine, data path, and control logic implemented, and am now on to the assembler. Does anyone have experience parsing programs into machine code? The standard implementation of LC3 makes use of a symbol table to parse the various labels and instructions. I've got a partial setup that parses an input program using regex, but I'm unsure of the best way to build the symbol table. As it stands, I'm searching each line of the command for tokens (valid tokens being commands like ADD,JMP,LDI, registers like R0-R7, branch tags, and offset numbers), then deciding on "valid" command grammar for each command (Like you can't have AND BR JMP, rather AND R* R*||imm||fill R*||imm||fill) and building out the machine code that way. Is there a better way to do this?

 

I'm also lost on how to build labels into all of this. You can label lines for something like a branch command, or for a .FILL (say you want to store a bitmask x8000 as MASK_MSB). Should I just allow any text to be a label before a command? What then would prevent you from labelling a line with an otherwise valid command, eg .FILL .FILL x8000?

 

I do realize this is a very hard problem, and would appreciate helpful/insightful comments over pessimistic ones. This is just a personal project of mine that I've been working on for a few months, so if need be I can implement things "the hard way", but if there's something simple that I'm missing, I'd love to hear about it.

 

Here's a reference on the LC3 assembler in case you're interested: https://classes.soe.ucsc.edu/cmpe012/Summer09/notes/07_LC3_Assembly.pdf

0 Kudos
Message 1 of 6
(3,862 Views)

I tried something like that in LV 4 (or maybe an earlier version when I started). Mine was for the 6502 processor.  That was the device used in the Apple ][ computers.

 

From a quick glance at the VI names, it looks like I did something very similar to your approach. I recall that the labels were an issue for me as well.  

 

Unfortunately, I cannot offer you any real solutions.  I never finished that project.

 

I seem to recall that there was a list of restricted terms (such as command names) which were not permitted as labels.

 

I know that the program made several passes through the source code rather than trying to parse it all at once.

 

Good luck.

 

Lynn

0 Kudos
Message 2 of 6
(3,839 Views)

Thanks! Any chance you still have the source code?

0 Kudos
Message 3 of 6
(3,835 Views)

I have some of the LV VIs in version 4. I do not have any 6502 source code or any documents on the language, although I suspect those can be found through a search. The VIs seem to be scattered into several locations so I will need to do some digging to collect them.  I will post something later, possibly tomorrow.

 

Lynn

Message 4 of 6
(3,820 Views)

Personally, I find both parsers and CPU architectures to be really boring, so I'm not sure what a good data structure is, but I was about to point out that there are already C64 and Apple II emulators out there. I figured I would post a link, and the first result was this - http://forums.ni.com/t5/LabVIEW/Can-I-implement-a-stack-in-LabVIEW/m-p/3172993/highlight/true#M91669... . Hmm...

 

Another option is this guy, who says he has been working on x86 emulation - https://lavag.org/topic/19464-lurking/

 

I also remember seeing various parsers that people posted for things (such as BNF for parsing math), but I don't remember details, as it was years ago. Maybe it was rolfk?

 

 


___________________
Try to take over the world!
0 Kudos
Message 5 of 6
(3,785 Views)
Yep, that was mine! I've gotten much farther since then. Thanks to some good discussion elsewhere, I think I'm on the right track to finishing up the parser. Thanks for the link.
0 Kudos
Message 6 of 6
(3,767 Views)