是否可以在不使用条件跳转的情况下交换x86汇编中寄存器的最高有效位和最低有效位?

问题描述 投票:0回答:1

这里是如何在 PicoBlaze 组件中完成的:

;This is an example program written by
;Agustin Izaguirre in the issue #9. It
;switches the least significant bit and the
;most significant bit without using jumps.

address 0

load s0,59
output s0,0

;shift and load MSB into an aux register
sl0 s0
output s0, 0
addcy s1, 0

;shift back again and load LSB into an aux register
sr0 s0
output s0, 0
sr0 s0
output s0, 0
addcy s2, 0

;load MSB aux reg into carry so that we can SLA in the bit
sr0 s1
sla s0
output s0, 0

;shift back and load LSB aux reg into carry so that we can SRA in the bit
sl0 s0
output s0, 0
sr0 s2
sra s0 ;bugged line, should be shifting the C flag from the left
output s0, 0

在 x86 汇编中也可以这样做吗?如果是的话,怎么办?

x86 没有与

sra
等效的指令,对吧?那么,不使用条件跳转如何模拟呢?

assembly x86
1个回答
0
投票

如果您想在 EAX 中交换 MSB 和 LSB(或就此而言的任何其他)。

pushf               ;Save FLAGS push ebx            ;Save EBX - used as temp register. bt eax, 0           ;Move EAX[0] to carry. xor ebx, ebx        ;Set EBX to 0. setc bl             ;Set BL according to carry. ror ebx, 1          ;Rotate EBX right to move LSB to MSB bt eax, 31          ;Move EAX[31] to carry. setc bl             ;Set BL according to carry.  and eax, 0xEFFFFFFE ;Set EAX[31] and EAX[0] to 0. xor eax, ebx        ;Set EAX[31] and EAX[0] to EBX[31] and EBX[0], therefore to EAX[0] and EAX[31]. pop ebx             ;Restore EBX. popf                ;Restore FLAGS.

© www.soinside.com 2019 - 2024. All rights reserved.