Do programs that use OS files work when compiled to assembly?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Do programs that use OS files work when compiled to assembly?

tungsten
I have finished writing a VM to assembly compiler. It passes all the tests supplied in Projects 7 and 8.
I.e. loading and running the generated assembly files on the CPU Emulator produces the expected behaviour.

However, when I try to run the assembly code I generate for programs that use OS functions like Output.println(), the program does not produce the expected behaviour in the CPU Emulator. (The program works fine in the VM Emulator).

The generated assembly code,
- initializes SP, ARG, and LCL appropriately to 256
- includes the assembly version of the provided OS files
- jumps to Sys.init()

Is there something I'm missing?

Here's the program I am trying to run:

class Main {

        function void main () {

                do Output.printString( "Hi!" );
                return;
        }
}


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do programs that use OS files work when compiled to assembly?

cadet1620
Administrator
You should be able to translate the supplied OS VM files along with your Main.vm and run the result.

First thing to try is to ensure that you have an correct stack frame on entry to Sys.init(). The easiest way to do this is use your VM call code writer to write the bootstrap call:
writeAsm("@256, D=A, @SP, M=D");
writeCall("Sys.init", 0);
writeAsm("@$HALT, ($HALT), 0;JMP");  // Sys.init() shouldn't return, but...

If you haven't done so, have your VM Translator write the VM source code in the ASM Output as comments.
// function Array.new 0
(Array.new)
// push argument 0
    @ARG
    AD=M
    D=M
    @SP
...
// push constant 0
    @SP
...
// gt
    @RIP$2
    D=A

Also very helpful is to have your Assembler generate a listing file that includes the ROM addresses for the instructions and the symbol tables. If you print the ROM and RAM symbols in separate tables it is quite obvious when a (LABEL) is missing because LABEL shows up in the RAM symbols.
             // function Array.new 0
   74        (Array.new)
             // push argument 0
   74     2      @ARG
   75  FC30      AD=M
   76  FC10      D=M
   77     0      @SP
...
             // push constant 0
   81     0      @SP
...
             // gt
   85   126      @RIP$2
   86  EC10      D=A
Note: my assembler writes C-instructions codes in hex, all other numbers in decimal.

Debugging a problem like this can be rather intense.  You might want to move on through projects 9-12 adn come back to this later.

If you want direct help debugging this, email me.

--Mark



   
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do programs that use OS files work when compiled to assembly?

tungsten
Thanks for the reply!

It's good to know that the problem is with my code and not the emulator itself.

I have already done the things you've recommended (with the exception of the listing file). I'll try a couple of more things on my end to troubleshoot.

Loading...