- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
myfunction:
@ Function supports interworking.
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
mul r3, r0, r0
mov r0, r3
mla r0, r1, r0, r2
bx lr
我能够使用以下 C 函数生成除 mov 指令之外的所有内容。
int myfunction(int r0, int r1, int r2, int r3)
{
r3 = r0*r0;
r0 = r3;
r3 = r0;
return (r1*r3)+r2;
}
如何在汇编代码中指示 r3 设置为 r0 的地址?
最佳答案
unsigned int myfunction(unsigned int a, unsigned int b, unsigned int c)
{
return (a*a*b)+c;
}
你的选择将是这样的
00000000 <myfunction>:
0: e52db004 push {r11} ; (str r11, [sp, #-4]!)
4: e28db000 add r11, sp, #0
8: e24dd014 sub sp, sp, #20
c: e50b0008 str r0, [r11, #-8]
10: e50b100c str r1, [r11, #-12]
14: e50b2010 str r2, [r11, #-16]
18: e51b3008 ldr r3, [r11, #-8]
1c: e51b2008 ldr r2, [r11, #-8]
20: e0010392 mul r1, r2, r3
24: e51b200c ldr r2, [r11, #-12]
28: e0000291 mul r0, r1, r2
2c: e51b3010 ldr r3, [r11, #-16]
30: e0803003 add r3, r0, r3
34: e1a00003 mov r0, r3
38: e28bd000 add sp, r11, #0
3c: e49db004 pop {r11} ; (ldr r11, [sp], #4)
40: e12fff1e bx lr
或者这个
00000000 <myfunction>:
0: e0030090 mul r3, r0, r0
4: e0202391 mla r0, r1, r3, r2
8: e12fff1e bx lr
正如您可能已经想到的那样。
mov 永远不应该被编译器后端考虑,因为它只是浪费一条指令。 r3 进入 mla 无需将其放入 r0 然后执行 mla。不太确定如何让编译器做更多的事情。即使这样也不鼓励它
unsigned int fun ( unsigned int a )
{
return(a*a);
}
unsigned int myfunction(unsigned int a, unsigned int b, unsigned int c)
{
return (fun(a)*b)+c;
}
给予
00000000 <fun>:
0: e1a03000 mov r3, r0
4: e0000093 mul r0, r3, r0
8: e12fff1e bx lr
0000000c <myfunction>:
c: e0030090 mul r3, r0, r0
10: e0202391 mla r0, r1, r3, r2
14: e12fff1e bx lr
基本上,如果您不进行优化,您将无法实现您所追求的目标。如果你优化那个 mov 不应该在那里,应该很容易优化掉。
虽然编写高级代码以鼓励编译器输出低级代码的某种程度的操作是可能的,但尝试获得这种准确的输出并不是您应该期望能够做到的事情。
除非你使用内联汇编
asm
(
"mul r3, r0, r0\n"
"mov r0, r3\n"
"mla r0, r1, r0, r2\n"
"bx lr\n"
);
给出你的结果
Disassembly of section .text:
00000000 <.text>:
0: e0030090 mul r3, r0, r0
4: e1a00003 mov r0, r3
8: e0202091 mla r0, r1, r0, r2
c: e12fff1e bx lr
或真正的汇编
mul r3, r0, r0
mov r0, r3
mla r0, r1, r0, r2
bx lr
并将其提供给 gcc 而不是 (arm-whatever-gcc so.s -o so.o)
Disassembly of section .text:
00000000 <.text>:
0: e0030090 mul r3, r0, r0
4: e1a00003 mov r0, r3
8: e0202091 mla r0, r1, r0, r2
c: e12fff1e bx lr
所以从技术上讲,您是在命令行上使用 gcc,但 gcc 会进行一些预处理,然后将其提供给 as。
除非你找到一个核心或者 Rd 和 Rs 必须是相同的寄存器然后可以在 gcc 命令行上指定那个核心/错误/任何东西,否则我看不到 mov 发生,也许,只是也许, clang/llvm 将 fun 和 myfunction 分别编译为字节码,然后组合它们,然后优化,然后输出到目标,然后检查它。我希望在优化或输出中将 mov 优化掉,但你可能会走运。
我犯了一个错误:
unsigned int myfunction(unsigned int a, unsigned int b, unsigned int c)
{
return (a*a*b)+c;
}
arm-linux-gnueabi-gcc --version
arm-linux-gnueabi-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Disassembly of section .text:
00000000 <myfunction>:
0: e0030090 mul r3, r0, r0
4: e1a00003 mov r0, r3
8: e0202091 mla r0, r1, r0, r2
c: e12fff1e bx lr
但是这个
arm-none-eabi-gcc --version
arm-none-eabi-gcc (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
arm-none-eabi-gcc -O2 -c so.c -o so.o
arm-none-eabi-objdump -D so.o
so.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <myfunction>:
0: e0030090 mul r3, r0, r0
4: e0202391 mla r0, r1, r3, r2
8: e12fff1e bx lr
我必须构建一个 7.3 或去找一个。在 5.x.x 和 8.x.x 之间的某个地方,后端发生了变化或者...
请注意,您可能需要在命令行上使用 -mcpu=arm7tdmi 或 -mcpu=arm9tdmi 或 -march=armv4t 或 -march=armv5t,具体取决于编译器内置的默认目标 (cpu/arch)。或者你可能会得到这样的东西
Disassembly of section .text:
00000000 <myfunction>:
0: fb00 f000 mul.w r0, r0, r0
4: fb01 2000 mla r0, r1, r0, r2
8: 4770 bx lr
a: bf00 nop
这个
arm-none-eabi-gcc --version
arm-none-eabi-gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
产生
Disassembly of section .text:
00000000 <myfunction>:
0: e0030090 mul r3, r0, r0
4: e0202391 mla r0, r1, r3, r2
8: e12fff1e bx lr
因此,您可能必须向后工作才能找到它发生更改的版本,源代码更改为导致它的 gcc 并修改 7.3.0 使一些东西不是真正的 7.3.0 但报告为 7.3.0 并输出您的所需的代码。
关于c - 如何使用 ARM gcc 7.3 生成以下 arm 汇编程序输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53660203/
我必须在操作后写入寄存器的目的地和值。 斜体字的字段是我写的。粗体字段(如说明)由我的教授编写。 我曾尝试填写所有字段,但不确定答案。 如果你能告诉我哪里出了问题,我会很高兴,谢谢! :) 最佳答案
bios 中断函数 21h (ah = 1h) 应该从标准输入中读取一个字符并回显它。 我的阅读功能: mov ah, 1h int 21h 所以,如果我按下一个键,它会意识到这一点,
是否有 actionscript 3 的汇编器?类似于 Flasm,但用于 AS3(flasm 是 AS2)。我想将 AS3 程序集编译为独立的 SWF,或将其注入(inject)现有的 SWF。 我
我的汇编代码在调用 xbegin 时引发非法指令。 有什么问题吗? 这是我的代码。 主.c if ( rtm_begin() == 0 ) { //do something. } rtm.S
有人可以用英语解释什么是汇编程序中的相对跳转吗? 最佳答案 它是一个 OP 代码,其操作数将导致执行跳转到相对于当前地址的地址。操作数的值是 偏移 . 假设相对跳转指令保存在地址 0x0005 中,操
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我正在尝试学习 Assembly,并将其用于 64 位。我想用 C 语言编译内联汇编程序,但每次都会出错。 #include int main() { __asm__ ( "mov %rdx, 10
我编写了一个 SIC 汇编程序,除了 I/O 方面外,一切似乎都运行良好。 我已经将目标代码加载到内存中(将 char 格式转换为机器表示形式),但是当我调用 SICRun();执行代码时,我收到一条
我正在学习汇编程序(Nasm、Linux、Ubuntu 16.4、x86_64)并在使用 sys_time 调用时出现问题 (mov eax, 13)。 section .bss time:
在汇编器中: .globl _test _test: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax pushl %eax call printf popl
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我正在阅读杰夫的精彩著作 assembly step by step ,我在第 8 章中展示了一个汇编程序示例,该程序以这种方式从用户那里获取文件: SECTION .bss ;
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 锁定。这个问题及其答案是loc
我有一个简短的问题。我正在使用 MARS 汇编程序(在 MIPS 指令集中编程)并且我有两个 MIPS 文件。一个文件包含我要运行的主要方法,它调用另一个文件中的函数。我的函数前面有 .globl 指
我必须回答以下关于 6502 汇编语言的问题: “在堆栈上,有以下值(顶部元素在前):0x01, 0x02, 0x03, 0x04, 0x05, 0x06地址 0xc000 是指令 jsr 0xABC
我实际上是在学习汇编,我用的是 Gas,但问题是: 1) 我只知道 Intel 语法,我在一个页面上看到使用 intel 语法的 Gas 在某些情况下优化得不是很好。这是正确的还是我错了?我说的是这个
在汇编程序中,我可以使用 MUL 命令并获得 64 位结果 EAX:EDX,我怎样才能在 C 中做同样的事情? http://siyobik.info/index.php?module=x86&id=
作为编译器项目的一部分,我必须为 x86 编写 GNU 汇编程序代码来比较浮点值。我试图找到有关如何在线执行此操作的资源,据我所知,它是这样工作的: 假设我要比较的两个值是浮点堆栈上的唯一值,那么 f
我有一个用 2 个不同的编译器编译的程序: GCC 3.4.4 PowerPC 交叉编译器 GCC 4.8.1 MinGW 编译器 在程序中,我使用了汇编程序指令 .weak 。文档说: 使具有弱绑定
我写了一个简单的 ASM 程序,但 sys_write 没有给出任何输出。我想我对指向 %ecx 的指针犯了一个错误,并且 sys_write 无法访问该字符串 - 但到目前为止我还没有发现我的错误。
我是一名优秀的程序员,十分优秀!