本文介绍了进位标志可以保持什么值,以及如何在 x86 程序集中检查其状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 进位标志可以容纳哪些值?它只是 0x00 和 0x01(布尔值)还是 16(或 32/64)位像其他 CPU 寄存器一样?

  1. What values can the carry flag hold? Is it just 0x00 and 0x01 (boolean) or is it 16 (or 32/64) bits like the rest of the CPU registers?

我如何查看它的状态?我是否只是像使用 cmp cf, 0x00 这样的普通 CPU 寄存器那样使用它,然后使用 jg ?

How do I check its status? Do I just use it like a normal CPU register like cmp cf, 0x00 then jg <jump destination>?

我正在编写一个迷你操作系统.将它用于我自己的目的是一种好习惯,还是应该为 CPU 保留独占写入权限,而我所做的只是从中读取?

I am writing a mini-OS. Is it good practice to use it for my own purposes, or should it be reserved for exclusive write-permissions for the CPU, and all I do is read from it?

推荐答案

这是一个标志,它只能保持真或假(技术上是 1 或 0,但有效如图所示).

It's a flag, it can only hold true or false (technically 1 or 0, but effectively the truth values as shown).

就使用而言,不,您不要将其与某物进行比较,然后使用 jg.它与其他标志处于相同抽象级别,因此您可以使用:

In terms of using it, no, you don't compare it to something and then use jg. It's at the same level of abstraction as other flags so you can just use:

jc somewhere         ; jump if carry flag is set
jnc somewhere_else   ; jump if carry flag is not set

它是由某些指令自动设置的,例如,要添加两个值并检测进位,您可以使用以下内容:

It's set automatically by certain instructions so, for example, to add two values and detect carry, you can use something like:

add ax,bx
jc  too_big

而且,虽然它主要由这些指令设置,但您也可以使用 stc(设置)、clc(清除)和 cmc(补充).例如,如果您正在进入一个循环,在该循环中将值结转到下一次迭代,那么事先清除它通常很有用.

And, while it's mostly set by those instructions, you can also do it manually with stc (set), clc (clear) and cmc (complement). For example, it's often useful to clear it before-hand if you're entering a loop where the value is carried forward to the next iteration.

这篇关于进位标志可以保持什么值,以及如何在 x86 程序集中检查其状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:42
查看更多