我仍然遇到装配中的结构问题,而且我坚持在结构数组中添加成员。我现在可以添加成员,但不是只在结构数组中添加一个成员,而是覆盖我之前添加的所有成员。所以数组的所有成员都与我添加的最后一个成员类似。
这是数据初始化
menu db 10, '------MENU------', 10, '1. Add Student', 10, '2. Delete Student', 10, '3. Delete All', 10, '4. Search Student', 10, '5. Display All', 10, '6. Exit', 10
menulen equ $-menu
fnamep db 'Enter firstname: '
fnameplen equ $-fnamep
lnamep db 'Enter lastname: '
lnameplen equ $-lnamep
agep db 'Enter age: '
ageplen equ $-agep
unitsp db 'Enter units enrolled: '
unitsplen equ $-unitsp
fullp db 'Sorry, the record is already full.', 10
fullplen equ $-fullp
record db '----Student Record----', 10
recordlen equ $-record
space db ' '
spacelen equ $-space
newline db '', 10
newlinelen equ $-newline
printfname db 'First name: '
printfnamelen equ $-printfname
printlname db 'Last name: '
printlnamelen equ $-printlname
printage db 'Age: '
printagelen equ $-printage
printunits db 'Number of units enrolled: '
printunitslen equ $-printunits
student equ 94
firstname equ 0
firstnamelen equ 40
lastname equ 42
lastnamelen equ 82
age equ 86
units equ 90
array_size equ 5
choice resb 1
x resb array_size*student
size resb 1
temp resb 1
这是添加到结构部分。
cmp byte[size], 5
jge full
mov eax, 4
mov ebx, 1
mov ecx, fnamep
mov edx, fnameplen
int 80h
mov eax, 3
mov ebx, 0
imul ecx,esi,size
lea ecx,[ecx+esi+x+student+firstname]
mov edx, 20
int 80h
mov eax, 4
mov ebx, 1
mov ecx, lnamep
mov edx, lnameplen
int 80h
mov eax, 3
mov ebx, 0
imul ecx,esi,size
lea ecx,[ecx+esi+x+student+lastname]
mov edx, 20
int 80h
mov eax, 4
mov ebx, 1
mov ecx, agep
mov edx, ageplen
int 80h
mov eax, 3
mov ebx, 0
imul ecx,esi,size
lea ecx,[ecx+esi+x+student+age]
mov edx, 3
int 80h
mov eax, 4
mov ebx, 1
mov ecx, unitsp
mov edx, unitsplen
int 80h
mov eax, 3
mov ebx, 0
imul ecx,esi,size
lea ecx,[ecx+esi+x+student+units]
mov edx, 3
int 80h
add byte[size], 1
jmp menustart
这是显示所有部分
mov eax, 4
mov ebx, 1
mov ecx, record
mov edx, recordlen
int 80h
mov al, byte[size]
mov [temp], al
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, newlinelen
int 80h
displayloop:
cmp byte[temp], 0
je menustart
mov eax, 4
mov ebx, 1
mov ecx, printfname
mov edx, printfnamelen
int 80h
mov eax, 4
mov ebx, 1
imul ecx,esi,temp
lea ecx, [ecx+x+student+firstname]
mov edx, 20
int 80h
mov eax, 4
mov ebx, 1
mov ecx, printlname
mov edx, printlnamelen
int 80h
mov eax, 4
mov ebx, 1
imul ecx,esi,temp
lea ecx, [ecx+x+student+lastname]
mov edx, 20
int 80h
mov eax, 4
mov ebx, 1
mov ecx, printage
mov edx, printagelen
int 80h
mov eax, 4
mov ebx, 1
imul ecx,esi,temp
lea ecx, [ecx+x+student+age]
mov edx, 3
int 80h
mov eax, 4
mov ebx, 1
mov ecx, printunits
mov edx, printunitslen
int 80h
mov eax, 4
mov ebx, 1
imul ecx,esi,temp
lea ecx, [ecx+x+student+units]
mov edx, 3
int 80h
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, newlinelen
int 80h
dec byte[temp]
jmp displayloop
答案 0 :(得分:1)
这些说明需要更改代码
imul ecx,esi,size
imul ecx,esi,temp
您将乘以这些变量的地址而不是它们的值!理想情况下,您将使用以下内容:
imul ecx,esi,[size]
imul ecx,esi,[temp]
但这些操作数是不可能的!
我建议使用如下构造:
mov ecx,esi
imul ecx,[size]
mov ecx,esi
imul ecx,[temp]
同时将两个变量的大小更改为DWORD而不是BYTE。 IMUL需要它。