开发者

Design patterns in Assembly language

Basically, are there any?

I'm tempted to think they do exist. For example, a template method can be implemented as a series of "jumps", where the target of a jump is specified "externally". Singleton will be just a well-known location in memory/code, etc.

I'm by no means an assembly expert, so these examples might turn out to be completely impossible, b开发者_如何学Pythonut still.


Assembly language is more about "tricks" than design patterns. While high-level design patterns can still be thought of and brought into play, most assembly guys are more concerned with clock cycles and exploiting tricks of instructions.

For example, in x86 it is quicker to do xor eax, eax, than it is to do mov eax, 0.

The point I am making (thanks for the downvotes!) is that with Assembly Language you want to focus more on the minor detail than you do the big design picture. Just as you wouldn't focus on fine details of execution speed in a high level language.


First definition on Google: "a design pattern is a general reusable solution to a commonly occurring problem in software design".

By that standard I'd say they most definitely exist.

First one that springs to mind is a jump table.


Applicable to OO design patterns:

People usually implement higher level language constructs like inheritance polymorphism and use them as building blocks to implement their intentions in design patterns. But then, maybe it's easier to find a c or c++ compiler for the platform and use design patterns without hassle of implementing basic oo functionality.


If there are no design patterns for all the layers then you should think about design patents. Because saying "i just write the code to the very details" is false modesty for "there are so much details to handle that the industrialisation of the software engineering process is too clever to fit this narrow stackoverflow".


A possible example would be how to write a loop: Why are loops always compiled into "do...while" style (tail jump)?

Or SIMD vectorizing something idempotent (like a memcpy with non-overlapping src, dst) using an unaligned first and last vector, and aligned vectors for the main loop body. If the alignment and/or sizes aren't all multiples of 16 bytes, there's partial overlap, but that's fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜