字符串到程序集中的数组/结构

Doc*_*hom 3 arrays string x86 assembly nasm

我需要做的就是获取用户输入的字符串并将它们放在数组或结构中,但我不断收到错误

有效地址无效

这是什么意思?

代码

section .data
  fName db 'Enter your first name: '
  fNameLen equ $-fName
  lName db 'Enter your last name: '
  lNameLen equ $-lName

  numberOfStruct equ 50
  structSize equ 25
  firstName equ 0
  lastName equ 10


section .bss
  person resb numberOfStruct*structSize

section .text
  global _start

_start:
  mov esi, 0
  input_start:
    mov eax, 4
    mov ebx, 1
    mov ecx, fName
    mov edx, fNameLen
    int 80h

    mov eax, 3
    mov ebx, 0
    lea ecx, [person+structSize*esi+firstName] ;This is where the error appears
    mov edx, 15
    int 80h

    mov eax, 4
    mov ebx, 1
    mov ecx, lName
    mov edx, lNameLen
    int 80h

    mov eax, 3
    mov ebx, 0
    lea ecx, [person+structSize*esi+lastName] ;This is where the error appears
    mov edx, 10
    int 80h

    inc esi

    cmp esi,10
    jl input_start

    exit:
    mov eax, 1
    mov ebx, 0
    int 80h
Run Code Online (Sandbox Code Playgroud)

我完全错了吗?

nrz*_*nrz 5

编辑:添加代码和已编辑的答案以匹配相关更改.

lea ecx, [person+structSize*esi+firstName] ; this is where the error appears

lea ecx, [person+structSize*esi+lastName]   ; this is where the error appears
Run Code Online (Sandbox Code Playgroud)

这两个具有相同的错误:你不能繁殖25,有效的比例因子是1,2,48.

编辑:正如哈罗德指出的那样,imul计算地址是最简单的方法:

 imul ecx,esi,25                    ; ecx == 25*esi
 lea ecx,[ecx+person+firstName]     ; ecx == 25*esi + person + firstName
Run Code Online (Sandbox Code Playgroud)

您还可以使用3来计算地址lea:

 lea ecx,[8*esi]                    ; ecx == 8*esi
 lea ecx,[ecx+2*ecx]                ; ecx == 24*esi
 lea ecx,[ecx+esi+person+firstName] ; ecx == 25*esi + person + firstName
Run Code Online (Sandbox Code Playgroud)

维基百科对所有64位,32位和16位寻址模式都有一个有用的总结.