- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前正在编写一个简单的 C 编译器,它将 .c 文件作为输入并生成汇编代码(X86、AT&T 语法)。我很难传递数组类型的参数并为其生成正确的汇编代码。这是我的输入:
int getIndexOne(int tab[]){
return tab[1];
}
int main_test(void){
int t[3];
t[0] = 0;
t[1] = 1;
t[2] = 2;
return getIndexOne(t);
}
一个相当简单的测试。这是我的输出:
getIndexOne:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 16
movl %esp, %ebp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
movl %edi, -24(%ebp)
movl $1, %eax
movl -24(%ebp, %eax, 8), %eax #trouble over here
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size getIndexOne, .-getIndexOne
falsemain:
.LFB1:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 16
movl %esp, %ebp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
pushl %ebx
subl $120, %esp
movl $2, -32(%ebp)
movl $0, %eax
movl $0, -24(%ebp, %eax, 8)
movl $1, %eax
movl $1, -24(%ebp, %eax, 8)
movl $2, %eax
movl $2, -24(%ebp, %eax, 8)
leal -24(%ebp, %eax, 8), %eax
movl %eax, %edi
call getIndexOne
addl $120, %esp
popl %ebx
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main_test, .-main_test
我无法访问传递的地址(leal 指令)的内容。任何帮助将非常感激。PS:不要担心我的整数的大小,由于其他原因,它们被设置为 8 个字节而不是 4 个字节。
最佳答案
有两个问题,第一个是在为调用 getIndexOne
设置堆栈时:
movl $2, %eax
movl $2, -24(%ebp, %eax, 8)
leal -24(%ebp, %eax, 8), %eax ##<== EAX still holds value of 2!
movl %eax, %edi ##<== wrong address for start of array
您没有在 MOV
命令后清除 EAX
寄存器的内容,因此您要放入 EDI
的地址> 函数调用的注册不是指向数组的开头,而是数组的最后一个元素(即元素值为 2
的第二个索引)。
第二个问题出现在您的 getIndexOne
函数中:
movl %edi, -24(%ebp)
movl $1, %eax
movl -24(%ebp, %eax, 8), %eax
您已将地址存储在堆栈中。这很好,但这也意味着当您从堆栈中检索值时,您将获得一个返回指针,然后必须第二次取消引用该指针。你现在正在做的是你只是从堆栈上的帧指针读回一个值偏移量......这不是数组中的值,因为你没有取消引用你存储在堆栈中的指针。换句话说,如果必须将指针存储在堆栈上,则应将其更改为以下内容(我认为这不是最有效的方法,因为该值已经在 EDI
中,但无论如何):
movl %edi, -24(%ebp) ##<== store pointer to the array on the stack
movl $1, %eax
movl -24(%ebp), %ecx ##<== get the pointer back from the stack
movl (%ecx, %eax, 8), %eax ##<== dereference the pointer
作为旁注,虽然我不确定您的编译器是如何工作的,但我确实认为您使用加载到数组元素中的值同时索引到数组中有点可怕......如果正在加载的值与数组索引不匹配,这会造成相当大的破坏......我猜这是你在两个值匹配时尝试进行的某种优化?
关于c - X86 程序集 - 处理数组类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10637989/
C#内部访问修饰符的定义是内部:只能在包含程序集或友元程序集内访问。所以我的问题是什么是 C# 程序集?在包含程序集或 friend 程序集之内是什么意思?它是否意味着在同一个命名空间或项目中? 最佳
任何人都可以回答以下问题。我正在使用 c# 语言。 我可以将程序集调用为 .ddl 或 .exe 文件吗? 我可以将 Assembly Manifest 称为程序集吗? 程序集、元数据和程序集 lis
我正在从 Python 运行一个 .NET COM 程序集,只有当我将程序集 dll 和依赖项复制到我的 Python 根路径 c:\Python27 时才能使它正常工作。 这是不整洁的,所以我想将
作为世界上任何一名程序员,他/她一生中至少有一次,我正在尝试创建我的“革命性”,新的且唯一的操作系统。 :D 好吧,我正在使用虚拟模拟器(Oracle VM Virtual Box),为此我创建了一个
我创建了以下程序来读取 5 个数字,然后 dumpreg查看输入的数字... INCLUDE Irvine32.inc .data count = 5 scor
如何在保护模式下执行 IN 和 OUT 等受限指令? 我发现它需要足够高的特权级别(CPL)才能执行 IO 指令。我怎样才能在内核模式下运行,拥有 IO 权限或任何其他可能对我有帮助的东西? - 我希
目录 C# 程序集、模块和类型概念及关系 概述 程序集 模块 类型 程序集、模块和类型的关系 总结 引用
构建 maven assembly ,我留下了这样的东西: ${project.basedir} / LICENS
我的应用程序由几个核心程序集和几个扩展/插件程序集组成。为了让 MEF 知道插件必须提供的所有部件,即使我永远不会使用它们的任何部件,我也必须加载这些程序集。这使得应用程序需要更多时间来启动(如果我要
我对我们的构建基础结构有一个非常具体的要求,即将另一个 JAR 依赖项的一些内容复制到我的 Web 应用程序的特定子文件夹中。我们正在使用 maven-assembly-plugin,一个自然的方法是
为什么下面的指令会设置符号标志? mov al,0FEh sub al,2 据我了解,AL寄存器可以保存2^8 - 1或255。0FEh = 254(十进制)。减去 2 叶 252。这似乎是正数。 (
我以前使用过 NUnit,但已经有一段时间了,而且从来没有在这台机器上使用过。我在 Program Files 下解压了 2.4.8 版本,并且在尝试加载测试时不断收到此错误。 Could not l
我说的是一个使用 C# 进行游戏编程的小型游戏引擎。所以,我有一个嵌入单声道运行时的 C++ 应用程序(我称之为“启动器”)。我有一个用 C# 编写的程序集,它是我的游戏引擎类库。启动器按照 Embe
我对汇编相当陌生,并尝试从标准输入读取值(从 C 调用 scanf 函数)并将其打印回标准输出(使用 printf)。 .text readstr: .asciz "%d" #strin
谢谢帮助,我的问题是关于从下面的代码中收到的 ax 值? mov al,22h mov cl,0fdh imul cl 真机结果:ff9a 我的预期:00:9a(通过二进制相乘) 第一个数字是 22h
我正在开发一个汇编程序,该程序将整个文本文件读入缓冲区,然后将其显示在控制台中。它立即显示 24 行(每行的最大长度为 80,因为我使用 80 宽 * 25 高的 dossbox )然后等待用户输入,
我正在使用一个简单的程序集片段,使用 BIOS 作为引导加载程序的一部分将字符打印到屏幕上。这是引导加载程序代码。 [org 0x7c00] [bits 16] %include "a20_check
我只是想知道这段代码是什么意思: XOR EAX,EBX XOR EBX,EAX XOR EAX,EBX 最佳答案 那是 xor swapping . 在寄存器上执行它不会遇到常见的难看的失败案例。
我在新电脑上的 XNA 项目开始出现奇怪的错误。我有两个关于解决方案的项目和一个由它们使用的库。其中一个项目,一个 XNA 游戏项目,运行完美。另一个项目是 WindowsForm 和 XNA 的混合
是的,我正在努力实现类似的目标 __asm__(jmp label;); 其中 label 应替换为内存中保存的字符串值(结构体的字段)。 有没有办法做到这一点(或类似的方法可以让我跳转到运行时确定的
我是一名优秀的程序员,十分优秀!