2024-04-09 18:55:24 +02:00

71 lines
2.8 KiB
NASM
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(37, 6, 0, 0, 0, 1, 1, 1, 0, 0, 3, 2, 1, 3, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 0, 0, 2, 2, 1, 0, 0, 2, 2, 2, 3, 1, 3, 1)
ADD(0, 0, r0) // r0 current state in pushdown automaton
ADD(2, 0, r1) // r1 cursor position in input word, (i2 first symbol of input word, i1 length of input word)
ADD(12, 0, r11) // r11 address of stack top
ADD(3, 0, r12) // r12 bottom symbol
ADD(i0, 1, r7) // r7 address registry after last instruction in input
ADD(i1, 2, r10) // r10 last symbol of input word address + 1
ADD(i1, 2, r2) // r2, address first automaton instruction begin state 'q', instruction: (q, a, A, w, q), (reset loop)
JUMP(3) // skip loop increment on 1st iteration
ADD(r6, 1, r2) // r2, address of next instruction to check
JE(r2, r7, 42) // loop condition
ADD(r2, 1, r3) // r3, address instruction read symbol 'a'
ADD(r3, 1, r4) // r4, address instruction read stack symbol 'A'
ADD(r4, 1, r5) // r5, address, instruction word pushed on stack length
ADD(r5, i@r5, r6)
ADD(1, r6, r6) // r6, address, next state q'
JE(r0, i@r2, 2) // current state is the expected state in the instruction
JUMP(-8) // if not, next iteration
JE(i@r1, 2, 4) // read symbol is epsilon
JE(r1, r10, -11) // check if input word has been read, if yes next iteration
JE(i@r3, i@r1, 5) // symbol in input == read symbol
JUMP(-12) // next iteration
JE(i@r4, 2, 6) // read stack symbol is epsilon (read symbol was epsilon)
JE(r@r11, i@r4, 8) // stack top is the expected symbol
JUMP(-15)
JE(i@r4, 2, 10) // read stack symbol is epsilon (read symbol was symbol in input)
JE(r@r11, i@r4, 14) // stack top is the expected symbol
JUMP(-18)
ADD(i@r6, 0, r0) // a=epsilon, A=epsilon, replace current state
JE(i@r5, 0, -22) // restart loop if nothing to write on stack
JUMP(16) // go to copy word on stack
ADD(i@r6, 0, r0) // a=epsilon, A=symbol
JE(i@r5, 0, 2) // check if word to copy is empty
JUMP(13) // go to copy word on stack
JUMP(-27) // restart loop
ADD(i@r6, 0, r0) // a=symbol, A=epsilon
ADD(r1, 1, r1) // move cursor in input word
JE(i@r5, 0, -30) // restart loop
SUB(r11, 1, r11)
JUMP(7) // go to copy word on stack
ADD(i@r6, 0, r0) // a=symbol, A=symbol
ADD(r1, 1, r1) // move cursor in input word
JE(i@r5, 0, 2) // check if word to copy is empty
SUB(r11, 1, r11)
JUMP(2) // go to copy word on stack
JUMP(-38) // restart loop
SUB(r6, 1, r9) // address symbol to copy on stack
JE(r9, r5, -40) // inner loop condition, restart outer loop
ADD(r11, 1, r11)
ADD(i@r9, 0, r@r11)
SUB(r9, 1, r9)
JUMP(-4)
JE(r0, 1, 3) // check if final state
ADD(0, 1, o1) // reject = 1
JUMP(2)
ADD(0, 0, o1) // accept = 0
ADD(0, 1 ,o0) // output size in o1