I have this RLE exercise in assembly to count elements of an array and I am encountering a strange problem I cannot understand. In label RegisterOccurrence, I increment BL for the second time and compare it to 255 cause this is the max value of an unsigned char in case there are more elements in the array. Now the problem is that in this case when CMP BL,255 is done BL will be 2 and 2 is lower than 255 still the program jumps to AdjustValue
__asm
{
XOR EAX, EAX
XOR EBX, EBX
XOR ECX, ECX
XOR EDX, EDX
XOR EDI, EDI
XOR ESI, ESI
MOV EAX, Len
//---------------------------------------------------------------------------------------------------------------------
Loop:
CMP ESI,EAX
JE EndProgram
MOV DL,[Buffer+ESI]
MOV CL,[Buffer+ESI+1]
CMP DL,CL
JE Occurrence
JNE SingleNumber
INC ESI
JMP Loop
//----------------------------------------------------------------------------------------------------------------------
SingleNumber:
MOV BufComp[EDI],1
MOV BufComp[EDI+1],DL
INC ESI
ADD EDI,2
JMP Loop
//----------------------------------------------------------------------------------------------------------------
Occurrence:
INC BL
INC ESI
MOV DL, [Buffer + ESI]
MOV CL, [Buffer + ESI + 1]
CMP DL,CL
JNE RegisterOccurrence
JMP Loop
//---------------------------------------------------------------------------------------------------------------
RegisterOccurrence:
INC BL
CMP BL,255
JG AdjustValue
MOV BufComp[EDI],BL
MOV BufComp[EDI+1],DL
INC ESI
ADD EDI,2
XOR EBX,EBX
JMP Loop
//-------------------------------------------------------------------------------------------------------------------
AdjustValue:
SUB BL,255
MOV BufComp[EDI],255
MOV BufComp[EDI+1],DL
ADD EDI,2
MOV BufComp[EDI],BL
MOV BufComp[EDI+1],DL
INC ESI
ADD EDI,2
XOR EBX,EBX
JMP Loop
//----------------------------------------------------------------------------------------------------------------------
EndProgram:
MOV BufComp[EDI],0d
}
//PRINT VALUES PART