archi:y86
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| archi:y86 [2016/09/29 13:00] – [Simulateur Y86] orel | archi:y86 [2024/03/18 15:06] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 13: | Line 13: | ||
| * %edi : le registre // | * %edi : le registre // | ||
| - | En outre, le registre %eip (// | + | En outre, le registre %eip (// |
| y86 propose un jeu d' | y86 propose un jeu d' | ||
| Line 37: | Line 37: | ||
| | | ||
| L' | L' | ||
| + | |||
| + | ==== Simulateur web y86 en JS ==== | ||
| + | |||
| + | Voici un simulateur y86 écrit en JavaScript et disponible en ligne : | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | Attention, cette version disponible sur https:// | ||
| + | |||
| + | A vous de jouer ;-) | ||
| + | |||
| + | |||
| + | |||
| + | |||
| ==== If then ==== | ==== If then ==== | ||
| Line 44: | Line 58: | ||
| long a = 2, b = 3, c; | long a = 2, b = 3, c; | ||
| if (a < b) c = 1; | if (a < b) c = 1; | ||
| + | </ | ||
| + | |||
| + | Afin de se rapprocher du code assembleur à écrire, il peut être utile de réécrire le code C de la façon suivante en utilisant //une condition d' | ||
| + | |||
| + | <code c> | ||
| + | long a = 2, b = 3, c; | ||
| + | // (a < b) <=> (a-b < 0) <=> ! (a-b >= 0) | ||
| + | long tmp = a-b; // calcul de la condition d' | ||
| + | if (tmp >= 0) goto _endif; // test de la condition d' | ||
| + | c = 1; | ||
| + | _endif: | ||
| + | |||
| </ | </ | ||
| Line 73: | Line 99: | ||
| if (b <= a) c = 1; else c = 2; | if (b <= a) c = 1; else c = 2; | ||
| </ | </ | ||
| + | |||
| + | Un peu de réécriture du code C : | ||
| + | |||
| + | <code c> | ||
| + | long a = 2, b = 3, c; | ||
| + | long tmp = b - a; | ||
| + | if (tmp > 0) goto _else; | ||
| + | c = 1; // tmp <= 0, donc la condition b <= a est vraie | ||
| + | goto _endif; | ||
| + | _else: | ||
| + | c = 2; // tmp > 0, donc la condition b <= a est fausse | ||
| + | _endif: | ||
| + | </ | ||
| + | |||
| + | Avant de traduire cela en assembleur : | ||
| <code - ifthenelse.ys> | <code - ifthenelse.ys> | ||
| Line 413: | Line 454: | ||
| .pos 0x200 | .pos 0x200 | ||
| stack: | stack: | ||
| + | </ | ||
| + | |||
| + | Attention, cette fonction ne respecte pas la convention // | ||
| + | |||
| + | 1) sauvegarder / restaurer le registre %ebx dans la fonction pour respecter la convention (attention au décalage de la pile) : | ||
| + | |||
| + | <code - swap1.ys> | ||
| + | swap: pushl %ebx | ||
| + | mrmovl 8(%esp), | ||
| + | mrmovl 12(%esp), | ||
| + | mrmovl (%eax), | ||
| + | mrmovl (%ebx), | ||
| + | rmmovl %ecx, | ||
| + | rmmovl %edx, | ||
| + | popl %ebx | ||
| + | ret | ||
| + | </ | ||
| + | |||
| + | 2) essayer si possible de se limiter aux seuls registres %eax, %ecx et %edx en essayant de se passer de %ebx (ce qui impose de faire des va-et-vient avec la mémoire) : | ||
| + | |||
| + | <code - swap2.ys> | ||
| + | swap: | ||
| + | mrmovl (%eax), | ||
| + | mrmovl 8(%esp), | ||
| + | mrmovl (%edx), | ||
| + | rmmovl %edx, | ||
| + | mrmovl 8(%esp), | ||
| + | rmmovl %ecx, | ||
| + | ret | ||
| </ | </ | ||
| Line 612: | Line 682: | ||
| - | ==== Simulateur Y86 ==== | + | ==== En vrac ==== |
| - | Voici un simulateur Y86 écrit en Javascript et disponible en ligne : http://dept-info.labri.fr/ | + | < |
| + | .pos 0 | ||
| + | irmovl stack, %esp | ||
| + | jmp main | ||
| - | Attention, la version originale du simulateur | + | # f(long *x, long y) |
| + | f: | ||
| + | mrmovl 4(%esp),%eax # x | ||
| + | mrmovl 8(%esp), | ||
| + | rmmovl %ecx,(%eax) # *x = y | ||
| + | ret | ||
| - | * Les instructions //mrmovl// et //rmmovl// ne supportent pas l' | + | # main |
| - | * Par ailleurs, les instructions suivantes (non standards, mais pratiques) ne sont pas disponibles | + | main: |
| - | * D' | + | |
| - | * Utilisation optionnelle du symbole %%$%% devant les constantes numériques. | + | |
| + | mrmovl u, %eax | ||
| + | pushl %eax # empiler 2eme arg (u) | ||
| + | irmovl t, %eax | ||
| + | pushl %eax # empiler 1er arg (&t) | ||
| + | call f | ||
| + | iaddl 8, | ||
| + | halt | ||
| + | |||
| + | .pos 0x100 | ||
| + | t: .long 0 | ||
| + | u: .long 2 | ||
| + | |||
| + | .pos 0x200 | ||
| + | stack: | ||
| + | </ | ||
| + | |||
| + | <code - td04_exo2.ys> | ||
| + | .pos 0 | ||
| + | |||
| + | irmovl stack, %esp | ||
| + | jmp main | ||
| + | |||
| + | # f(long n, long * t) | ||
| + | f: | ||
| + | mrmovl 4(%esp), | ||
| + | mrmovl 8(%esp), | ||
| + | |||
| + | loop: | ||
| + | isubl 1, %ecx | ||
| + | jl end | ||
| + | mrmovl (%eax), | ||
| + | iaddl 1, %edx # inc | ||
| + | rmmovl %edx, (%eax) | ||
| + | iaddl 4, | ||
| + | jmp loop | ||
| + | |||
| + | end: | ||
| + | ret | ||
| + | |||
| + | # main | ||
| + | main: | ||
| + | irmovl t, %eax | ||
| + | pushl %eax # empiler 2eme arg (adresse t) | ||
| + | mrmovl n, %eax | ||
| + | pushl %eax # empiler 1er arg (valeur n) | ||
| + | call f | ||
| + | iaddl 8, | ||
| + | |||
| + | halt | ||
| + | |||
| + | .pos 0x100 | ||
| + | n: .long 4 | ||
| + | t: | ||
| + | .long 1 | ||
| + | .long 2 | ||
| + | .long 3 | ||
| + | .long 4 | ||
| + | |||
| + | |||
| + | .pos 0x200 | ||
| + | stack: | ||
| + | </ | ||
| + | |||
| + | <code - td04_exo3.ys> | ||
| + | .pos 0 | ||
| + | |||
| + | irmovl stack, %esp | ||
| + | jmp main | ||
| + | |||
| + | # sommme(long n, long v[0], long v[1], ...) | ||
| + | f: | ||
| + | pushl %ebx # save callee-saved registry | ||
| + | xorl %eax, | ||
| + | mrmovl 8(%esp), | ||
| + | rrmovl %esp,%ebx | ||
| + | iaddl 12, %ebx # v | ||
| + | |||
| + | loop: | ||
| + | isubl 1, %ecx | ||
| + | jl end | ||
| + | mrmovl (%ebx), | ||
| + | addl %edx, | ||
| + | rmmovl %edx, (%ebx) | ||
| + | iaddl 4, | ||
| + | jmp loop | ||
| + | end: | ||
| + | popl %ebx # restore callee-saved registry | ||
| + | ret # %eax | ||
| + | |||
| + | # main | ||
| + | main: | ||
| + | irmovl 3, %eax | ||
| + | pushl %eax # empiler v2 | ||
| + | irmovl 2, %eax | ||
| + | pushl %eax # empiler v1 | ||
| + | irmovl 1, %eax | ||
| + | pushl %eax # empiler v0 | ||
| + | irmovl 3, %eax | ||
| + | pushl %eax # empiler n | ||
| + | call f | ||
| + | iaddl 16, | ||
| + | |||
| + | halt | ||
| + | |||
| + | .pos 0x100 | ||
| + | n: .long 4 | ||
| + | |||
| + | |||
| + | .pos 0x200 | ||
| + | stack: | ||
| + | </ | ||
archi/y86.1475154012.txt.gz · Last modified: 2024/03/18 15:05 (external edit)
