Error when attempting to run VMEmulator (Project 11)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Error when attempting to run VMEmulator (Project 11)

SchwerToMe
Whenever I try to run the VMEmulator on my Main.vm for the folder Seven, I get this error:

Exception in thread "Thread-8" java.lang.ArrayIndexOutOfBoundsException: 101
        at Hack.VMEmulator.CPU.popToSegment(Unknown Source)
        at Hack.VMEmulator.CPU.pop(Unknown Source)
        at Hack.VMEmulator.CPU.executeInstruction(Unknown Source)
        at Hack.VMEmulator.VMEmulator.doCommand(Unknown Source)
        at Hack.Controller.HackController.miniStep(Unknown Source)
        at Hack.Controller.HackController.singleStep(Unknown Source)
        at Hack.Controller.HackController.access$000(Unknown Source)
        at Hack.Controller.HackController$FastForwardTask.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)

I inserted all of the .vm files from the OS folder in tools but cannot get passed this error to test my code.
Reply | Threaded
Open this post in threaded view
|

Re: Error when attempting to run VMEmulator (Project 11)

cadet1620
Administrator
SchwerToMe wrote
Whenever I try to run the VMEmulator on my Main.vm for the folder Seven, I get this error:

Exception in thread "Thread-8" java.lang.ArrayIndexOutOfBoundsException: 101
        at Hack.VMEmulator.CPU.popToSegment(Unknown Source)
        at Hack.VMEmulator.CPU.pop(Unknown Source)
        ...
My guess is that your compiler has written a defective "pop" instruction that for some reason isn't being caught during load.

Please post the Main.vm your compiler generated so I can take a look at it.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Error when attempting to run VMEmulator (Project 11)

SchwerToMe
function Main.main 0
pop constant 1
pop constant 2
pop constant 3
call Math.multiply 2
add
call Output.printInt 1
push temp 0
pop constant 0
return


Reply | Threaded
Open this post in threaded view
|

Re: Error when attempting to run VMEmulator (Project 11)

cadet1620
Administrator
SchwerToMe wrote
function Main.main 0
pop constant 1
pop constant 2
pop constant 3
call Math.multiply 2
add
call Output.printInt 1
push temp 0
pop constant 0
return
You have the sense of "push" and "pop" backwards. You push arguments onto the stack and pop return values.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Error when attempting to run VMEmulator (Project 11)

SchwerToMe
Ahh, that makes a lot of sense haha. I went back and switched up my writePop and writePush, so I believe it will work now. Thank you!