From a771db2ef8c6a03e83555fece530c55f0b590913 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Tue, 9 Apr 2024 20:23:10 +0200 Subject: [PATCH] fix stack assembly --- src/stack.asm | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/stack.asm b/src/stack.asm index 94fe418..a68f54f 100644 --- a/src/stack.asm +++ b/src/stack.asm @@ -1,4 +1,4 @@ -(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) +(37, 6, 0, 0, 1, 1, 1, 1, 0, 0, 3, 2, 1, 3, 0, 0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 0, 2, 2, 1, 1, 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 @@ -9,7 +9,7 @@ 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 +JE(r2, r7, 44) // 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 @@ -18,45 +18,46 @@ 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, 2, 4) // read symbol is epsilon +JE(r1, r10, -10) // 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 +JE(r@r11, i@r4, 9) // 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 +JE(i@r4, 2, 12) // read stack symbol is epsilon (read symbol was symbol in input) +JE(r@r11, i@r4, 16) // 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 - +SUB(r11, 1, r11) +JE(i@r5, 0, -23) // restart loop if nothing to write on stack +JUMP(17) // go to copy word on stack ADD(i@r6, 0, r0) // a=epsilon, A=symbol +SUB(r11, 1, r11) JE(i@r5, 0, 2) // check if word to copy is empty JUMP(13) // go to copy word on stack -JUMP(-27) // restart loop +JUMP(-29) // 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) +JE(i@r5, 0, -33) // restart loop 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) +JE(i@r5, 0, 2) // check if word to copy is empty JUMP(2) // go to copy word on stack -JUMP(-38) // restart loop +JUMP(-40) // restart loop -SUB(r6, 1, r9) // address symbol to copy on stack -JE(r9, r5, -40) // inner loop condition, restart outer loop + +SUB(r6, 1, r9) // COPY WORD ON STACK, address symbol to copy on stack +JE(r9, r5, -42) // inner loop condition, restart outer loop ADD(r11, 1, r11) ADD(i@r9, 0, r@r11) SUB(r9, 1, r9)