1

I porting a good and I faced the following assembly x86 lines:

mov al, UNLOCK_DATA1    ; load al with byte for the first unlock write
db  67h         ; use 32 bit addressing
mov ds:[esi], al        ; write the command to flash
mov eax, FLASH_ADDRESS  ; load ecx with the base address for flash

This snippet runs in protected mode. So the question is, why the "db 67h" ??? what does it mean ?

user1657666
  • 351
  • 2
  • 9
  • Maybe it is actually 16-bit code. So needs the prefix to use esi instead of si. And you used a 32-bit disassembler so it doesn't know what to do with the prefix. Not unthinkable for flashing code. – Hans Passant Sep 20 '17 at 10:36
  • Did you already search/replace `[si]` with `[esi]` from the 16-bit original source? That would explain why the comment doesn't make sense anymore. (I'm assuming you're porting from 16-bit?) – Peter Cordes Sep 20 '17 at 11:42

2 Answers2

6

The comment is wrong or the code is wrong. This code is either meant to be executed in 16bit mode in which case mov ds:[esi], al would be assembled with the address size override prefix (ASOP) already and the manual override would just give it twos ASOPs (not harmful, but useless), or worse, the code is meant to be executed in 32bit mode and then the ASOP turns the instruction into mov [sword], al (because 16bit ModRM is different) and then it misaligns the instruction stream. Also ds: is useless since it's the default segment for [esi]

By the way the last comment (or code) is also wrong, the flash address is loaded into eax, not ecx.

harold
  • 61,398
  • 6
  • 86
  • 164
5

What means then 32 bits addressing with db opcode on x86 architecture

It is not an opcode, but an address override prefix that changes the size of the address expected by the prefixed instruction.

Since a prefix, if present, corresponds to the first few bytes of a prefixed instruction, the instruction this one-byte prefix (67h) is applied to, is the one following the prefix, that is:

mov ds:[esi], al

why the "db 67h" ??? what does it mean ?

It switches the address size expected by the instruction above (16-bit address to 32-bit and the other way around).

JFMR
  • 23,265
  • 4
  • 52
  • 76
  • 1
    The OP might be missing something more basic: `db` is a "pseudoinstruction" that assembles bytes directly into the output. So `db 67h` puts a `0x67` byte into the machine code at that point. – Peter Cordes Sep 20 '17 at 11:40