Sure! Here is a long tutorial on how to output binaries from My Assembler – Superscalar 8-Bit CPU #26 using HTML tags:
Output Binaries from My Assembler – Superscalar 8-Bit CPU #26
Welcome to this tutorial on how to output binaries from My Assembler – Superscalar 8-Bit CPU #26. This tutorial will guide you through the process step by step.
Step 1: Write Your Assembly Code
The first step in outputting binaries from My Assembler – Superscalar 8-Bit CPU #26 is to write your assembly code. Make sure your code is correctly formatted and error-free.
Step 2: Assemble Your Code
Next, you will need to assemble your code using My Assembler – Superscalar 8-Bit CPU #26. This will convert your assembly code into machine code.
Step 3: Output the Binaries
Once your code has been successfully assembled, you can now output the binaries. This can be done by using the output command followed by the name of the file where you want to save the binaries.
Step 4: Save the Binaries
After executing the output command, your binaries will be saved in the specified file. Make sure to save the file in a secure location to prevent loss of data.
Step 5: Verify the Binaries
Before using the binaries, it is important to verify that they have been output correctly. You can do this by loading the binaries into a simulator and running them to see if they produce the desired output.
Conclusion
Congratulations! You have successfully output binaries from My Assembler – Superscalar 8-Bit CPU #26. You can now use these binaries in your projects or simulations. If you encounter any issues, feel free to refer back to this tutorial for guidance.
The way you add onto strings within a loop (buffer += bytes(…)) is accidentally quadratic. Every time you append a new thing to the end of a string, you have to allocate a whole new string. This will start to bite with bigger programs. You should use bytearray or a list which you b"".join() at the end.
Very nice! What you might want next is labels (for neater jumps) and macros (so you don't have to repeat yourself all the time).
But maybe a little different approach to the assembler would make it easier to expand.
As it is now you have to declare new operands, arguments, etc. And after that you need to write how to parse those things, how to print them and how to encode them.
Maybe instead of matching a string like "if self.consume_identifier("ldi"): do_stuff" you could take the string as an argument and use a dictionary?
Eg. "mv": [symbol, argument_type, …].
Data in this dictionary could then be interpreted by functions (to parse, print, encode) to automagicaly do the things that you have to add manually.
This way instead of updating your code in several places when adding new opcodes you would just expand the LUT and rest of the code would stay as it was.
Maybe it would even parse larger files faster in the future because it might end up with less if statements to check?
I'm not a programmer (just a PLC wrangler), not a python guru and certainly not a parsing expert, so take it with a grain of salt, but I believe this might be a good improvement.
Very interesting. Right now it's a smaller program, but have you tested how the assembler fares for much larger programs in terms of build speed? Maybe something like a full 128KB program?
brilliant my dude!
Very cool. I am wondering if it could be made as a standalone .exe that you can run. That way, you could just run the program and have all the parsing and output code hidden away.
Also looking forward to getting back to some hardware. Will be interesting to see if you approached it in a similar way to me, particularly the bitwise logic/shift…
I hope you'll continue messing around with Python.
I borrowed your approach on the assembler code and started the project of a very simple and basic parser generator. My previous attempts didn't go well so I have to thank you because this time it worked as expected.
are you going to add labels?