- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
MIPS 跳转寄存器 (JR) 指令经常出现在 C++ 代码的二进制文件中。那么,C++ 中的哪些功能使用了 JR 指令,为什么要使用这些指令?
最佳答案
分支指令只能用于目标地址在编译时已知并且在当前指令的小范围内的情况。您不能(轻松地)使用它来分支到一个静态未知的地址,并且必须在运行时计算/加载,或者跳转到太远的目标
下面是一些必须使用JR
或JALR
的例子(除了JALR
存储要返回的当前地址外,两者完全相同稍后):
跳转到任意地址:静态分支指令不能用于跳转到 32 位或 64 位地址,因为立即数只有 16 或 26 位长。您需要将完整地址加载到寄存器中并使用 JR
/JALR
Function pointers : 调用函数只在运行时才知道,所以显然你需要一些方法来动态调用它
int Add(int a, int b);
int Sub(int a, int b);
int Mul(int a, int b);
int Div(int a, int b);
int (*p[4]) (int x, int y) = { Add, Sub, Mul, Div };
int test_function_pointer(int i, int x, int y) {
return p[i](x, y);
}
shared libraries 中的函数(*.dll, *.so...) 在加载之前对进程也是未知的,因此如果您手动加载这些库(使用 LoadLibrary()
, dlopen()
...),您还将获得地址到一个函数指针,并用 JR
/JALR
调用它们。通常情况下,函数将使用 JALR
调用,但如果它位于函数的末尾并且 tail-call optimization启用后将使用 JR
Vtable在C++等很多OOP语言中也是函数指针的一个例子
struct A {
virtual int getValue() = 0;
};
int test_vtable(A *a) {
return a->getValue() + 1;
}
Jump table (就像在一个大开关 block 中)
typedef int (*func)(int);
int doSomething(func f, int x, int y)
{
switch(x)
{
case 0:
return f(x + y);
case 1:
return f(x + 2*y);
case 2:
return f(2*x + y);
case 3:
return f(x - y);
case 4:
return f(3*x + y);
case 5:
return f(x * y);
case 6:
return f(x);
case 7:
return f(y);
default:
return 3;
}
}
GCC 将上面的代码编译成
doSomething(int (*)(int), int, int):
sltu $2,$5,8
beq $2,$0,$L2 # x >= 8: default case
move $25,$4
lui $2,%hi($L4)
addiu $2,$2,%lo($L4) # load address of $L4 to $2
sll $5,$5,2 # effective address = $L4 + x*4
addu $5,$2,$5
lw $2,0($5)
nop
j $2
nop
$L4:
.word $L11
.word $L5
.word $L6
.word $L7
.word $L8
.word $L9
.word $L10
.word $L11
$L11:
jr $25
move $4,$6
$L9:
sll $4,$6,2
jr $25
addu $4,$4,$6
# ... many more cases below
您可以在 Compiler Explorer 上看到完整的输出
$L4
是一个跳转表,其中包含您要跳转到的位置的地址,也就是此代码段中的 case
block 。它的地址存储在$2
中,需要使用jr
将指令指针移动到该地址。 j $2
如上所示,但我认为这是一个反汇编程序错误,因为 j
无法接收寄存器操作数。一旦你处于正确的情况下,jr
将再次用于调用 f
函数指针
另见 Necessity of J vs. JAL (and JR vs. JALR) in MIPS assembly
关于c++ - C++ 的哪些功能使用了 JR 指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58477929/
我正在使用 C# (asp .net),并且我有一个文本框,它接受在数据库上执行查询的名称条目。 我想使用 IN 子句获取所有可能的值,但在我的 C# 页面中我得到 1 个字符串 例如 'john s
我正在使用 JasperReports 插件生成复杂的报告。它适用于 pdf 文件,但要求是在下载 pdf 之前以 html 格式显示准确的 pdf 报告预览。 我只是想使用 "inline=true
我需要实现自定义反序列化器以正确地将 JSON 解析为 Java 对象。如 documentation 中所述我需要用我的自定义替换默认 JSONReader: JSON j = JSON.std.w
我正在使用 Jackson-jr 来读取我的 JSON 文件。其中之一有点复杂: [ {"test-1":["a","b","c","d"]}, {"test-2":["b","j","d"]},
我想将报 TableView 从纵向更改为横向。 我用过这个方法: jasperPrint.setOrientation(OrientationEnum.LANDSCAPE); 但是它不起作用。 最佳
我想在计划的持续时间对生成的报告(PDF 文件)执行删除。 我已经完成了调度程序部分。唯一要做的就是制作一个方法,该方法具有删除在这些时间之间生成的一堆报告的逻辑。 是否有可用的 JasperRepo
MIPS 跳转寄存器 (JR) 指令经常出现在 C++ 代码的二进制文件中。那么,C++ 中的哪些功能使用了 JR 指令,为什么要使用这些指令? 最佳答案 分支指令只能用于目标地址在编译时已知并且在当
我目前可以通过添加扩展 JComponent 的组件(在其中修改 PaintComponent 方法)来在 Java 中绘制矩形、椭圆形和线条: public class myComponent ex
我有一个 jasper 报告列表控件,我从后端获取动态值。我需要在两列中显示列表值。 我该怎么做? 这是我的jr:list代码
我正在尝试使用 jackson-jr 作为 jackson-databind 的轻量级替代品。我的目标是解析 JSON 字符串,并在遇到重复键时让解析器失败。据我了解该库,以下内容可能会引发异常: S
我正在做一个 Controller ,以便在用户需要时显示 JR 报告。我正在使用 Maven + Eclipse + JasperReports API。 该项目编译良好,但是当我尝试访问我的 Co
我已经写了一个实现归并排序算法的 MIPS 子程序(代码在帖子的最后)。它接收指向数组的指针及其大小。排序它,不要返回任何东西。 我一直在调试它,修复了一些错误,并且由于子例程在达到基本情况(大小为
我是 jasper 报告的新手,我不知道如何将 JRBeanCollectionDataSource 仅传递给子报表,将 JREmptyDataSource 传递给 master ireport。 我
我尝试在 Linux 中显示 JR 报告。我刚才出错了,生产大约在几个小时后。首先它在 Windows 上运行良好。我的应用服务器是GlassFish 2.1,操作系统是RedHat,框架是Strut
所以我目前正在开发我的第一个 meteor 应用程序,这将是一个很好的移动应用程序。由于它只能在移动设备上运行,我想使用 Junior Framework实现经典应用程序 + 幻灯片切换的外观和感觉。
我正在创建一个 jasper 报告,其中包含标题和元素列表。我通过 JRBeanCollectionDataSource 将自定义对象的数组列表传递给 jasper 报告我已使用列表组件。但它总是返回
我正在编写一些自修改代码,我想从 MIPS 调用 C 函数(将其称为 foo)。 我已将 foo、&foo 的 mem add 加载到 $t1 中。现在我jr/jalr $t1。 C 会将 $ra 设
我是 MAC 用户,我购买这款手机专门用于应用测试。到目前为止,设置它的说明(提供的链接)只能让我了解,因为在我应该点击以打开开发人员选项的设置中,这个特定手机上没有明确称为“内部版本号”的选择选项。
我必须做这样的事情:对于名字字段,如果该字段由两个或多个单词组成,如果最后一个单词包含以下之一,则将最后一个单词删除到后缀字段中: II, III, IV, V, VI, VII, VIII, ESQ
我是一名优秀的程序员,十分优秀!