codice:
#include <stdio.h>
void main() {
//Variabili
#define MaxLen 1024
int Len=30; //Lunghezza della sequenza da comprimere
unsigned char Buffer[MaxLen]={1,2,3,3,3,3,0,1,0,0,0,0,0,0,0,0,0,0, //I dati
0,0,0,4,5,99,99,99,255,255,255,255}; //comprimere
#define MaxLenComp (MaxLen*2+1)
unsigned char BufComp[MaxLenComp]; //Vettore in cui mettere i dati compressi
unsigned char temp;
int numocco;
//Blocco Assembler
__asm{
xor eax,eax
mov eax,Len
MENTRE: cmp eax,0
je FINE
mov esi,-1
mov numocco,-1
mov edi,0
mov temp,Buffer[edi]
CICLO: inc esi
inc numocco
cmp temp,Buffer[esi]
je CICLO
jmp ALLORA
ALLORA: inc esi
jmp CICLO
mov temp,Buffer[esi]
FINE:
}
int i,j;
for (i=0;i<=Len;i++){
temp=Buffer[i];
for(j=i+1;j<Len;j++){
numocco=1;
if (temp==Buffer[j]){
numocco++;
Buffer[j]="";
}
}
BufComp[i]=numocco;
printf("%d\n", cstr(numocco));
BufComp[i+1]=temp;
printf("%c\n", temp);
}
BufComp[i+2]="0";
printf("%03d",BufComp[0]);
for (i=0;i<Len;i++){
printf("\n", BufComp[i]);
}
system("pause");
Stampa su video
{
mov esi,-1
mov numocco,-1
mov edi,0
mov temp,Buffer[edi]
CICLO: inc esi
inc numocco
cmp temp,Buffer[esi]
je CICLO
jmp ALLORA
ALLORA: inc esi
jmp CICLO
mov temp,Buffer[esi]
int i;
for (i=0;i<Len;i++){
printf("%02X ",Buffer[i]);
}
printf("\n");
for (i=0;BufComp[i];){
printf("%3d ",BufComp[i++]);
printf("%02X",BufComp[i++]);
}
printf("\n");
}
}
La mia bozza di idea è questa però quando lo compilo esce la finestra, dura 2 secondi, e si chiude subito facendomi vedere una serie di numeri.