News for hackers. Stuff that matters.

ununoctio

Re:Codility - Automated tests of programming skills on Sunday March 21, 2010 @05:00AM (#1207723)
{In Pascal Language+Assembly} {$ASMMODE INTEL} function equi (A : Array of longint; n : longint ) : longint; var c:Longint; label noOverflow1; label noOverflow2; label ciclo; label fine; label Over; label tot; Begin Asm DEC n JS over XOR ECX, ECX {Somma1} XOR EDI, EDI {Somma2} XOR EAX, EAX MOV c, EDI MOV ESI, n tot: MOV EDX, A MOV EDX, [EDX+ESI*4] PUSH EDX ADD ECX, EDX JNO nooverflow1 ADD c, ECX nooverflow1: DEC ESI JNS tot; SUB ECX, c SUB EDI, c ciclo: POP EDX SUB ECX, EDX CMP ECX, EDI JE fine ADD EDI, EDX JNO nooverflow2 DEC EDI nooverflow2: CMP EAX, n JA over INC EAX JMP ciclo over: MOV EAX, -1 fine: end; End;