use for the inline assembler

Mike Parker aldacron71 at yahoo.com
Sat Jul 22 18:26:50 PDT 2006


llee wrote:
> I've been working with the inline assembler for the past few weeks, trying to
> learn the in's and out's of assembly code. I've managed to gain a basic
> understanding of it's syntax, but a major question still remains; what can it be
> used for? Over this time period I've spent a lot of time reviewing other
> programs and code. Every one of them seem to rely on interrupts services. Yet
> everytime I try to use these services I find myself commiting an 'access
> violation'. If windows no longer provides access to bios and dos services, how
> can user input be accessed, or output displayed? If a programmer is forced to
> use the standard D input  and output functions with assembly code intersparsed,
> what advantage does it have over pure D code? 
> I'm looking to gain something from using assembly, but I'm not sure that there's
> anything worth while. 
> 
> 
Inline assembly is called 'inline' exactly because it is intended to be 
interspersed with your D (or C, or C++, or any other language that 
supports it) code. If someone wanted to write a pure assembly program, 
why would you do so with a D compiler?

The idea behind inline assembly is primarily one of optimization. While 
most optimization should be done at the algorithmic level, there are 
times when that is not enough. For example, you can't use MMX, SSE, 
SSE2, and such directly from D code. In order to get at those, you have 
to use assembly. There may be other times when algorithmic optimization 
doesn't result in the performance you need, or maybe the compiler isn't 
putting out efficient instructions for a performance critical block of code.



More information about the Digitalmars-d mailing list