Re: Embedding assembler in a language
- From: "bartc" <bartc@xxxxxxxxxx>
- Date: Wed, 18 Nov 2009 22:17:02 GMT
"James Harris" <james.harris.1@xxxxxxxxxxxxxx> wrote in message
news:2aff8423-152e-4921-956f-e914c0e45ba1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
It is generally desirable for a high level language to be independent
of any target hardware but ISTM that sometimes it is useful to write
system-specific modules. For example, these could be specific to a CPU
or to a hardware device. Any disagreement on this?
Not from me. I depend on inline assembler to get the best performance from
my (very) non-optimising compiler.
If the above is accepted, I'd like to ask about the processor as one
potential target. It could be helpful to the programmer to allow him
or her to embed assembler in high level code.
Issues include: appearance (beauty or ugliness), line continuations
and comments (use the HLL's scheme or not), freely mix HLL and
assembler or how to indicate which is being used, independence of a
particular assembler (if an assembler is used as part of code
generation), recognising registers used in the programmer's asm code,
allowing the translator to supply real register names (by allowing the
programmer to use explicit temporaries), accessing HLL symbols from
the asm code, and suchlike.
Is anyone else allowing embedded assembler or have you any thoughts on
how it *should* be done?
Assembler: Nasm for x86. (This used to be quite slow, taking 5 times as long
to assemble the output of my compiler (as x86 source) as compiling the
program. I either don't notice the speed now, or they've made it faster).
Appearance (within my hll syntax), multiline and single line forms:
assem
push eax
inc dword [mem]
end
asm pop esi
(I used to use <...> delimiters for assembler, the above is better.)
Comments: use both ";" (nasm) and "!" (my hll)
Registers: I can't use identifiers in the hll that would clash with
assembler registers, if access from asm is needed.
Identifiers: Assembler can access all hll variable names which are visible
from the current scope. Local frame variables don't need a frame register
for access ([x] is mapped to [ebp+x] as needed).
Function names I think need a "_" prefix when imported or exported
(something to do with the linker; I used to write my own everything, and had
none of this nonsense...).
Labels in the hll are accessed as normal in the assembler. Hll labels are
subject to scope. Asm labels should not clash with hll labels in the current
scope, and have file scope (this is to do with the assembler).
Struct member names are not accessible from the assembler...
The hll itself is compiled to assembler source, and any inline asm is shown
indented in that output. Nasm then assembles the lot, but for any errors that occur, I have to look to the line number in the compiler output (.asm file), then fix in the hll source... but errors are rare.
All in all, I probably wouldn't use stand-alone asm files anymore, the
advantages of a hll are too great. (My first assemblers had a hll framework: function, variable and const declarations just as in a hll, labels with scope local to a function, so that you didn't have to be keep inventing unique names.., identifiers of any length, and so on. You get spoilt.)
--
Bartc
.
- References:
- Embedding assembler in a language
- From: James Harris
- Embedding assembler in a language
- Prev by Date: Re: Embedding assembler in a language
- Next by Date: Re: Embedding assembler in a language
- Previous by thread: Re: Embedding assembler in a language
- Next by thread: Re: Embedding assembler in a language
- Index(es):
Relevant Pages
|