bl0x / learn-fpga-amaranth

Code for Bruno Levy's learn-fpga tutorial written in Amaranth HDL
BSD 3-Clause "New" or "Revised" License
89 stars 12 forks source link

16_store isn't transitioning to LOAD state #4

Closed wdevore closed 4 months ago

wdevore commented 1 year ago

I noticed that the LOAD state wasn't being reached even though isLoad was active. Looking at Bruno's code it is using ternary operator to select state which, for Amaranth, I believe you can either use Mux or m.Elif. So, I changed the Execute state from:

                with m.If(~isSystem):
                    m.d.sync += pc.eq(nextPc)
                with m.If(isLoad):
                    m.next = "LOAD"
                with m.If(isStore):
                    m.next = "STORE"
                with m.Else():                      <-- this overrides because isStore isn't active
                    m.next = "FETCH_INSTR"

to:

                with m.If(~isSystem):
                    m.d.sync += pc.eq(nextPc)
                with m.If(isLoad):
                    m.next = "LOAD"
                with m.Elif(isStore):                   <---- change is here
                    m.next = "STORE"
                with m.Else():
                    m.next = "FETCH_INSTR"

which makes it work correctly. However, my mind says that m.If should also work. However, the problem is with the m.Else part. This is being triggered because isStore isn't active which overrides the LOAD state!

wdevore commented 1 year ago

LOL. I see that it is correct in #17.

bl0x commented 4 months ago

@wdevore Thank you for reporting this. I must have stumbled over this in the next section and corrected it along the way. It is fixed now.