我正在尝试调用 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
关于assembly - 访问汇编中缓冲区的第一个字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56208619/