pvt*_*ame 1 x86 assembly predicate
我正在写一个代码,计算一个字符串中有多少个单词。如何使用je增加寄存器?
例如:
cmp a[bx+1],00h
je inc cx
Run Code Online (Sandbox Code Playgroud)
je
是有条件的跳跃。与ARM不同,x86不能基于任意条件直接断言另一条指令。没有单一的机器指令可以执行类似je inc cx
ARM风格的操作inceq cx
。
相反,您需要通过有条件地分支到其他指令上来自己构建逻辑。
如果要在两个数字比较相等的情况下增加寄存器,请尝试以下操作:
cmp a[bx + 1], 00h ; compare numbers
jne .noteq ; if they are different, skip
inc cx ; the increment
.noteq:
Run Code Online (Sandbox Code Playgroud)
如果您具有386兼容的CPU,则可以使用无分支选项。它需要一个额外的寄存器:
xor ax, ax ; clear register
cmp a[bx + 1], 00h ; compare numbers
sete al ; set al = 1 if the numbers are equal
add cx, ax ; increment cx if numbers are equal
Run Code Online (Sandbox Code Playgroud)
与PPro兼容的CPU具有cmovcc
和fcmovcc
。与setcc
(386),jcc
(8086)和loopcc
(8086)一起,它们是x86唯一的条件检查指令。(条件位存储在FLAGS寄存器中,您可以在其中直接访问它们,但这通常不太方便。)
归档时间: |
|
查看次数: |
54 次 |
最近记录: |