How to read and write x86 flags registers directly?

前端 未结 6 891
执笔经年
执笔经年 2020-11-29 05:07

From what I\'ve read, seems like there are 9 different flags. Is it possible to read/change them directly? I know I can know for example if the zero flag is set after doing

6条回答
  •  庸人自扰
    2020-11-29 05:46

    • LAHF: loads status flags into AH
    • Copies the low byte of the EFLAGS register including Sign, Zero, and Carry flags.
    • Save a copy of the flags in a variable for safekeeping

      .data
       saveflags BYTE ? 
      .code 
       lahf ; load flags into AH 
       mov saveflags,ah ; save them into a variable 
      
    • SAHF: stores AH into status flags

    • Copies AH into the low byte of the EFLAGS register
    • Retrieve the value of flags stored earlier

      .code
       mov ah, saveflags ; load save flags into AH 
       sahf ; copy into flags register 
      

提交回复
热议问题