assembly - 访问汇编中缓冲区的第一个字节?
问题描述
我正在尝试调用 isdigit,为此我需要缓冲区的第一个字节,其定义如下。
...
.equ ARRAYSIZE, 20
.section ".bss"
buffer:
.skip ARRAYSIZE
...
input:
pushl $buffer
pushl $scanFormat
call scanf
addl $8, %esp
因此,缓冲区被分配了一个 20 字节的内存空间,我使用 scanf 输入了一些值,如输入所示。
现在我想访问前 4 个字节以调用 isdigit。我怎样才能访问它们?
我最初的猜测是使用 movl 缓冲区,%eax,因为 eax 寄存器是 4 字节大小,并将前 4 个字节存储在缓冲区中。但我不确定它是如何工作的。
请让我知道我是否只能访问缓冲区的前 4 个字节,或者任何其他将 isdigit 应用于前 4 个字节的方法。谢谢你。
解决方案
您需要将isdigit分别应用于这 4 个字节。您可以使用执行 4 次迭代的循环从缓冲区中一一获取它们。计数器设置在%ecx
寄存器中,指向缓冲区的指针设置在%esi
寄存器中。
movl $4, %ecx ; Counter
movl $buffer, %esi ; Pointer
More:
movsbl (%esi), %eax ; Get next byte sign-extending it
push %eax
call isdigit
addl $4, %esp
...
incl %esi ; Advance the pointer
decl %ecx ; Decrement the counter
jnz More ; Continu while counter not exhausted
或者
xorl %esi, %esi ; Offset start at 0
More:
movsbl buffer(%esi), %eax ; Get next byte sign-extending it
push %eax
call isdigit
addl $4, %esp
...
incl %esi ; Advance the offset
cmpl $4, %esi ; Test for max offset
jb More ; Continu while offset not max-ed
推荐阅读
- ios - 提取 4 位与 2 位蓝牙 HEX 数据,为什么相同的方法会导致错误
- linux - 如何更新手册页数据库?
- compiler-errors - 我无法运行 Kade Engine 的最后一个命令。它错误
- c# - 如何将数据表中的数据加载到 resx 文件中?
- c# - C# 覆盖不同的子参数(相同的父级)?
- gstreamer - 如何使用 GStreamer RTSP 服务器创建多个管道
- typescript - Angular12+Firebase:TypeError:无法读取 ProductCardComponent.getQuantity 处未定义的属性“未定义”
- powershell - 是否可以强制 PowerShell cmdlet 在远程会话中使用 TLS 1.2 运行?
- c - 无法使用 wasmer 执行独立的 webassembly 文件
- git - 是否可以重置已提交的部分文件?