i'm trying to create a microprogrammed function that, given 4 values in the stack, swaps the 3rd and the fourth. I called it "mswap", this is the microcode so far:
mswap1 SP = SP - 1
mswap2 SP = SP - 1
mswap3 MAR = SP - 1
mswap4 rd
mswap5 MAR = H
mswap6 wr
mswap7 MAR = SP
mswap8 rd
mswap9 MAR = SP - 1
mswap10 wr
mswap11 MAR = H
mswap12 rd
mswap13 MAR = SP
mswap14 wr
mswap15 SP = SP + 1
mswap16 SP = SP + 1; goto Main1
And this is an example program:
.main start: BIPUSH 0x39 BIPUSH 0x30 BIPUSH 0x36 BIPUSH 0x35 MSWAP OUT OUT OUT OUT HALT .end-main
It should give an output of 5690 Sad truth, the output is just 56 it's ike i "missed" two pile elements.. Is this due to excessive use of SP = SP -1? It worked just fine when writing a similar function to swap the 2nd and 3rd element