flat assembler
Message board for the users of flat assembler.

Index > Main > use32 directive not will add prefix 0x66?

Author
Thread Post new topic Reply to topic
Byte



Joined: 21 Mar 2026
Posts: 8
Byte 27 Mar 2026, 13:50
fasm for DOS
Code:
format binary

_inc_addr   EQU  01000h
use32

ORG 0A000h

Main:
  mov   EAX, 00000010h
  mov   EBX, _inc_addr
  mov   [EBX], EAX
.....
    

Disassembly: (lDebug)
Code:
 B81000     mov  ax, 010
 0000         add  [bx+si], al
 BB0010     mov  bx, 1000
 0000         add  [bx+si], al
 8903         mov  [bp+di], ax
    


Why B81000000, not 66B810000000 ?
Why
Code:
8903         mov  [bp+di], ax    
?
Post 27 Mar 2026, 13:50
View user's profile Send private message Visit poster's website Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 152
Location: Socket on motherboard
Core i7 27 Mar 2026, 15:31
Apparently your disassembler is in 16-bit mode, because this design works correctly.

Code:
format binary
inc_addr  equ 1000h
use32
org 0A000h

start: mov  eax,10h
       mov  ebx,inc_addr
       mov  [ebx],eax
       ret
    


Description:
Filesize: 10.19 KB
Viewed: 42 Time(s)

Bin.png


Post 27 Mar 2026, 15:31
View user's profile Send private message Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 8
Byte 27 Mar 2026, 18:07
Thanks for the reply.
Core i7 wrote:
Apparently your disassembler is in 16-bit mode...

Maybe.
But isn't the 0x66 prefix in the binary code a sign of using a 32-bit register? Shouldn't the compiler add this prefix to define a 32-bit instruction?
Post 27 Mar 2026, 18:07
View user's profile Send private message Visit poster's website Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 152
Location: Socket on motherboard
Core i7 27 Mar 2026, 18:21
it turns out the other way around - the prefix 0x66 is used if you use 16-bit registers in x32 mode.
Code:
format binary
use32
start: mov  eax,100h
       mov  bx,66h
       mov  word[eax],bx
       ret
;------------------------
00000000: B800010000           mov eax, 00000100
00000005: 66BB6600             mov bx, 0066 ;'f'
00000009: 668918               mov [eax], bx
0000000C: C3                   ret 


    
Post 27 Mar 2026, 18:21
View user's profile Send private message Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 152
Location: Socket on motherboard
Core i7 27 Mar 2026, 18:32
By the way, the prefix also works in the opposite direction - if you use 32-bit registers in x16 mode
Code:
format binary
use16
start: mov  eax,100h
       mov  bx,66h
       mov  word[eax],bx
       ret                
;-----------------------
00000000: 66B800010000         mov eax, 00000100
00000006: BB6600               mov bx, 0066 ;'f'
00000009: 678918               mov [eax], bx
0000000C: C3                   ret 
    
Post 27 Mar 2026, 18:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20915
Location: In your JS exploiting you and your system
revolution 27 Mar 2026, 20:31
The CPU has modes.

In 32-bit mode all registers are 32-bit without 0x66, and 16-bit with 0x66.
In 16-bit mode all registers are 16-bit without 0x66, and 32-bit with 0x66.

The disassembler has to be told which mode the CPU is in to correctly disassemble the bytes.

CPU modes are changed by writing to CR0 with MOV or SMSW.

There is also 64-bit mode (long mode) where the 0x66 prefix can make registers either 32-bit or 16-bit, or do nothing, depending on the instruction. This is not confusing in any way. Wink
Post 27 Mar 2026, 20:31
View user's profile Send private message Visit poster's website Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 8
Byte 27 Mar 2026, 20:38
revolution wrote:

In 32-bit mode all registers are 32-bit without 0x66, and 16-bit with 0x66.
In 16-bit mode all registers are 16-bit without 0x66, and 32-bit with 0x66.


Thank you, now I understand.
Post 27 Mar 2026, 20:38
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.