【发布时间】:2018-08-08 08:46:28
【问题描述】:
这是我的第一个汇编源代码,我想使用 scanf 函数但是这个 ELF 给出了分段错误。
所以,我尝试使用核心转储来解决,但我不能。
使用scanf函数
.section .data
string:
.ascii "input yournumber : \0"
value:
.ascii "your value is %d \n\0"
scanf:
.ascii "%d"
.section .text
.globl _start
_start:
movl %esp, %ebp
subl $4, %esp
pushl $string
call printf
leal -4(%ebp), %ebx
pushl %ebx
pushl $scanf
call scanf
pushl -4(%ebp)
pushl $value
call printf
pushl $0
call exit
【问题讨论】:
-
你是如何构建和运行它的?如果你静态链接它,或者你在 MinGW 上尝试过这个,那么 libc 不会被初始化,因为你是从
_start运行它的。
标签: assembly x86 scanf coredump gnu-assembler