How to translate these VM commands?

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

How to translate these VM commands?

riverfish
This post was updated on .
I've hit a roadblock in project 7 and it's mainly down to the fact that I haven't the clear idea how to translate VM commands into assembly code.

Take these VM commands for example:
push constant 111
push constant 333
push constant 888
pop static 8

This is what I had in mind:
(deleted)


But absolutely no clue if this is the correct implementation or not. Please help!
Reply | Threaded
Open this post in threaded view
|

Re: How to translate these VM commands?

cadet1620
Administrator
Those look correct.

The way to test them is to put those commands preceded by @256, D=A, @SP, M=D, into a .asm file.
Load it into the CPUEmulator.
Single-step through it and see if it did the right thing.

static.8 should pop into RAM[16] since it is the only RAM variable.


You will likely be doing a lot of single-step testing of code snippets as you implement the more complex VM commands.


Please edit your post to remove the ASM code.

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

Re: How to translate these VM commands?

riverfish
Thanks a ton Cadet.

I assume that the initialisation with @256 is to initialise the stack pointer ?
Reply | Threaded
Open this post in threaded view
|

Re: How to translate these VM commands?

cadet1620
Administrator
riverfish wrote
I assume that the initialisation with @256 is to initialise the stack pointer ?
Yes, that is initializing the stack.

It's part of the "bootstrap" code that you will write in project 8.

--Mark