- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个汇编程序和一个 C 程序; C 程序将调用一个用汇编编写的函数。环境为Ubuntu 18.04LTS x64。
它是为 32 位 x86 设计的,将由 NASM 编译,但它不能传递正确的参数。
为了简化问题,我只是更改了函数以获得a 和b 的总和。
extern int FindPattern(int a,int b);
int result;
result=FindPattern(1,1);
printf("%d\n",result);
global FindPattern
section .text
FindPattern:
push ebp
push esi
push edi
push ebx
push edx
push ecx
mov ebp,esp
mov esi,[ebp+8] ; a
mov edi,[ebp+12] ; b
mov eax,0
add eax,esi
add eax,edi ; return a+b
pop ecx
pop edx
pop ebx
pop edi
pop esi
pop ebp
ret
该函数只是将a 和b 相加,并返回总和。总和应该是 2,但是我得到了一个随机数,如 1449041840。看来程序集没有得到正确的参数。
代码有什么问题,我该如何解决?
# Makefile
cc=gcc
ASMBIN=nasm
all : asm cc link
asm:
$(ASMBIN) -o findpattern.o -f elf32 -l findpattern.lst findpattern.asm
cc :
$(cc) -m32 -c -g -O0 -fpack-struct graph_io.c
link :
$(cc) -m32 -o graph_io findpattern.o graph_io.o
clean:
rm *.o
rm graph_io
rm findpattern.lst
最佳答案
您的堆栈框架设置有误。 推 ebp; mov ebp, esp
必须在任何其他堆栈移动发生之前发出。
通过在设置 ebp
之前将其他内容压入堆栈,您已经将 ebp
设置为指向与平常不同的位置,从而导致所有偏移量不同。要解决这个问题,首先设置栈帧,然后压入剩余的寄存器:
global FindPattern
section .text
FindPattern:
push ebp
mov ebp,esp
push esi
push edi
push ebx
push edx
push ecx
mov esi,[ebp+8] ; a
mov edi,[ebp+12] ; b
mov eax,0
add eax,esi
add eax,edi ; return a+b
pop ecx
pop edx
pop ebx
pop edi
pop esi
pop ebp
ret
关于c - 在推送/弹出其他寄存器时从堆栈访问相对于 EBP 的函数参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65905009/
回车和有什么区别 push ebp mov ebp, esp sub esp, imm 说明?有性能差异吗?如果是这样,哪个更快,为什么编译器总是使用后者? 与离开和类似 mov esp, eb
我有一个简单的代码: void func() { func2(); } 我省略了 func2 和 main 的实现,因为它们无关紧要。然后我用windbg跟踪汇编,下面是执行“func2()”
这两条指令在gcc为x86机器生成的汇编代码中产生了什么影响: push %ebp movl %esp, %ebp 最佳答案 unwind的解释是字面上的事实(尽管有一个较小的方向性错误),但没有解释
我们为什么push ebp作为汇编函数的被调用者中的第一个操作? 我明白了,那么我们使用mov edi, [ebp+8]获取传入的变量,但是我们的 esp已经指向调用者函数的返回地址。我们可以使用 m
我正在阅读这本书 Hacking: The Art of Exploitation, 2nd Edition 并在简单的 C 程序中 #include int main() { int i;
我正在 Uni 学习计算机体系结构和汇编编程类(class)。前段时间我们学习了如何在 ASM 中编写函数并从 C 中调用它们。但是有一件事我不明白——在每个 ASM 函数的开头,讲师总是进行两条指令
我有这个 C 函数: void hello(char * src) { char buffer[64]; strcpy(buffer, src); printf("Hello %s !\n
我正在努力为考试而学习,并查看堆栈溢出的东西,我希望有人能为我解决一些问题。 (假设这是在 32 位系统上,所以所有地址都是 4 个字节。另外我正在从 C 函数研究它,所以引用的任何代码都来自 C)
我目前正在学习英特尔处理器的汇编。既然堆栈“向下增长”,为什么我们必须添加才能访问特定元素 [ebp + 8] ;; This will access the first param 我知道我们必须跳
我一直在研究 StackGuard 和类似的技术,以及英特尔关于“控制流执行”(基本上是影子堆栈)的新技术预览,此处:https://software.intel.com/sites/default/
我在这里需要一些帮助,我是汇编语言的新手。到目前为止我做了什么。汇编代码: extern puts section .data test: db 'test',0 section .text
当明确告知编译器不要使用 ebp 作为堆栈帧指针时,如何实现堆栈回溯? 最佳答案 这个问题的答案只出现在对 What is the purpose of the EBP frame pointer r
我正在尝试通过 EBP 从被调用方获取调用方中定义的局部变量。这应该是可能的,但如果不是,请解释原因。 这是我现在的代码: #include void TEST(int a, int b, int
我想通过查看堆栈上的原始数据将堆栈划分为堆栈帧。我想通过找到保存的 EBP 指针的“链表”来做到这一点。 我可以假设(标准和常用的)C 编译器(例如 gcc)将始终在函数序言中的函数调用中更新和保存
对于这个简单的代码: void main(){ char buf[12]; buf[11]='\xff'; puts(buf); } 我使用 gdb 调试此代码并获取其堆栈信息,如下所示:
前段时间我在尝试写汇编例程并将其与 C 程序链接,我发现我可以跳过标准的 C 调用序言结语 push ebp mov ebp, esp (sub esp, 4 ...
我正在编写一个汇编程序和一个 C 程序; C 程序将调用一个用汇编编写的函数。环境为Ubuntu 18.04LTS x64。 它是为 32 位 x86 设计的,将由 NASM 编译,但它不能传递正确的
是的,我敢肯定这是隐含地回答了很多次,但我似乎无法完全理解它。 如果您有一个 (x86) 堆栈跟踪(例如,在 WinDbg 中查看它),并且您查看了寄存器,那么 EBP 和 ESP 值相距 x 字节意
我对以下代码中的 EBP、ESP 和堆栈帧有一些疑问。 为什么我们要从 esp 中减去 28? main 中有两个局部变量 x 和 y。那么我们为什么不减去 8呢? 我们不把值从右(或上)到左(或下)
当我使用disas时在gdb 。我可能会得到这样的东西。 (gdb) disas bar Dump of assembler code for function bar: 0x08048e84
我是一名优秀的程序员,十分优秀!