There is an array, you need to use the assembler insert in C to find the same elements and remove them to replace all but one, say, '$'
Let's start with the most primitive algorithm in C. We will stupidly change all duplicates to the '$' symbol, leaving only the first of the duplicate characters:
#include <stdio.h> static char * find_and_replace_dups( char * data, size_t n, char to ) { size_t i, j; for( i = 0; i < n; i++ ) { for( j = i + 1; j < n; j++ ) { if( data[i] == data[j] ) { data[j] = to; } } } return data; } #define SIZE ((sizeof(data)/sizeof(data[0]))-1) int main(void) { char data[] = "abcdabcdabcdef"; printf( "%s", find_and_replace_dups( data, SIZE, '$' ) ); return 0; }
Output: abcd $$$$$$$$$ ef
And now the same thing in assembler. Apparently, Intel is needed, but this is not at hand, like Windows. Therefore, NASM and under Linux: the syntax will be closer, and the rest of the type int 80h
- little things, everything is the same main.
; ------------------------------------------ section .data ; ------------------------------------------ data db 'abcdabcdabcdef' data_length equ $-data ; ------------------------------------------ section .text ; ------------------------------------------ global main main: cld mov ah, '$' mov esi, data mov ecx, data_length mov edx, ecx add edx, esi for1: lodsb cmp esi, edx je print mov ebx, esi for2: cmp al, [ebx] jne next1 mov [ebx], ah next1: inc ebx cmp ebx, edx jne for2 jmp for1 print: mov ecx, data mov edx, data_length mov eax,4 mov ebx,1 int 80h mov eax, 1 xor ebx, ebx int 80h ; ------------------------------------------ ; That's all, folks! ; ------------------------------------------
The conclusion is the same, hooray! abcd $$$$$$$$$ ef
Well, how to turn this into an inline insert is already an independent comprehension :)
PS Well, to the heap: tyk myshy .
a
is a link to two links. Moreover, one is located in memory at[[a + 1]]
, but this cannot be, since the 32-bit register and addressing are also (otherwise there would be amovzx
instruction). - Indy[eax + 1]
. And the registers to zero before loading them makes no sense. Saving somewhere in a variable value is also meaningless, since there are still unused general-purposeecx
:ecx
andedx
. - Indymov [eax], 's'
is not the Intel syntax: let the segment be omitted (ds
/ss
), but the size of the operand is not specified. A typeCHAR
has the size of one byte, so the dvard cannot be loaded into it (maybebl
used or the names of the curves). - Indymov bl, [eax+1]; cmp bl, [eax+2]
mov bl, [eax+1]; cmp bl, [eax+2]
But this is almost useless information to solve this problem :) - user6550