如何手动(在汇编代码中)更改8086的标志? [英] how to change flags manually (in assembly code) for 8086?

查看:215
本文介绍了如何手动(在汇编代码中)更改8086的标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法手动更改每个标志?还是您必须使用一条命令,使您知道会改变它们的结果?

Is there any way to change every flag manually? Or do you have to use a command with a result that you know will change them?

基本上我正在使用命令RCL,并且我不想一开始就得到1,所以我想将 CF 更改为0,我知道我可以使用以下命令:

Basically I'm working with the command RCL, and I don't want to get 1 at the begining, so I want to change the CF to 0, and I know that I can use commands like:

mov al, 0
shl al, 1

但是我想知道是否还有其他方法可以执行此操作,而不会使用其他命令.

But I want to know if there is any other way to do that, without the use of another commands result.

我还想知道您向我展示的方式是否还可以用于更改所有标志,不仅包括CF,还包括OF,ZF等.

I would also want to know whether the way you may show me, can also be used to change all of the flags, not only CF, but OF, ZF, and so on.

推荐答案

没有任何指令将eflags视为可读写GP寄存器.
引用Intel 1 :

There isn't any instruction that treat eflags as read-write GP-register.
Quoting Intel1:

可以使用特殊指令直接修改EFLAGS寄存器中的某些标志(在 以下各节). 没有说明可以直接检查或修改整个寄存器.
以下指令可用于在过程堆栈或EAX寄存器之间来回移动标志组:
LAHF,SAHF,PUSHF,PUSHFD,POPF和POPFD.将EFLAGS寄存器的内容传送到之后 过程堆栈或EAX寄存器,可以使用处理器的位操作来检查和修改标志 说明(BT,BTS,BTR和BTC).

Some of the flags in the EFLAGS register can be modified directly, using special-purpose instructions (described in the following sections). There are no instructions that allow the whole register to be examined or modified directly.
The following instructions can be used to move groups of flags to and from the procedure stack or the EAX register:
LAHF, SAHF, PUSHF, PUSHFD, POPF, and POPFD. After the contents of the EFLAGS register have been transferred to the procedure stack or EAX register, the flags can be examined and modified using the processor’s bit manipulation instructions (BT, BTS, BTR, and BTC).

eflags寄存器分为三组:状态标志控制标志系统标志.

The eflags register is divided into three groups: Status flags, Control flags and System flags.

状态标志中,只有 CF 可以直接通过clcstccmc进行操作.
没有读取 CF 的指令,但是您可以使用cmovccadcsetcc等指令间接读取它. 所有其他标志都需要使用专门定制的算术指令或通过将eflags Status group 内容对应到ah(使用lahf)或堆栈(使用pushfd)来修改而不是返回到eflags(使用sahfpopfd).

Of the Status flags only the CF can be manipulated directly with clc, stc, cmc.
There is no instruction to read the CF but you can read it indirectly with instructions like cmovcc, adc, setcc. All other flags need to be modified with specially tailored arithmetic instructions or by coping the Status group content of eflags into ah (with lahf) or the stack (with pushfd) and than back into eflags (with sahf or popfd).

控制标志组中,只有 DF 可以用cldstd进行操作.
要读取DF的当前值,您需要使用pushfd.

In the Control flags group there is only DF that can be manipulated with cld and std.
To read the current value of DF you need to use pushfd.

系统标志通常是通过执行一些特权操作(例如切换任务,进入v86模式等)来间接操纵的.
IF 可以直接用clisti进行操作.
所有其他标志只能用pushfd/popfd进行操作.

The System flags are usually manipulated indirectly by performing some privileged operation like switching a task, entering v86 mode and similar.
The IF can be manipulated directly with cli and sti.
All other flags can only be manipulated with pushfd/popfd.

供参考:

  • 在64位模式下,标志寄存器为rflags,但到目前为止保留了高32位,因此rflags被视为eflags.
  • pushfdeflags压入堆栈.还有一个16位版本pushf,该版本仅压入eflags的低16位.与popfd/popf相同.
  • lahf/sahf仅复制状态标志.
  • In 64-bit mode the flag register is rflags but the higher 32 bits are reserved so far, thereby rflags is handled as eflags.
  • pushfd pushes eflags on the stack. There is also a 16-bit version pushf that pushes only the lower 16 bits of eflags. Same for popfd/popf.
  • lahf/sahf only copies the status flags.

1 英特尔手册,第1卷,第3.4.3节.

1 Intel Manuals, Volume 1, Section 3.4.3.

这篇关于如何手动(在汇编代码中)更改8086的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆