Re: Bootloader needs fix. See (JMP ...)
Posted: Tue Dec 22, 2015 3:49 am
You need check your assembler documentation to see what syntax is to be used for what forms of instructions. There's nasmdoc.(txt|pdf) for NASM.0b00000000 wrote:I'm starting to think that assembly is not as low level as may be desirable for some situations. It seems that the only way to be sure this is working right in some cases is to inspect the machine code. I wonder if there is a disassembler out there that can give a richer instruction set that differentiates between all the variant of instructions like JMP, MOV etc.alexfru wrote:0b00000000 wrote: Jumps can be absolute far (e.g. jmp sel:ofs), indirect near/far (e.g. jmp eax or jmp [eax] or jmp far [eax] (I hope I got the syntax right)), or near relative only.
The first loads sel into CS. The second changes CS only if it's a far jump with the far address being in memory (e.g. jmp far [eax]). The last doesn't touch CS at all, it merely adds a constant to [R|E]IP. That's why it's relative and that's why it isn't affected by the value in the org directive. If you move code containing a relative jump (short or not), it will still jump by the same amount forwards or backwards. Time to start reading the instruction set reference?
It is true, however, that in certain cases assemblers are too primitive or too smart on the contrary and you have to encode instructions manually. For example, there are instructions like SHL and SAL and intel and AMD are trying to deprecate SAL and some assemblers accept SAL but generate SHL instead. Both do the same thing, but differ in encoding. Deprecating SAL frees an opcode for some other new instruction or subset of instructions. AFAIR, there are a few other duplicates in the instruction set. There are also instructions like MOV r/m8, R8 and MOV r8, r/m8, where r8 is an 8-bit register and r/m8 is either an 8-bit register or an 8-bit memory location. Obviously, there are two different encodings available for MOV AL, AH, which is representable as either. For most purposes it doesn't matter which of the two is used. But if you're trying to use code as data or data as code, you have to consider the issue. The same thing applies to instruction prefixes. There's a certain freedom as to their order of appearance, which typically should make no difference (except, it looks like some older CPUs had bugs w.r.t. the order).