Suggestion for type checking in an assembler.

Started by hutch--, September 27, 2005, 01:20:41 AM

Previous topic - Next topic

hutch--

I had an idea for developing assemblers that may make implimenting type checking a bit easier. At some stage in the assembly process the address of a procedure must be obtained and the ideal time to check the argument count and size is while this is being done. In what would normally be a pre-processor pass, this type of information can be loaded in whatever the appropriate data structure may happen to be so that when the actual code has to be checked and expanded into opcodes, it can just grab this info from the data structure and have the address type, arg count and size in one read.

A bare "call" can ignore the argument count data while obtaining the address for the code at that procedure lable while a higher level calling mechanism like "invoke" can test the argument count and size against the prototype from the same source.


    MessageBox  PROTO IMPORT    MessageBoxA.4.4.4.4     ; normal DLL API calls
    MyFunction  PROTO LOCAL     MyFunction.4.4.4.4      ; local function in module
    ExtFunction PROTO EXTERN    ExtFunction.4.4.4.4     ; function in another module
    LibFunction PROTO LIB       LibFunction.4.4.4.4     ; function in a library


The two assemblers I see in the development area that would profit from type checking are FASM and GoAsm and if a capacity of this type could be put in place, it would be a great leap forward for both of them.

Variations of the above suggestion can be things like the source DLL name "kernel32.dll" etc and the calling convention could easily be added to make more information available to the assembler. The idea here is to put as much information as is needed by the assembler in a single prototype so that the user end source code is as natural and uncluttered as possible.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MusicalMike

Type checking is for high level languages and should only be optional in an assembler and the default setting should be off. However, I do aggree that using a preprocessor to do it would be the most affective way to do it. You could even use macros to impliment high level data types. Just a thought.

Randall Hyde

Quote from: MusicalMike on October 23, 2005, 01:53:44 AM
Type checking is for high level languages and should only be optional in an assembler and the default setting should be off. However, I do aggree that using a preprocessor to do it would be the most affective way to do it. You could even use macros to impliment high level data types. Just a thought.

Actually, what Steve is proposing is type checking for HLL-like procedure calls, which isn't assembly language anyway. So in that respect, it's quite optional. With respect to actual machine instructions, the last time I checked, FASM *did* support type checking. That is, it verifies that you're accessing a DWORD memory location when the other operand is a 32-bit register, etc.
Cheers,
Randy Hyde

hutch--

Randy is right here, the sum total of error checking for mnemonics is if there is a matching opcode built into the hardware. High level calls are a different matter and this is what API calls are. Minimum size checking and argument counting is probably best left to the assembler where it encounters high level notation as it already has access to the prototypes and data structures if it is done properly.

Type checking at this level with the associated prototyping and "invoke" style syntax is purely an automated method of the push call syntax that tests the number of argument pushed onto the stack and how big they are. Notions of pure assembler were left behind about 1990 with the introduction of a macro assembler where you actually have the choice of using higher level structures if they will do the job and direct mnemonic coding where it is better suited.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php