27.04.2013 Views

Treball de Recerca - Recercat

Treball de Recerca - Recercat

Treball de Recerca - Recercat

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Per exemple a la Font 1 on s’hi pot trobar una funció per a un processador <strong>de</strong> 32-bit<br />

x86 que calcula el valor enèsim <strong>de</strong> la successió <strong>de</strong> Fibonacci.<br />

Segona generació<br />

El llenguatge <strong>de</strong> segona generació és el llenguatge assemblador. És un llenguatge<br />

format per estructures simples <strong>de</strong> codi que són converti<strong>de</strong>s directament a codi<br />

màquina.<br />

8B542408 83FA0077 06B80000 0000C383<br />

FA027706 B8010000 00C353BB 01000000<br />

B9010000 008D0419 83FA0376 078BD98B<br />

C84AEBF1 5BC3<br />

Font 1: Llenguatge <strong>de</strong> primera generació.<br />

Com per exemple a la Font 2, on hi ha la mateixa funció que a la Font 1, per a trobar<br />

el nombre enèsim <strong>de</strong> la successió <strong>de</strong> Fibonacci, però en llenguatge assemblador<br />

MASM 5 , tornant-se així més llegible, però també complex.<br />

fib:<br />

mov edx, [esp+8+1]<br />

cmp edx, 0<br />

ja @f<br />

mov eax, 0<br />

ret<br />

@@:<br />

cmp edx, 2<br />

ja @f<br />

mov eax, 1<br />

ret<br />

@@:<br />

push ebx<br />

mov ebx, 1<br />

mov ecx, 1<br />

@@:<br />

lea eax, [ebx+ecx]<br />

cmp edx, 3<br />

jbe @f<br />

mov ebx, ecx<br />

mov ecx, eax<br />

<strong>de</strong>c edx<br />

jmp @b<br />

@@:<br />

pop ebx<br />

ret<br />

Font 2: Llenguatge <strong>de</strong> segona generació<br />

5 MASM: Microsoft Macro Assembler.<br />

7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!