Am I Writing Assembly Or NASM?

One of the things about assembly, like any other language, is that it is, in part, defined by the assembler. That "div 5" seems awfully strange to me - but I learned assembly using MASM, which has a different syntax. Based on the comments in the tutorial, it looks like the assembler used for that tutorial has some "implied" operands for the instruction, whereas NASM does not, and expects the Intel syntax for the div instruction.

Up vote 2 down vote favorite share g+ share fb share tw.

I'm fed up with this. I've been trying to just get a grip on assembly for awhile, but I feel like I'm coding towards my compiler rather than a language. I've been using this tutorial, and so far it's giving me hell.

I'm using NASM, which may be the problem, but I figured it was the most popular one. I'm simply trying to learn the most general form of assembly, so I decided to learn x86. I keep running into stupid errors, like not being able to increment a variable.

Here's the latest one: not being able to use div. Mov bx, 0; mov cx, 0; jmp start; start: inc cx; mov ax, cx; div 3; Do I need to read two tutorials (one on NASM, and one on x86? ).

Any specific help on this problem? Assembly nasm link|improve this question asked May 20 '10 at 14:32cam1,601421 94% accept rate.

One of the things about assembly, like any other language, is that it is, in part, defined by the assembler. That "div 5" seems awfully strange to me - but I learned assembly using MASM, which has a different syntax. Based on the comments in the tutorial, it looks like the assembler used for that tutorial has some "implied" operands for the instruction, whereas NASM does not, and expects the Intel syntax for the div instruction.

IMHO, you'll be best served by using NASM, but getting a tutorial that's either NASM-specific, or geared to the 'pure' Intel syntax. The Art of Assembly book is a good resource for the Intel syntax.

Think of it this way: x86 architectures really only understand machine code. Assemblers such as NASM will translate from assembly to machine code. So your choice of assembler really does not matter much, as long as it is doing the right translation (which NASM does).

This is analogous to the question of whether to use javac or Eclipse's built-in compiler. They will both compile valid Java. I understand that assemblers also support some extra macros and things like that, but that doesn't seem to apply in this situation.

In addition, the NASM site itself just points you to the Intel documentation for x86 assembly, so you can be sure that it is not expecting some special form of it. Now, I did find this site documenting the DIV instruction, and it has this to say: The 80x86 divide instructions perform a 64/32 division (80386 and later only), a 32/16 division or a 16/8 division. These instructions take the form: div reg For unsigned division div mem idiv reg For signed division idiv mem aad ASCII adjust for division So that would explain your error.

The argument to div can be a register or memory location, but you are giving it a constant.

1 I'd like to add that the div opcode will not accept immediate values (this is what they are called, not "constants"). If you're looking at an opcode reference, immediate operands are referenced by the abbreviation "imm" sometimes followed by a size such as "imm32" of 32-bit, "imm16" for 16 bit, and so on. Several opcodes have odd requirements such as this, but div is the most annoying one.

While probably way more detail than you need, ref.x86asm.net/coder32.html will give you all the instructions and possible operator combinations. – Sparafusile May 20 '10 at 18:04 Sorry, "immediate value". – danben May 20 '10 at 18:40.

Intel does not support an immediate-argument div (only register and memory ones) so whatever tutorial you're using is built for a non-standard assembler.

Ummm, you are using a different dialect of the assembler compiler...the manual clearly stated and explicitly, that its A86 assembler which is a shareware assembler package (gee that's a long time ago! ) Your best bet would be to check out some nasm tutorials instead, incidentally there was a question posted here about the best nasm tutorial.. x86 Assembler regardless of what you're using such as GAS, NASM, A86, TASM, MASM are all generally the same, some may have extra syntactical sugar, others may not...

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions