首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >“调用__isoc99_sscanf”是如何工作的?

“调用__isoc99_sscanf”是如何工作的?
EN

Stack Overflow用户
提问于 2014-03-19 03:42:27
回答 2查看 19.9K关注 0票数 1

我非常确定命令行上的输入参数应该是一个字符串,但是当我执行"call __isoc99_sscanf“时,eax寄存器的值为0。我真的不知道“调用__isoc99_sscanf”是如何工作的,但我知道堆栈指针是这样排序的:

.LC1 |V

在"call __isoc99_sscanf“为33之前,.LC1为"Input:%s”和eax,并在内存中保存一个字符串。在任何情况下,调用__isoc99_sscanf的结果都是1?

代码语言:javascript
运行
复制
  .code32
.file   "mystery.c"
.text
.LCO:
.string "Incorrect number of command line arguments given"
.LC1:
.string "Input:%s"
.align 4
.LC2:
.string "Incorrect format for command line argument"
.LC3:
.string "Output: \"%s\"\n"
.text
 .globl main
.type   main, @function
 main:
pushl   %ebp
movl    %esp, %ebp
andl    $-16, %esp
subl    $32, %esp
cmpl    $2, 8(%ebp)
je  .L18
movl    $.LC0, (%esp)
call    puts
movl    $1, %eax
jmp .L19
.L18:
movl    12(%ebp), %eax
addl    $4, %eax
movl    (%eax), %eax
movl    %eax, (%esp)
call    strlen
movl    %eax, %edx
movl    %edx, %eax
sall    $2, %eax
addl    %edx, %eax
movl    %eax, (%esp)
call    malloc
movl    %eax, 28(%esp)
movl    $.LC1, %edx
movl    12(%ebp), %eax
addl    $4, %eax
movl    (%eax), %eax
movl    28(%esp), %ecx
movl    %ecx, 8(%esp)
movl    %edx, 4(%esp)
movl    %eax, (%esp)
call    __isoc99_sscanf
cmpl    $1, %eax
je  .L20
movl    $.LC2, (%esp)
call    puts
movl    $1, %eax
jmp .L19

 .L20:
movl    28(%esp), %eax
movl    %eax, (%esp)
call    foo
movl    $.LC3, %eax
movl    28(%esp), %edx
movl    %edx, 4(%esp)
movl    %eax, (%esp)
call    printf
movl    28(%esp), %eax
movl    %eax, (%esp)
call    free
jmp .L17
.L19:
.L17:
leave
ret
.size   main, .-main
.ident  "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-4)"
.section    .note.GNU-stack,"",@progbits
EN

回答 2

Stack Overflow用户

发布于 2014-03-19 04:01:51

我认为这很有帮助:

代码语言:javascript
运行
复制
   man scanf:

       These  functions  return the number of input items successfully matched
   and assigned, which can be fewer than provided for, or even zero in the
   event of an early matching failure.
票数 1
EN

Stack Overflow用户

发布于 2019-06-09 06:06:15

基本上,它返回您刚刚在计算机中键入的输入总数。如果你在"1 4“中输入两个数字,它会将%rax设置为2。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22489434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档