Running ASM code

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
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Running ASM code

Post by Zamaster »

Im wondering if anybody out there knows hows I would create a program that takes ASM code like "mov 1, ax" and things of that nature and turns it into HEX and then runs that system HEX code. Uh... so maybe this is kinda a far out question but Im all open for suggestions. I mean like, ASM code to HEX and then run that HEX. And I need my code to do this all by itself, no CALL ABSOLUTE or any assemblers like DEBUG. This is kind've urgent so help'd be great.
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: Running ASM code

Post by moneo »

Zamaster wrote:Im wondering if anybody out there knows hows I would create a program that takes ASM code like "mov 1, ax" and things of that nature and turns it into HEX and then runs that system HEX code. Uh... so maybe this is kinda a far out question but Im all open for suggestions. I mean like, ASM code to HEX and then run that HEX. And I need my code to do this all by itself, no CALL ABSOLUTE or any assemblers like DEBUG. This is kind've urgent so help'd be great.
By HEX code I assume you mean machine language code.
The only way you can get ASM source code converted to HEX machine language is by using some sort of an assembler.

Of course you can also do it the hard way, if you have weeks of time. You can write a QB program which takes ASM source code as input, and generates (translates) it into a near equivalent QB source code. Then you compile this generated QB code and run it. Might even be fun!

But watch out. If the final program doesn't run right, you won't know if it's your translator program or maybe the original ASM code was buggy. You would need to assemble the ASM code and test it to be sure, which kinda defeats the whole purpose.
*****
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

There are several QB programs that run as a frontend to DOS's DEBUG, you can input assembler code to them, they output a chunk of QB code including a loader and the required CALL ABSOLUTE
Check the site of Glenn Stumpf (the Glenn of QB45.com), i think one of the guys of Enhanced Creations (Peter ?Holmberg? ) did another one. As they use DEBUG, I don't know if they work in XP.
RyanKelly
Coder
Posts: 48
Joined: Sun Jan 22, 2006 6:40 pm
Contact:

Post by RyanKelly »

I'm not quite sure what it is that you want to do.

If you want to execute machine code with a QB program then a loader and a call are the bare minimum. The machine instructions have to be placed into memory one way or another and the proccessor won't execute the code unless it is directed to do so. I suggest you take a look at NASM if you don't like the DEBUG front end idea. As for converting assembly language source to machine code, that IS assembling, and any program that does it IS an assembler. If what you're looking for is a library routine that will assemble and execute with one easy command, you're probably out of luck.
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

Im with moneo, thats pretty much what Im trying to do. CREATE A PROGRAM that takes ASM code and converts it to HEX machine code and than runs it without CALL ABOSOLUTE. I know all abou DEBUG and CALL ABSOLUTE and what an assembler is, thats not the issue. I need to create a homade assembler and something that runs the machine code. Any suggestions/thoughts?
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

You cant run machinecode from QB qithout call absolute, get over it..
As for asm->hex, just make your own lookup table... ASM is a very simple language to parse, which is kind of it's point..
I have left this dump.
RyanKelly
Coder
Posts: 48
Joined: Sun Jan 22, 2006 6:40 pm
Contact:

Post by RyanKelly »

The only way around using a CALL ABSOLUTE statement in Qbasic is to shell out to another executable file, which if you're trying to aviod a simple statement, shelling probably isn't attractive either.
If you are absolutely determined to do this, then here is some information that might help you on your wat.


Look here for information on parsing assembly code for an intel machine.
http://www.intel.com/design/pentium4/ma ... m#sdm_vol1

Look here for information on the environment Qbasic is running in (or at least thinks it is). Look especially at the chapters on memory layout and MS-DOS/BIOS
http://www.arl.wustl.edu/~lockwood/clas ... m/toc.html

The source code to Qbasic.exe is out there somewhere. Ask around.
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Zamaster,

Just out of curiosity, why do you need to take ASM code and convert to HEX for running, without using an assembler? If we knew why, then maybe we could come up with a better approach.
*****
RyanKelly
Coder
Posts: 48
Joined: Sun Jan 22, 2006 6:40 pm
Contact:

Post by RyanKelly »

It also occurred to me that you could redirect an interupt vector to execute your code, but this would be very messy.
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

Thanks a bunch everybody. I guess Im pretty much attempting a mini programing language(nothing big) so I can make it work the way I want it to work and have the capacity to do things that Id like it to do easily. Like adding in commands that I thought other languages should have and creating ones I think it should have. And take this code and run it in machine code so it moves as fast as any other language. All the parsing of the language code is very easy for me, my only problem was taking the ASM and converting it to machine HEX and than running it.
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
Post Reply