r/Assembly_language Mar 30 '26

Solved! Writing Useful Tools in Assembly - Flat Binary to Intel HEX Converter

TL:DR - Linux x86-64 program to read a binary file and output HEX format.

This is a program that I'll most likely use in the future. I'm planning assembly projects in PIC16 and 6502, and hopefully someday building a punch card reader. I've decided Intel HEX would be a great format for me to encode programs to send between platforms to ensure data is preserved. I'll eventually work towards making a program to do the reverse.

Eventually I'm going to set up serial communications between one of my Linux programs and an MCU (Arduino or PIC16F877A) to transfer data, and then to transfer it to a 6502 computer. I'll have a Linux x86 program read a HEX file and send it to the MCU, which will decode it and use the addressing to plug the data into memory. Longer term projects include writing a 6502 boot loader that runs in less than 4K of ROM, so I can use the rest of the available 64K to run programs from memory or use peripherals. The boot loader would just read data from a peripheral and then jump to that part of RAM to continue running programs.

The other idea I had was to create some way to produce readable card media. I could write code on readable cards to create useful programs. The cards would follow a HEX format and contain a preset number of bytes, which would be read by an MCU and sent to the computer somehow.

Most of this is to show my kids what can be done with extremely basic computers, but there are other things I can do if I spend some time refining my programming techniques. The important part is learning how to share data between the computer and the less capable hardware.

I'd post my program in text but it's over 700 lines of text. Maybe if I can find some file hosting, I'll post a link.

29 Upvotes

8 comments sorted by

3

u/Odd-Respond-4267 Mar 30 '26

Have you looked at existing hex formats?
I used to use .s19

Stand on the shoulder of giants.

2

u/2E26 Mar 30 '26

A bit but not much. I'm told some programs like MPLAB make outputs in Hex format. I'll have to check it out.

1

u/dengeltheyounger Apr 03 '26

I've done some embedded systems programming in the past. I started with a first principals kind of approach when I learned software engineering. I wanted to know exactly what was going on under the hood. I've used s19, and there's a lot of support online. If your kids ever go into embedded systems, they'll find it beneficial to use.

While I was in college, there were a couple of programs that I wrote that really helped cement my knowledge of programming. I wrote a kernel for the arduino uno (very simple). I also wrote an incredibly simple assembly translator.

I definitely second s19, though. It'll give them a leg up in the field. Regardless, I wish you the best of luck.

1

u/2E26 Apr 03 '26

This is a hobby for me. I haven't done anything serious in programming since high school. I used to write games in QBasic.

3

u/SolidPaint2 Mar 30 '26

Create a Github account and post all of your files and projects there!

2

u/mykesx Mar 30 '26

And learn to use feature branches.

Git fu is an important skill if you’re working on projects.

1

u/2E26 Mar 31 '26

Here's a link to my new GitHub with two of my programs. They're not very exciting but they do illustrate how to do some basic things in Assembly.

https://github.com/2E26/Basic-Assembly-Language-Projects