[英]How do I write rotation Operation for the Risc-V(Assembly Language) Do we have any command for it like we have have in 8086?
[英]How do I write NOT Operation for the Risc-V (Assembly Language)?
如何为 Risc-V(汇编语言)编写 NOT 操作? 如果没有 NOT 指令,你如何实现同样的目标?
与 MIPS 和其他一些架构一样,RISC V 没有为许多事情提供专用指令,包括二元一元运算,因为这些运算可以使用它们的三元格式进行,通常使用x0
作为第三个操作数,但有时是常数1
或-1
作为第三个操作数。
为方便起见,汇编器将接受用于这些一元操作(和其他操作)的所谓伪指令。 这是常见的 RISC V 伪指令及其替换的列表。
要执行更复杂或未列出的事情,请使用数学和逻辑以及尽可能多的指令。
li rd, immediate | Myriad sequences | Load immediate
mv rd, rs | addi rd, rs, 0 | Copy register
not rd, rs | xori rd, rs, -1 | One’s complement
neg rd, rs | sub rd, x0, rs | Two’s complement
negw rd, rs | subw rd, x0, rs | Two’s complement word
sext.w rd, rs | addiw rd, rs, 0 | Sign extend word
seqz rd, rs | sltiu rd, rs, 1 | Set if = zero
snez rd, rs | sltu rd, x0, rs | Set if ̸= zero
sltz rd, rs | slt rd, rs, x0 | Set if < zero
sgtz rd, rs | slt rd, x0, rs | Set if > zero
beqz rs, offset | beq rs, x0, offset | Branch if = zero
bnez rs, offset | bne rs, x0, offset | Branch if ̸= zero
blez rs, offset | bge x0, rs, offset | Branch if ≤ zero
bgez rs, offset | bge rs, x0, offset | Branch if ≥ zero
bltz rs, offset | blt rs, x0, offset | Branch if < zero
bgtz rs, offset | blt x0, rs, offset | Branch if > zero
bgt rs, rt, offset | blt rt, rs, offset | Branch if >
ble rs, rt, offset | bge rt, rs, offset | Branch if ≤
bgtu rs, rt, offset | bltu rt, rs, offset | Branch if >, unsigned
bleu rs, rt, offset | bgeu rt, rs, offset | Branch if ≤, unsigned
j offset | jal x0, offset | Jump
jal offset | jal x1, offset | Jump and link
jr rs | jalr x0, 0(rs) | Jump register
jalr rs | jalr x1, 0(rs) | Jump and link register
ret | jalr x0, 0(x1) | Return from subroutine
call aa | auipc x1, aa[31 : 12] + aa[11] | Call far-away subroutine
| jalr x1, aa[11:0](x1) | (two instructions)
tail aa | auipc x6, aa[31 : 12] + aa[11] | Tail call far-away subroutine
| jalr x0, aa[11:0](x6) | (also two instructions)
顺便说一句,有一个名为 LC-3 的教育处理器。 它只有三个算术/逻辑运算: ADD
, AND
, NOT
。 然而,学生需要编写执行乘法、除法、模数、 XOR
、 OR
等运算的代码;! 乘法和除法/模数是通过循环完成的; XOR
和OR
是使用逻辑序列完成的——我们知道所有 boolean 操作只能使用 NAND 门进行,因此(仅) AND
& NOT
是原始但足够的。
我最喜欢该处理器上的XOR
序列来自以下公式:
(A AND NOT B) + (NOT A AND B)
这里的+
字面上是ADD
,它可以代替OR
因为两个操作数永远不会同时为 1,因此不会发生从一位 position 到另一位的进位,在这种情况下, ADD
和OR
是相等的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.