标志寄存器(二)

目录

一、abc指令

 二、sbb指令

三、cmp指令

四、DF标志和串传送指令

五、pushf和popf

六、标志寄存器在debug中的表示


 

 

一、abc指令

1.abc是带进位加法指令,它利用了CF位上记录的进位值。

2.指令格式:abc 操作对象1,操作对象2

3.功能:操作对象1=操作对象1+操作对象2+CF。

4.例如:指令 abc ax,bx 实现的功能是:(ax)=(ax)+(bx)+CF

 二、sbb指令

1.sbb是带错位减法指令,它利用了CF位上记录的错位值。

2.指令格式:sbb 操作对象1,操作对象2。

3.功能:操作对象1=操作对象1-操作对象2-CF。

4.例如:sbb ax,bx实现的功能是:(ax)=(ax)-(bx)-CF。

三、cmp指令

1.cmp是比较指令,cmp的功能相当于减法指令,只是不保存结果。cmp指令执行后,将对标志寄存器产生影响。

2.cmp指令格式:cmp 操作对象1,操作对象2。

3.功能:计算操作对象1-操作对象2但不保存结果,仅仅根据计算结果对标志寄存器进行设置。

4.例如:指令cmp ax,bx,做(ax)-(ax)的运算结果为0,但并不在ax中保存,仅影响flag相关各位。指令执行后:zf=1,pf=1,sf=0,cf=0,of=0。

四、DF标志和串传送指令

1.falg的第10位是DF,方向标志位。在串处理指令中,控制每次操作后si,di的递减。

df=0 每次操作后si,di递减

df=1 每次操作后si,di递减

2.我们来看下面这条指串传输指令。

格式:movsb

功能:执行movsb指令相当于进行下面几步操作:
(1)((es)*16+(di))=((ds)*16+si)

(2)如果df=0 则:

(si)=(si)+1

(di)=(di)+1

五、pushf和popf

1.pushf的功能是将标志寄存器的值压栈,而popf是从栈中弹出数据,送入标志寄存器当中。

2.pushf和popf,为直接访问标志寄存器提供了一种方法。

六、标志寄存器在debug中的表示

在Debug中,标志寄存器是按照有意义的各个标志位单独表示的。

 

 

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
下面是一个简单的 VHDL 代码实现 16 位 ALU,可以支持加、减、与、或、非、逻辑左移、逻辑右移、算数左移、算数右移、循环左移、循环右移、和 ADC/SBB 指令。 ```vhdl library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity alu_16bit is Port ( a : in STD_LOGIC_VECTOR (15 downto 0); b : in STD_LOGIC_VECTOR (15 downto 0); op : in STD_LOGIC_VECTOR (3 downto 0); carry_in : in STD_LOGIC; result : out STD_LOGIC_VECTOR (15 downto 0); carry_out : out STD_LOGIC; zero : out STD_LOGIC); end alu_16bit; architecture Behavioral of alu_16bit is signal temp : unsigned(16 downto 0); signal carry : std_logic; begin process(a, b, op, carry_in) begin case op is when "0000" => -- ADD temp <= unsigned(a) + unsigned(b) + unsigned(carry_in); carry <= temp(16); result <= std_logic_vector(temp(15 downto 0)); when "0001" => -- SUB temp <= unsigned(a) - unsigned(b) - unsigned(not carry_in); carry <= not temp(16); result <= std_logic_vector(temp(15 downto 0)); when "0010" => -- AND result <= a and b; when "0011" => -- OR result <= a or b; when "0100" => -- NOT result <= not a; when "0101" => -- LSL result <= std_logic_vector(shift_left(unsigned(a), to_integer(unsigned(b)))); when "0110" => -- LSR result <= std_logic_vector(shift_right(unsigned(a), to_integer(unsigned(b)))); when "0111" => -- ASL temp <= unsigned(a) * power(2, to_integer(unsigned(b))); carry <= temp(16); result <= std_logic_vector(temp(15 downto 0)); when "1000" => -- ASR temp <= shift_right(unsigned(a), to_integer(unsigned(b))); carry <= temp(0); result <= std_logic_vector(temp(15 downto 0)); when "1001" => -- ROL temp <= shift_left(unsigned(a), to_integer(unsigned(b))) or shift_right(unsigned(a), 16 - to_integer(unsigned(b))); carry <= temp(16); result <= std_logic_vector(temp(15 downto 0)); when "1010" => -- ROR temp <= shift_right(unsigned(a), to_integer(unsigned(b))) or shift_left(unsigned(a), 16 - to_integer(unsigned(b))); carry <= temp(0); result <= std_logic_vector(temp(15 downto 0)); when "1011" => -- ADC temp <= unsigned(a) + unsigned(b) + unsigned(carry_in); carry <= temp(16); result <= std_logic_vector(temp(15 downto 0)); when "1100" => -- SBB temp <= unsigned(a) - unsigned(b) - unsigned(not carry_in); carry <= not temp(16); result <= std_logic_vector(temp(15 downto 0)); when others => -- not a valid operation result <= (others => 'X'); end case; if result = (others => '0') then zero <= '1'; else zero <= '0'; end if; carry_out <= carry; end process; end Behavioral; ``` 需要注意的是,这只是一个简单的实现,可能在一些情况下需要进行修改或优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

*ppsuc*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值