57 lines
4.3 KiB
Markdown
57 lines
4.3 KiB
Markdown
|
|
# Description of functions inside FASM.DLL
|
|
|
|
### fasm_GetVersion()
|
|
Returns double word containg major version in lower 16 bits, and minor version in the higher 16 bits.
|
|
|
|
### fasm_Assemble(lpSource,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
|
|
Assembles the given source, using the provided memory block as a free storage space(which is also to contain generated output).
|
|
|
|
The lpSource should contain a pointer to zero-ended source text(pansichar).
|
|
|
|
The lpMemory should be a pointer to the memory block and cbMemorySize should contain its size. In the beginning of this memory block the FASM_STATE(TFASM_STATE in Delphi) structure will reside. The assembler doesn't allocate any memory beside this block, if it is not enough for its purposes, the function return FASM_OUT_OF_MEMORY.
|
|
|
|
The nPassesLimit should be a value in range from 1 to 65536, defining the maximum number of passes the assembler can perform in order to generate the code(the recommended value is 100). If the limit is reached, the function return FASM_CANNOT_GENERATE_CODE.
|
|
|
|
The hDisplayPipe should contain handle of the pipe, to which the output of DISPLAY directives will be written. If this parameter is 0, all the display will get discarded.
|
|
|
|
If the assembly is successful, function returns FASM_OK value and fills the output_data and output_length fields of the FASM_STATE structure(which resides at the beginning of provided memory block).
|
|
|
|
If the assembly failed, function returns one of the other general conditions/errors codes(see "General errors and conditions" in Fasm4Delphi.pas). If if error code is FASM_ERROR, it means that an error caused by a specific place in source occured, then the error_code and error_line fields of FASM_STATE are filled, first one with detailed error code(see "Error codes for FASM_ERROR condition" in Fasm4Delphi.pas), and the second one with pointer to a structure containing data about line that caused the error(see "TLINE_HEADER" in Fasm4Delphi.pas).
|
|
|
|
### fasm_AssembleFile(lpSourceFile,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
|
|
This function performs identically to fasm_Assemble, except that it takes the lpSourceFile parameter in place of lpSource, and it shall contain the pointer to zero-ended path to file containing the source to assemble(pansichar).
|
|
|
|
********************************************
|
|
# Description of structures used in FASM.DLL
|
|
|
|
The following structure resides at the beginning of memory block provided to the fasm_Assemble function. The condition field contains the same value as the one returned by function.
|
|
|
|
When function returns FASM_OK condition, the output_length and output_data fields are filled - with pointer to generated output(somewhere within the provided memory block) and the count of bytes stored there.
|
|
|
|
When function returns FASM_ERROR, the error_code is filled with the code of specific error(see "Error codes for FASM_ERROR condition" in Fasm4Delphi.pas) that happened and error_line is a pointer to the LINE_HEADER structure, providing information about the line that caused the error.
|
|
|
|
TFASM_STATE=record
|
|
condition:Int32;
|
|
case byte of
|
|
0:(error_code:Int32;
|
|
error_line:PLINE_HEADER;);
|
|
1:(output_length:cardinal;
|
|
output_data:pointer;);
|
|
end;
|
|
|
|
The following structure has two variants - it either defines the line that was loaded directly from source, or the line that was generated by macroinstruction. First case has the highest bit of line_number set to 0, while the second case has this bit set.
|
|
|
|
In the first case, the file_path field contains pointer to the path of source file(empty string if it's the source that was provided directly to fasm_Assemble function), the line_number is the number of line within that file(starting from 1) and the file_offset field contains the offset within the file where the line starts.
|
|
|
|
In the second case the macro_calling_line field contains the pointer to LINE_HEADER structure for the line which called the macroinstruction, and the macro_line field contains the pointer to LINE_HEADER structure for the line within the definition of macroinstruction, which generated this one.
|
|
|
|
TLINE_HEADER=record
|
|
file_path:PAnsiChar;
|
|
line_number:cardinal;
|
|
case byte of
|
|
0:(file_offset:cardinal);
|
|
1:(macro_calling_line:^TLINE_HEADER;
|
|
macro_line:^TLINE_HEADER;);
|
|
end;
|