jmp label+n

n Is the number of instructions to jump. When one instruction is compiled how much instructions will it split to? And are all instructions split into the same amount of instructions when compiled?

Im using NASM as a compiler.

Thanks in advance!
Posted on 2004-09-01 13:24:16 by Cookie
i guess you don't understand much of jmp's (sorry if i understood you wrong).

you can't jmp n instructions, you can jmp n bytes.
Posted on 2004-09-01 13:52:45 by lifewire
No, n is the number of BYTES.

And no, all instructions are not the same length. They vary from 1 byte to something like 15 bytes.

This is generally a bad practice. It's difficult to figure out, difficult to read, and if you insert another instruction later, it can really mess things up...

You're better off using another label...

Posted on 2004-09-01 13:54:55 by S/390
Thanks very much!

I was about to mess my computer up :wink:

I have a variable 'a' that contains a number from 1 to 99. Based on that I will perform a certain instruction.

Im currently doing this:
cmp a, 1
je l1
cmp a, 2
je l2
etc ...

How should I do something simmiler to this(Speed is valuable)?

Thanks in advance!
Posted on 2004-09-01 14:49:03 by Cookie
Use a jump table, syntax will be different for each assembler but basically for 3 labels you could try

JumpTable dd offest l1,offset l2, offset l3

mov eax,a ; a being only 0, 1 or 2 (You'd need code to check/ensure this)
jmp [JumpTable+eax*4]






Posted on 2004-09-01 15:00:57 by Eóin
create an array with offsets to the functions and do this:

movzx ecx, byte value
check_if_ecx is a valid number
jmp dword
Posted on 2004-09-01 15:01:59 by lifewire
you must use some sort of debugger to figure out the value of n, because the length of instructions are certainly *not* the same. for example, you could use relative jmp/jccs for stuff like:


jnz $-1
(scans for 0 in string pointer in edi)

$-1 denotes 1 byte from the current position, scasb is a 1 byte instruction, using $ in jmps makes your code look a bit messy.
Posted on 2004-09-01 16:12:00 by Drocon
Thanks very much everyone!
Posted on 2004-09-01 17:29:29 by Cookie