1, left shift 2, plus a double value 3, then move again, get the array subscript forming offset 4, take the first address 5, the first address array subscript forming offset structural internal offset to be required Address ROUTINE SHL ... Add ... SHL ... MOV Offset XXXXX
The CALL ATOI function acquires an integer that addresses this integer to address a structure of a structure in 16 bits to write to the fourth byte of the corresponding structure. TEXT: 0802A6E9 Call _atoi .text: 0802a6ee add ESP, 4 .TEXT: 0802A6F1 MOV [EBP TMP], EAX; Saved Integer (Return Value) .Text: 0802A6F7 MOV EAX, [EBP INDEX]; [EBP INDEX] Save Dys to Address Site Structure Body .Text: 0802a6fa MOV [EBP STRUCT_OFFSET], EAX; [EBP INDEX] = [EBP TMP] = EAX = Index (Item Item) .Text: 0802A700 MOV EBX, [EBP STRUCT_OFFSET] .TEXT: 0802A706 MOV ECX, EBX.TEXT: 0802A708 SHL ECX, 4; ECX = 16 * [EBP INDEX] .TEXT: 0802A70B Add ECX, [EBP STRUCT_OFFSET]; ECX = 17 * [EBP INDEX] .Text: 0802a711 LEA EDX, DS: 0 [ECX * 4]; EDX = 68 * [EBP INDEX] Complete the calculation of the ITEM offset address .Text: 0802A718 MOV [EBP STRUCT_OFFSET], EDX; save the offset address .Text: 0802A71E MOV ECX, OFFSET MEMORY; Take the first address of the array memory area .Text: 0802A723 MOV EAX, [E BP TMP]; Take the return value of the ATOI function .Text: 0802A729 MOV EDI, [EBP STRUCT_OFFSET]; take offset address .Text: 0802A72F MOV [EDI ECX 4], AX; ATOI return value with 16 bits Fourth byte starting place to write to the corresponding structure
Read: .text: 0802A734 MOV EDX, [EBP INDEX] .Text: 0802A737 MOV [EBP TMP], EDX .TEXT: 0802A73D MOV ECX, [EBP TMP] .Text: 0802a743 MOV EDI, ECX .Text: 0802A745 SHL EDI, 4; First shift to get 16 * index .text: 0802A748 MOV [EBP STRUCT_OFFSET], EDI .TEXT: 0802A74E MOV EAX, [EBP TMP] .TEXT: 0802A754 Add [EBP STRUCT_OFFSET], EAX; [EBP STRUCT_OFFSET] = 17 * [EBP INDEX] .TEXT: 0802A75A MOV EDX, [EBP STRUCT_OFFSET] .TEXT: 0802A760 SHL EDX, 2; Second shift to get 68 * index .text: 0802a763 MOV [EBP TMP], EDX; [EBP TMP] = 68 * [EBP INDEX] .Text: 0802A769 MOV [EBP STRUCT_OFFSET], OFFSET MEMORY.TEXT: 0802A773 MOV EDI, [EBP STRUCT_OFFSET] .TEXT: 0802A779 MOV E AX, [EBP TMP] .TEXT: 0802A77F CMP Word PTR [EAX EDI 4], 0xFF; Take the value that is previously written, the content of the temporary variable is stored, the basic idea is once after a shift After the last value is shifted once, because the memory is allocated, the memory is aligned, the shift can be indexed, and if you want to find the value of a domain in the access structure, the value of a domain is as long as the first address is And then add the index address obtained by the calculated offset address, plus the offset value in the structure in the structure.
Source code struct item {int a; char ch1; int b; char CH2; int C; char CH3; char CH [10]; int D;};
Struct Item Test [100];
Void Print (int index) {INT TMP = test [index] .d; char * p = test [index] .ch; char ctmp = test [index] .CH2; Printf ("% d / n", TMP); TMP = test [index] .a; printf ("% d / n", TMP);}