我需要做的就是获取用户输入的字符串并将它们放入数组或结构中,但我不断收到错误
Invalid effective address
这是什么意思?
代码
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
我做错了吗?
最佳答案
编辑:添加了代码并编辑了答案以匹配问题中的更改。
lea ecx, [person+structSize*esi+firstName] ; this is where the error appears
lea ecx, [person+structSize*esi+lastName] ; this is where the error appears
两者都有相同的错误:不能与 25
相乘,有效的缩放因子为 1
、2
、4
和 8
。
编辑:正如 Harold 指出的,imul
是计算地址的最简单方法:
imul ecx,esi,25 ; ecx == 25*esi
lea ecx,[ecx+person+firstName] ; ecx == 25*esi + person + firstName
您还可以使用 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
Wikipedia对所有 64 位、32 位和 16 位寻址模式进行了有用的总结。
关于arrays - 在汇编中将字符串转换为数组/结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12482434/