properly formatting asm code to make it QB ready

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
mikefromca
Coder
Posts: 39
Joined: Wed Oct 16, 2019 11:28 am

properly formatting asm code to make it QB ready

Post by mikefromca » Sat Jan 02, 2021 3:49 pm

I almost lost it because I spent a few hours trying to understand why a simple piece of assembly code would not work and it turned out after further examination that it wasn't formatted correctly for QB.

I want to know of a simple way to import assembly code into my QB program.

Because my only dos is DOSBOX (I'm running linux), this is what I am currently doing:

1. I write my assembly code
2. I compile it with nasm
3. I extract the data using linux od tool as follows (replacing binary with the filename containing the raw code:

Code: Select all

od -tx1 -w999 binary
4. I highlight and copy all the hex codes
5. I paste them into my program, append a space and use QB mid$ function to extract each hex string and convert it into its actual byte.

The problem is everytime I paste, some codes don't have a space in-between and that's what screws up my program every time!

Is there an easier way to do it where I don't have to manually check to see that all hex codes are evenly spaced? It would be a pain to do this every time I want to change a character in my assembly code.

I would prefer the utility to be run in unix since I have copy and paste functionality there. Maybe there's something better than "od" or maybe I'm not using it perfectly for this purpose.

Thanks

Erik
Veteran
Posts: 57
Joined: Wed Jun 20, 2007 12:31 pm
Location: LI, NY
Contact:

Re: properly formatting asm code to make it QB ready

Post by Erik » Tue Feb 23, 2021 1:29 am

I'd probably write something in python or perl that took the output from od and formatted it correctly to paste into the qb program. Probably could also use a straight bash script but I'm not really familiar with od so I'm not sure how much parsing of the output you need to do and it might just be easier to do within perl or python.

Or maybe even add a placeholder string in the QB code, save the file, and then do the above but have the script replace the placeholder string in the QB source code file with the parsed output from the od parsing script.

mikefromca
Coder
Posts: 39
Joined: Wed Oct 16, 2019 11:28 am

Re: properly formatting asm code to make it QB ready

Post by mikefromca » Fri Feb 26, 2021 2:02 pm

I ended up using xxd at first because it can output my whole thing as a continuous string of hex digits which can take up a few of my screens, but now I ended up making a small C program that formats the binary into a bunch of mkl$ statements for fast loading into QB.

Last thing I want to see is for a QB program to not compile because the "expression is too complex". so It would make sense to use mkl$(zyxw) instead of chr$(w)+chr$(x)+chr$(y)+chr$(z). I figure these things out through experimentation.

Anyone who wants to experiment now can try this:

Code: Select all

cls
if mkl$(&H11223344)=chr$(&H44)+chr$(&H33)+chr$(&H22)+chr$(&H11) then print "equal"
if mkl$(&H11223344)=chr$(&H11)+chr$(&H22)+chr$(&H33)+chr$(&H44) then print "equal"
And the word "equal" will appear once on the screen if the code above is run as-is.

Post Reply