Given a sequence of bits, knowing that every n bit (of data) there is a parity bit (1 if the number of bits at 1 among the previous n is odd), check if there are errors
#include <stdio.h>
void main()
{
// Input
unsigned char vet[] = { 2,4,67,2,2,58,99 };
unsigned int len = 55; // length (numbers of bit)
unsigned char n = 4; // numbers of data bit
// Ouput
unsigned char errori = 0; // 1 = error; 0 = not error
__asm
{
}
// Stampa su video
printf("The bit sequence %scontains errorsn", (errori ? "" : "does not"));
}
Thank you so much.
Until now, i have done so much versions and nothing, for example:
__asm
{
XOR EAX, EAX
XOR EBX, EBX
XOR ECX, ECX
XOR EDX, EDX
ADD n, 1
Salto3: MOV BL, vet[ECX]
Salto2 : TEST BL, 1
JZ Salto1
XOR errori, 1
Salto1 : SHR BL, 1
INC EAX
VerificaByte : CMP EAX, 8
JL VerificaN
XOR EDX, EDX
ContinuaByte : SUB EAX, 8
INC EDX
CMP EAX, 8
JGE ContinuaByte
CMP EAX, 0
JE RipristinaByteS
JNE RipristinaByteN
RipristinaByteS : ADD EAX, 8
DEC EDX
CMP EDX, 0
JNE RipristinaByteS
INC ECX
MOV BL, vet[ECX]
JMP VerificaN
RipristinaByteN : ADD EAX, 8
DEC EDX
CMP EDX, 0
JNE RipristinaByteN
VerificaN : CMP AL, n
JL Salto2
CWD
DIV n
CMP AH, 0
JE VerificaBit
MOV DL, AH
MUL n
ADD AL, DL
CMP EAX, len
JE FineNoErrori
JNE Salto2
PostVerifica : MOV DL, AH
MUL n
ADD AL, DL
INC EAX
SHR BL, 1
MOV errori, 0
CMP EAX, len
JE FineNoErrori
JNE Salto2
}
Thats one of my versions but sometimes it doesnt gave me the correct answers (according to cases that are generated manually at my school platform)
New contributor
Alion Emini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.