News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help Generating an Executable w/out visual

Started by victorvmpm, April 27, 2010, 09:51:51 PM

Previous topic - Next topic

victorvmpm

Hi everyone, I have a question about the project. You'll see i'm building a compiler for my own invented language for my college class and I decided to make my intermediate code masm32 assembler code. My question is:

How can i link the assembler generated code to its compiller without intermediary programs to generate the executable?

regards,
Victor Pereira

dedndave

 :dazzled: ???

could you re-phrase the question ?

ahhhh - i think i understand
we use MASM - microsoft macro-assembler
that program accepts assembly language text files and generates object modules
we then use LINK to convert object modules into executables

jj2007

Quote from: victorvmpm on April 27, 2010, 09:51:51 PM
How can i link the assembler generated code to its compiller without intermediary programs to generate the executable?

Hi Victor,
Welcome to the forum. Your question is not very clear: Do you mean you have an own syntax and want to use Masm to implement it?
Example:

Open_a_file_for_input "MyFile.txt" ; your syntax
v v v v v v
invoke CreateFile, chr$("MyFile.txt"), GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0

Such conversions can be done with Masm's built in macro engine. It is powerful but old and very tricky. You might check MasmBasic, with over 80 "Basic" commands, all realised as macros that call runtime routines.

Please post some examples of your "invented language", so that we can judge better where you are heading.
Regards,
Jochen

victorvmpm

My program is kind of:


start

function add(x:integer, y:integer){
return x + y;
}

function main() returns integer{
print(add(1,2));
return 0;
}

end


the code generated is kind of like this:

.
.
.

jmp main
add:
pop ax
pop bx
add ax, bx
push ax
ret
main:
push 1
push 2
call add
pop ax
;printing interruptions and exit interruption


;Sorry but my assembly is kind of rusted and i'm in unrusting process as well as learnning a new knowledge.

usually the linking is done in microsoft redistributable c++ or something like that. My question is how can create it without it.
System calls would do it.

kind of
asm-C addressSource -options directoroutput

jj2007

Do you have a good reason to stick with 16-bit assembly?

Here are some basic steps to install the Masm32 package and work with it. It's a two-pager that certainly is no substitute for reading the manuals.

victorvmpm

no i don't have to stick with it, but it become kind of an vice when i study assembly language in college. Since it was rare to use the extended registries.

actually the distribution is full 32bits signed.

In the project it would be the extended kind even the float data.


hutch--

Victor,

A 32 bit EXE only has an interfface is you write one for it. You can easily write an app that just runs and does what its supposed to do without sending anything to the screen at all. It would be written more like and old DOS app in that it would not have a message loop or other components designed to maintain a working Window but its simple enouugh to do.

You can also write a console mode app in win32 which writes any output you want to the win32 console CMD.EXE.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

MASM32 uses Microsoft link.exe that is not redistributable under the current EULA, if you plan on distributing your language you will either have to get permission to distribute ML.EXE and LINK.EXE from Microsoft or choose an assembler/linker combination with a more flexible license. One that comes to mind is JWASM which is apparently compatible with MASM so it should not require any rewriting of your code generation engine. For a linker there are many of them out there, PoLink has a fairly liberal license as far as I remember.

Japheth's JWASM site
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Slugsnack

okay, am i correct in saying, you are making a compiler and have done the code generation part. and have generated assembler code and that you have to assemble and link this with external programs such as ml and link and you want to know how to do it so you don't need to use these 2 programs and can have it all done within your compiler ?

redskull

It's been a long while since my compiler class, but IIRC the "intermediate" code is better off being several levels higher than assembly, in a sort of psuedo-code (e.g., still contains IF statments, all "registers" are still virtual, but still one instruction per line), and then translate that into the program bytes.  After all, if you are going straight from the tree to assembly, you might as well just go straight to hex bytes; it's just a table lookup.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

victorvmpm

Is that im using the intermediate code to be a aciclic graph, and what Slugsnack says its correct. If possible i would want to know how to do that part? If not possible I would proportion the links for them to download ML and Link by themselves and by that avoiding problems of redistribution.

And yes it's an table lookup. I'm using stack movement with the lookup. Just by address, is kind of easy when it's implemented.

Slugsnack

If you want to use ML and Link, you can bundle those with your final executable and it'll still end up as one big program. I'm not sure if that violates any copyright agreements though. Otherwise, you could code your own assembler and linker. That's probably a lot more work than you're looking for though.

joemc

I would just CreateProcess JWASM's assembler and PoLink's linker. that way you can pipe the output from it to wherever you want inside of your application.  Maybe an Output Window,  or you could even parse it and make your own output.

dedndave

as long as you don't modify them - i don't see the harm
afterall, it is no different than a batch
this is a great idea - you could make simplified command line parms that cover the types of apps you usually build
with a little tinkering, you could even add ultra-modern 16-bit support - lol

joemc

Quote from: dedndave on May 08, 2010, 02:25:11 AM
as long as you don't modify them - i don't see the harm
afterall, it is no different than a batch
this is a great idea - you could make simplified command line parms that cover the types of apps you usually build
with a little tinkering, you could even add ultra-modern 16-bit support - lol

instead of makeit.bat i use makeit.exe that i wrote.  I suppose i could achieve the same thing with a batch file, but it assembles all *.asm files into seperate /obj/*.obj files than links them into /exe/output.exe.  I plan on adding code to check the date of the asm file vs the obj file and if it has not been touched not to rebuild it, but i got lazy.  If this is what you are looking for victor, I can post the code.