2014-11-30 1 views
0

어셈블리의 구조체에 여전히 문제가 있습니다. 구조체 배열 내부에 멤버를 추가해야합니다. 지금 멤버를 추가 할 수 있지만 구조체 배열에 멤버를 추가하는 대신 이전에 추가 한 멤버를 모두 덮어 씁니다. 배열의 모든 멤버는 내가 추가 한 마지막 멤버와 비슷합니다.구조체 x8086 배열에 멤버를 추가하는 방법

여기 여기 데이터를 초기화

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 

그리고 여기에는 모든 부분

이 지침 당신은 그 값 대신에 이러한 변수의 주소를 곱된다

imul ecx,esi,size 
imul ecx,esi,temp 

코드에서 변경해야

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 

답변

1

를 표시입니다! 다음을 사용하는 것이 이상적입니다.

imul ecx,esi,[size] 
imul ecx,esi,[temp] 

하지만 이러한 피연산자는 사용할 수 없습니다.

mov ecx,esi 
imul ecx,[size] 

mov ecx,esi 
imul ecx,[temp] 

는 또한 바이트 대신에 DWORD 두 변수의 크기를 변경 :
난 같은 구조를 사용하여 제시한다. IMUL은 그것을 요구합니다.

+0

다른 생각으로 'movxx ecx, byte ptr [size] \ imul ecx, esi'가 될 수 있습니다. 그러면 OP는 변수 유형을 변경하지 않아도됩니다. – harold

+0

구조체 배열에 제대로 추가 할 수 없습니다. , 이전에 추가 한 모든 항목을 덮어 씁니다. 심지어 내가 말한 내용을 수행 한 후에도 –