Think I did something wrong

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

Think I did something wrong

Jason
I managed to make it through project 8 without having to ask here for help (even though I read just about every previous post and got lots of help from them) and I have a translator that passes all of the given tests. However, at about 3am last night my brain woke me up with the realization that I had made an error somewhere in my translator. I probably should have gotten up and written it down or something because it all made sense then, not so much now many hours later when I'm looking at the code.

As I said, all given tests pass, but I think I'm doing something wrong with my label names. I add an index and increment it during the writeCall. I'm thinking there's a problem with that, but honestly can't remember what my brain told me the problem was last night!

Also, I appear to generate way too much code and could use a little help in optimizing. As a test, I copied the OS .vm files to a new directory, added a Main.vm that was posted in another thread and ran the translator. Couldn't tell you if it works though because it made a 49576 line asm file witch the cpu emulator says is just too big.

I've temporarily linked my 08 project folder at http://themadhouse.org/tecs/ if someone would like to poke around and let me know what I may have wrong. This includes the workspace directory where my translator  source resides. If the admins think it prudent I can password protect this, but I don't plan on leaving it up after my problem is solved. Your call.

I feel pretty good at how far I've come with understanding the assembly code, but I still don't have any idea how to optimize things.

Thanks

Jason
Reply | Threaded
Open this post in threaded view
|

Re: Think I did something wrong

Jason
update:

I've added a directory called myAsm in which I am re-writing my raw asm for each function using some techniques mentioned in other threads. This way, if someone wants to help out, they don't have to pour through a bunch of assembled code to find problems.

Thanks again,
Jason
Reply | Threaded
Open this post in threaded view
|

Re: Think I did something wrong

cadet1620
Administrator
In reply to this post by Jason
I have no problem with your code being temporarily available so that you can get help.

I won't be able to take a look at it until later tonight or perhaps tomorrow.

I use the same technique to generate the labels for if/then/else and return IPs. I have a routine named UniqueLabel() that returns "_nnnnn" where nnnnn is an incrementing number.

The biggest single optimization you can make is to use a common routine for your call and return code.

Since the return vm command doesn't have a parameter, the code is the same for every return.  Write a label, say "(_return)" at the beginning of the return code the first time you write it. All other times all you need to do jump to _return.

For call you need to be a bit more clever; you need to pass the the target function address, the number of parameters and the return IP to your common call code.  You can load these values into the temporary registers, R13-R15, and then jump to _call followed by the return IP label.

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

Re: Think I did something wrong

Jason
I've changed a bunch of things to eliminate the constant changing of SP as mentioned in another post. A question on that though. All of my translated files fail the comparison. Now, logically, I would assume that since part of the comparison is the expectation of what SP should be, making this change should cause them to fail. Is this correct or have I messed up the code entirely?

Has anyone written any test for code with the modified SP?

Just for reference, the changes I mad cause SP to point not to the next empty slot, but rather to the current top of the heap. When adding something, I increment SP and place data there, when doing a unary operation, I don't change SP at all, and with binary ops, it decrements once.
Reply | Threaded
Open this post in threaded view
|

Re: Think I did something wrong

cadet1620
Administrator
Jason wrote
Just for reference, the changes I mad cause SP to point not to the next empty slot, but rather to the current top of the heap. When adding something, I increment SP and place data there, when doing a unary operation, I don't change SP at all, and with binary ops, it decrements once.
Yes, this is what's causing the tests to fail. They expect the SP to point to the next available location.

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

Re: Think I did something wrong

Jason
Ok, I put it back and found another way to save some lines of code using the code you showed me here. My return is still messed up at the moment though, I'm going to have to spend some time figuring it out tomorrow.

Jason
Reply | Threaded
Open this post in threaded view
|

Re: Think I did something wrong

cadet1620
Administrator
One thing that can help a lot in debugging your generated assembly code is to write the VM source in the .asm file as // comments.
    // File: test.vm
    // function test.foo 11
(test.foo)
@11
D=-A
(_1)
...
D=D+1;JLT
    // push constant 7
@7
D=A
On my VM translator, the comments are optional based on a -d command line option.

--Mark