What are some hidden-features of x86
Assembly Language? What Tips and Tricks do you have for working with x86
Assembly language?
views:
870answers:
4Assembly rocked the world of its era because it freed programmers from manually writing machine code. We got lots of complex instruction sets to help programmers do multiple things in one instruction. There isn't anything hidden or powerful that cannot be accomplished with a compiler. We are at billions of cycles per second, so a instruction that does something in 1 cycle instead of 2 or 3 is not very exciting anymore.
Almost each processor has undocumented instructions and or registers. But they are often undocumented for a reason so its often not wise to use them.
Formerly secret hidden-feature revealed...
Now that computers are so fast, they are hard to actually stop. A single halt instruction is unreliable, and so just calling halt()
in a high level language isn't necessarily going to work if it's an old library routine.
Therefore, the following only-in-assembler design pattern is suggested:
_halt::
halt
halt
halt
halt
jmp _halt
halt ; fill branch delay slot
One of the interesting things about assembly language is that the smallest and/or fastest instructions are not necessarily intuitive. For example, to set the EAX register to zero, instead of mov eax,0
, you use xor eax,eax
which is fewer bytes but does the same thing at the same speed.
See Any reason to do a “xor eax, eax”? for more details on this one.