小编Kat*_*atz的帖子

汇编:这个程序中movl data_items(,%edi,4), %eax的作用是什么

该程序(来自 Jonathan Bartlett 的《从头开始编程》)循环访问内存中存储的所有数字,并将.long最大的数字放入 EBX 寄存器中,以便在程序完成时查看。

.section .data
data_items:
    .long 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 0

.section .text
.globl _start

_start:
    movl $0, %edi
    movl data_items (,%edi,4), %eax
    movl %eax, %ebx
start_loop:
    cmpl $0, %eax
    je loop_exit
    incl %edi
    movl data_items (,%edi,4), %eax
    cmpl %ebx, %eax
    jle start_loop
    movl %eax, %ebx
    jmp start_loop
loop_exit:
    movl $1, %eax
    int $0x80
Run Code Online (Sandbox Code Playgroud)

我不确定(,%edi,4)这个程序的目的。我读到逗号是为了分隔,而 4 是为了提醒我们的计算机数据项中的每个数字都是 4 个字节长。既然我们已经用.long声明了每个数字都是4个字节,为什么我们还需要在这里再声明一次呢?另外,有人可以更详细地解释这两个逗号在这种情况下的用途吗?

x86 assembly att addressing-mode array-indexing

3
推荐指数
1
解决办法
1864
查看次数

标签 统计

addressing-mode ×1

array-indexing ×1

assembly ×1

att ×1

x86 ×1