0

I am trying to implement a FSM in the aforementioned version of assembly, but can't seem to get far without knowing which approach to take. Does anyone out there have an implementation they're willing to share?

My main concern is how to use jumps and loops for this specific task.

Additionally, does anyone know how I can make a recursive "method" in assembly and whether that would work out well for this task?

Wilson Canda
  • 434
  • 5
  • 19
  • I apologize if this question is redundant, but I can't relate to the ones already posted on this site, they seem very different. – Wilson Canda Oct 23 '12 at 18:28
  • 1
    If it helps, implement your FSM in some other language first. Also, always draw your FSM. A visual diagram is very useful. – Alexey Frunze Oct 23 '12 at 18:32
  • thanks... ill try python. Can you give me a tip on using recursion in assembly? – Wilson Canda Oct 23 '12 at 19:02
  • 1
    Am I an infinite state machine? :P – Sheena Oct 24 '12 at 07:21
  • 1
    As I could remember now, I've always implemented FSM using basically two structures: a loop and a switch. The loop is for continuously reading the input and of course advancing the processing. The switch is for identifying in which state the machine currently is. The same idea can be implemented in ASM. – JohnTortugo Oct 26 '12 at 19:01

1 Answers1

1

I would recommend making your design as data-driven as possible; to describe your FSM in data as much as possible.

I implemented a DFA as a two-dimensional table of states and next-states and made a simple iterative motor that read input and changed states according to this table.

This is what the table looked like (fasm):

dfa_chars       db      '=','<','>','!','/',',','*','(',')','{','}','+','-',' ',';',TAB, CR, LF;  N,  A

dfa             db      $07,$04,$05,$06,$0a,$10,$11,$12,$13,$14,$15,$16,$17,$00,$18,$00,$0b,$1d,$08,$09; 0 WS
                db      $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$0b,$1d,$01,$01; 1 //
                db      $02,$02,$02,$02,$02,$02,$03,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02; 2 /*
                db      $02,$02,$02,$02,$1d,$02,$03,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02; 3 /**
                db      $19,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20; 4 <
                db      $1a,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21,$21; 5 >
                db      $1b,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22; 6 !
                db      $1c,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23,$23; 7 =
                db      $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$08,$24; 8 N
                db      $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$09,$09; 9 A+N
                db      $26,$26,$26,$26,$01,$26,$02,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26; a /
                db      $27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$27,$1d,$27,$27; b CR 
Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47