Thread overview
ASM
Feb 13, 2009
Zarathustra
Feb 13, 2009
Daniel Keep
Feb 13, 2009
Zarathustra
Feb 13, 2009
Frits van Bommel
February 13, 2009
I need to make some calculations with asm in D.
Could somebody write how to do this, micro tutorial ;p
x86
Especially inc, dec, add, sub, mul, imul, div, idiv instructions.
Also ja, jb, jg, jl, jo; jc ...
and, or, not, xor,
sal, shl, sar, shr


February 13, 2009
Zarathustra wrote:
> I need to make some calculations with asm in D.
> Could somebody write how to do this, micro tutorial ;p

I find the 'need' hard to believe.  The only way you would need to use assembler is if you're doing something really low level and complicated, in which case a 'micro tutorial' is going to be about as much help as a zeppelin.

> x86
> Especially inc, dec, add, sub, mul, imul, div, idiv instructions.
> Also ja, jb, jg, jl, jo; jc ...
> and, or, not, xor,
> sal, shl, sar, shr

http://digitalmars.com/d/1.0/iasm.html

http://en.wikibooks.org/wiki/X86_Assembly

If that isn't enough information, then you shouldn't be programming in assembly.

  -- Daniel
February 13, 2009
Zarathustra wrote:
> I need to make some calculations with asm in D.
> Could somebody write how to do this, micro tutorial ;p
> x86
> Especially inc, dec, add, sub, mul, imul, div, idiv instructions.
> Also ja, jb, jg, jl, jo; jc ...
> and, or, not, xor,
> sal, shl, sar, shr

First of all: unless you really need to detect overflow or something (or just want to learn about asm), I'd recommend doing calculations in D and letting the compiler worry about what asm to generate. It'll likely be able to do a better job.


Otherwise:

If you look up those instructions (plus MOV) you should be well on your way, if all you want to do is calculations.

The NASM manual used to have a pretty good overview of instructions and what they did (including implicit register usage etc.) in appendix B. Recent versions seem to have cut this from the manual for some reason, but there are still some places where the old version can be found, such as <http://home.comcast.net/~fbkotler/nasmdoc0.html> (thank you, Google).
Besides looking up the instructions themselves in B.4.*, you may also want to look at the first sections (B.1 to B.2.4) for notations used, condition codes, and status flags.

Alternatively, the Intel and AMD processor manuals contain much the same information and pdf files can be downloaded (for free) from their respective websites.

Note that IIRC all these documents document condition code jumps (ja/jb/jg/jl/jo/jc etc.) as Jcc.
February 13, 2009
Thanks a lot :)

Daniel Keep Wrote:

> 
> Zarathustra wrote:
> > I need to make some calculations with asm in D.
> > Could somebody write how to do this, micro tutorial ;p
> 
> I find the 'need' hard to believe.  The only way you would need to use assembler is if you're doing something really low level and complicated, in which case a 'micro tutorial' is going to be about as much help as a zeppelin.
> 
> > x86
> > Especially inc, dec, add, sub, mul, imul, div, idiv instructions.
> > Also ja, jb, jg, jl, jo; jc ...
> > and, or, not, xor,
> > sal, shl, sar, shr
> 
> http://digitalmars.com/d/1.0/iasm.html
> 
> http://en.wikibooks.org/wiki/X86_Assembly
> 
> If that isn't enough information, then you shouldn't be programming in assembly.
> 
>   -- Daniel