NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: nobody on June 12, 2008, 08:56:42 PM

Title: LOOP and absolute address
Post by: nobody on June 12, 2008, 08:56:42 PM
Hi

Why does NASM allow to compile
JZ 0x03
but it dosen't allow to compile
LOOP 0x03
?
How can I force NASM to compile
LOOP 0x03
?

I know I should use labels instead an absolute address, but this is a special case and I don't want to use labels.

Also
LOOP $-0x03
doesn't behave like I was expecting, because it translates it to E2FB but should translate to E2FD

Thanks.
Title: Re: LOOP and absolute address
Post by: nobody on June 15, 2008, 06:44:20 AM
> Also
> LOOP $-0x03
> doesn't behave like I was expecting, because it translates it to E2FB but should translate to E2FD

The opcode for LOOP takes one byte.
The operand of LOOP takes one byte.
So you get 0xE2,0xFE.

In addition, you subtracted 0x03.
So you get 0xE2,0xFB.
Title: Re: LOOP and absolute address
Post by: Frank Kotler on June 15, 2008, 11:38:33 AM
The apparent "off by one" is explained by the fact that "$" refers to the address at the *beginning* of the line. Assemble "mov eax, $" - just that - and you can see what's happening.

A label - including "$" - is a "relocatable value" (as opposed to what Nasm calls a "scalar" value... in the error message only...). The reason why "loop" requires a label and "jcc" doesn't is... damned if I know, they're both "relative addresses", I think... Unless you want to delve deep into the nitty-gritty, accept that "that's how Nasm does it".

If you care to say... why don't you want to use labels in this "special case"?

Best,
Frank