User Tools

Site Tools


archi:y86

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
archi:y86 [2018/09/12 09:55] orelarchi:y86 [2024/03/18 15:06] (current) – external edit 127.0.0.1
Line 682: Line 682:
  
  
 +==== En vrac ====
  
 +<code - td04_exo1.ys>
 +.pos 0
 +
 +irmovl stack, %esp
 +jmp main
 +
 +# f(long *x, long y)
 +f:
 +mrmovl 4(%esp),%eax   # x
 +mrmovl 8(%esp),%ecx   # y
 +rmmovl %ecx,(%eax)    # *x = y
 +ret
 +
 +# main
 +main:
 +
 +mrmovl u, %eax
 +pushl %eax          # empiler 2eme arg (u)
 +irmovl t, %eax
 +pushl %eax          # empiler 1er arg (&t)
 +call f
 +iaddl 8,%esp        # depiler les args
 +
 +halt
 +
 +.pos 0x100
 +t: .long 0
 +u: .long 2
 +
 +.pos 0x200
 +stack:
 +</code>
 +
 +<code - td04_exo2.ys>
 +.pos 0
 +
 +irmovl stack, %esp
 +jmp main
 +
 +# f(long n, long * t)
 +f:
 +mrmovl 4(%esp),%ecx   # n
 +mrmovl 8(%esp),%eax   # t
 +
 +loop:
 +isubl 1, %ecx
 +jl end
 +mrmovl (%eax),%edx    # load *t
 +iaddl 1, %edx         # inc
 +rmmovl %edx, (%eax)   # store *t 
 +iaddl 4,%eax          # t++
 +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,%esp        # depiler les args
 +
 +halt
 +
 +.pos 0x100
 +n: .long 4
 +t: 
 +.long 1
 +.long 2
 +.long 3
 +.long 4
 +
 +
 +.pos 0x200
 +stack:
 +</code>
 +
 +<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,%eax        # sum = 0
 +mrmovl 8(%esp),%ecx   # n
 +rrmovl %esp,%ebx
 +iaddl 12, %ebx         # v
 +
 +loop:
 +isubl 1, %ecx
 +jl end
 +mrmovl (%ebx),%edx    # load *v
 +addl %edx,%eax        # sum += *v
 +rmmovl %edx, (%ebx)   # store *v
 +iaddl 4,%ebx          # v++
 +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,%esp        # depiler les args
 +
 +halt
 +
 +.pos 0x100
 +n: .long 4
 +
 +
 +.pos 0x200
 +stack:
 +</code>
archi/y86.1536746145.txt.gz · Last modified: 2024/03/18 15:05 (external edit)