Testing "Xxx.hack" into "Assembler"

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

Testing "Xxx.hack" into "Assembler"

rauls

Hello!
I'm doing project 6. The task without programming. I translated the program "maxL.asm" into binary code. In the notepad (text file) named "Program.hack"

The problem is that when I load into the "Assembler" my file
 "Program.hack" to compare a message appears in "Error file" line 0 does not contain exactly 16 characters.

So I can not load my "Program.hack" file to verify that it is correct.

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Testing "Xxx.hack" into "Assembler"

cadet1620
Administrator
Check for text encoding. The tools don't like Unicode. Most text editors default to saving files in UTF-8. You need to save your files in ANSI (ASCII) encoding.

Also check for leading or trailing tabs or spaces.

If you can't get it working, feel free to send me your file.

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

Re: Testing "Xxx.hack" into "Assembler"

rauls
MaxL.hack 



Follows the upload of my file. (Maxl.hack)
I already coded for "ANSI"

But the "error file" message remains.

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Testing "Xxx.hack" into "Assembler"

rauls

 
OK!
Sorted out.
I coded for ASCII.
Now the "error file" disappears.

I can compare my "Maxl.hack" file by loading it into the assembler.
Anyway ...

Thanks a lot for the help.
Reply | Threaded
Open this post in threaded view
|

Re: Testing "Xxx.hack" into "Assembler"

Jack Draak
In reply to this post by cadet1620
Hmm... Something about this is not working for me....

When I try to load my .hack files into the CPU Emulator I get the error, "illegal character".

I modified my assembler (I'm using C#, for better or for worse) and what I'm reading here:

https://www.arclab.com/en/kb/csharp/read-write-text-file-ansi-utf8-unicode.html

...seems to be telling me to use Encoding.Default for ANSI output (I've also tried Unicode and UTF8, fwiw, all with the same result)

        File.WriteAllText(fileOut, ThisOutput(outStream), System.Text.Encoding.Default);

        // convert List of words into a string for output to a file
        private static string ThisOutput(List<String> list)
        {
            using (StringWriter stream_out = new StringWriter())
            {
                string line;
                int i = 0;
                while (i < list.Count)
                {
                    line = list[i];
                    stream_out.Write(line + "\r\n");
                    i++;
                }
                return stream_out.ToString();
            }
        }

Is my currently failing solution... Any pointers would be appreciated, thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Testing "Xxx.hack" into "Assembler"

cadet1620
Administrator
The "Illegal character" error occurs when the CPUEmulator reads a character that is not '0' or '1' when it is expecting a binary ASCII number.

The UTF-8 byte order mark is a common cause of this problem, but I've also seen students' assemblers that accidentally include a null character '\0' at the beginning or end of the lines, which will also cause this problem.

Because you must write ASCII, I would not trust "Encoding.Default".  I don't know C#, but a quick search shows "Encoding.ASCII" is available.

If you can't find a solution, post a ZIP or RAR archive containing the failing .hack file.

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

Re: Testing "Xxx.hack" into "Assembler"

Jack Draak
Thanks for the feedback!  I've switched to explicit ASCII encoding, which is working, but the problem was actually being caused by the way I was initializing the empty string for address codes.

It's a bit funny, I changed it from "\0" to "" and suddenly my output contained empty lines for address codes.  I fixed it by initializing the variable with a blank space, " ", but then before I return the encoded word I pass the string through my StripWhitespace() function.  Et viola!  It's not exactly pretty, but it works for now.

Now I can use the Assembler compare feature as it was intended, thank you again!