flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [fasmg] 80386.inc assembles POPFD as 9Ch (PUSHFD's opcode)

Author
Thread Post new topic Reply to topic
sunfloro



Joined: 10 Oct 2026
Posts: 6
sunfloro 10 Oct 2026, 17:09
This was discovered while trying some fasmg work with ai, and the report is written by ai.

Subject: 80386.inc assembles POPFD as 9Ch (PUSHFD's opcode)

fasmg version g.l8vn (repository state 126aaa2, 2026-07-19).

In the 80386 instruction set include, POPFD is listed with opcode 9Ch,
which is PUSHFD's opcode. It should be 9Dh.

Where:
core/examples/x86/include/80386.inc, line 2166
packages/x86/include/cpu/80386.inc, line 2192

Both lines read:
iterate <instr,opcode>, cwde,98h, cdq,99h, iretd,0CFh, pushad,60h,
popad,61h, pushfd,9Ch, popfd,9Ch, \

x64.inc (line 2826) and x86-2.inc (line 3171) have popfd,9Dh, which is
correct.

To see it:

include '80386.inc'
use32
pushfd
popfd
pushf
popf
use16
popfd

Bytes produced:
9C 9C 9C 9D 66 9C
Expected:
9C 9D 9C 9D 66 9D

Effect: code that saves the flags with PUSHFD and restores them with
POPFD pushes them a second time instead, so the flags are never
restored and the stack is off by 4 bytes. Writing POPF in 32-bit code
works around it (it gives 9Dh, which pops 32 bits there).

Suggested fix: change popfd,9Ch to popfd,9Dh on both lines.
Post 10 Oct 2026, 17:09
View user's profile Send private message 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.