【Solidity Yul Assembly】4.3 | What We Didn't Cover

0xE 发布于 2024-09-11 阅读 3646

在这最后一节,我们将看一些 Yul 中相对较少使用的指令。

虽然在之前的课中我们已经涵盖了 Yul 的大部分常用指令,但这次我们会简要介绍那些使用频率较低的指令,为本系列课程画上句号。

指令 描述
sdiv(x, y) x / y, for signed numbers in two’s complement, 0 if y == 0
smod(x, y) x % y, for signed numbers in two’s complement, 0 if y == 0
slt(x, y) 1 if x < y, 0 otherwise, for signed numbers in two’s complement
sgt(x, y) 1 if x > y, 0 otherwise, for signed numbers in two’s complement
sar(x, y) signed arithmetic shift right y by x bits
signextend(i, x) sign extend from (i*8+7)th bit counting from least significant
addmod(x, y, m) (x + y) % m with arbitrary precision arithmetic, 0 if m == 0
mulmod(x, y, m) (x * y) % m with arbitrary precision arithmetic, 0 if m == 0
byte(n, x) nth byte of x, where the most significant byte is the 0th byte
stop() stop execution, identical to return(0, 0)
invalid() end execution with invalid instruction

1. sdiv(x, y)

  • 执行有符号整数除法,适用于二进制补码形式的有符号数。
  • y == 0,结果返...

剩余50%的内容订阅专栏后可查看

该文章收录于
Solidity Yul Assembly 内联汇编
26 订阅 18 篇内容

0 条评论