Creating Small Programs with ChatGPT
Due to security-related updates, the hackaday.io web editor was out of service for a while, which delayed my blog updates. However, the project has been steadily progressing.
Anyway, I’ve been using ChatGPT to create Z80 assembler programs. Initially, I thought it would be easy to generate Z80 assembly code. For small programs like a MIDI player, I could create something functional with just minor tweaks. However, when I tested it with slightly more complex programs, I realized things weren’t so straightforward.
For example, there were several issues that made the generated code unusable as is:
1. Lack of knowledge about BDOS calls:
- Registers passed as arguments to BDOS calls were incorrect.
- The wrong arguments were passed to BDOS calls. For instance, in the case of the OPEN BDOS call, the correct argument is HL = FCB (File Control Block) address, but a pointer to the filename string was passed instead.
- It didn’t account for registers that are destroyed by BDOS.
2. Incorrect register saving and restoring:
- The order of PUSH and POP instructions was wrong. It would PUSH AF and BC in order but POP them in the same sequence, leading to errors.
3. Use of instruction combinations that are not valid for Z80.
While ChatGPT often generates reasonably correct code in Python, it seems to struggle more when it comes to Z80 assembler. There is potential to improve this by designing GPTs specifically for Z80 assembly, but this will take time. Therefore, I’ve decided to try splitting up the tasks. I plan to create small programs, have ChatGPT generate Z80 code, point out its mistakes, and gradually refine the code until it works.
I intend to store the programs I create in a GitHub repository, as I believe they will be useful for future program development.
https://github.com/kuwatay/MIDI-FOR-RC2014/tree/main/ai_playground
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.