0

I was reading the source code of LILO for a project and I stumbled across this line

mov dh, [d_dev](bp)

I wished to know what the mov instruction is doing here, I know that if it is

mov dh, [d_dev] 

then the value pointed by d_dev is placed in dh but what happens with the (bp).

Any help would be appreciated.

Source Link: https://github.com/a2o/lilo/blob/master/src/first.S line 205

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
systolicDrake
  • 101
  • 1
  • 6
  • What macro preprocessing happens before this assembles? Is this GAS `.att_syntax noprefix` or something? In that case `(bp)` would be a memory operand with the BP register as the base, and `[d_dev]` as the displacement. Presumably `[d_dev]` is replaced by a macro preprocessor like M4 or something. Can you link to the source file where this appears? – Peter Cordes Jun 18 '18 at 17:26
  • 1
    @PeterCordes I believe early versions of LILO used AS86 as its assembler (not GNU's as) – Michael Petch Jun 18 '18 at 17:36
  • @PeterCordes I should have been a bit more specific though. The actual syntax is parsed by as86 in Minix syntax compatibility mode. In Minix the meaning of square brackets and parentheses is reversed. So it would be more like `mov dh, (d_dev)[bp]` in normal AS86 syntax or `mov dh, [d_dev+bp]` in NASM syntax – Michael Petch Jun 18 '18 at 18:04
  • @MichaelPetch: thanks, I didn't know anything about AS86, but that's the meaning I was able to infer from context after the OP linked the whole file. – Peter Cordes Jun 18 '18 at 18:28

1 Answers1

1

LILO still uses AS86 (note the get common.s /* as86 "include" will bypass the CPP */) line at the top.

AS86 apparently has op dst, src operand order, but memory-operand syntax looks like a cross between AT&T and Intel. [d_dev](bp) is AT&T d_dev(%bp) or NASM [d_dev + bp], i.e. base register = BP, with the address of d_dev as a disp8 or disp16.

An earlier line in the same file zeros BP:

xor     bp,bp       ! shorted addressing

Presumably d_dev is an offset that fits in a signed 8-bit displacement. Yes, the label appears pretty soon after a .org 6, so its address is a small displacement, and mov dh, [bp + disp8] is only a 3 byte instruction, vs. mov dh, [disp16] being a 4 byte instruction (opcode + modrm + disp16).

So mov dh, [d_dev](bp) does the same thing as mov dh, [d_dev], but in one less byte of machine code, because BP=0.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847