CC4301 Arquitectura de Computadores

Anuncio
CC4301 Arquitectura de Computadores
Tarea 2 - Otoño 2010
No olviden: gcc -S -O es su amigo!
Pregunta 1
Que hace el código siguiente? Escribe los funciones equivalentes en C.
.globl _walk
_walk:
pushl %ebp
movl
%esp, %ebp
pushl %esi
movl
12(%ebp), %eax
movl
16(%ebp), %esi
cmpl
%esi, %eax
jl
L5
movl
8(%ebp), %ecx
leal
(%ecx,%eax,4), %edx
movl
%eax, %ecx
L4:
movl
(%edx), %eax
movl
%eax, 4(%edx)
decl
%ecx
subl
$4, %edx
cmpl
%ecx, %esi
jle
L4
L5:
popl
%esi
leave
ret
.globl _his
_his:
pushl %ebp
movl
%esp, %ebp
pushl %edi
pushl %esi
subl
$32, %esp
movl
12(%ebp), %eax
cmpl
$1, %eax
jle
L19
movl
$0, -16(%ebp)
decl
%eax
movl
%eax, -24(%ebp)
L10:
movl
-16(%ebp), %eax
movl
8(%ebp), %edx
movl
4(%edx,%eax,4), %edi
movl
%eax, -12(%ebp)
movl
$0, %esi
movl
$0, -20(%ebp)
testl %eax, %eax
js
L13
movl
-12(%ebp), %ecx
movl
$0, %esi
L14:
leal
(%ecx,%esi), %edx
movl
%edx, %eax
shrl
$31, %eax
addl
%edx, %eax
sarl
%eax
movl
8(%ebp), %edx
cmpl
(%edx,%eax,4), %edi
jge
L15
leal
-1(%eax), %ecx
jmp
L17
L15:
L17:
L13:
L19:
leal
1(%eax), %esi
cmpl
jle
movl
%ecx, %esi
L14
%esi, -20(%ebp)
movl
movl
movl
movl
movl
call
movl
movl
movl
incl
movl
cmpl
jne
%esi, 8(%esp)
-12(%ebp), %eax
%eax, 4(%esp)
8(%ebp), %edx
%edx, (%esp)
_walk
-20(%ebp), %eax
8(%ebp), %edx
%edi, (%edx,%eax,4)
-16(%ebp)
-24(%ebp), %eax
%eax, -16(%ebp)
L10
addl
popl
popl
leave
ret
$32, %esp
%esi
%edi
#leave =
#movl
#popl
%ebp, %esp
%ebp
Pregunta 2
Encuentra los 7 errores y corrige.
.globl _po
_po:
movl %ebp, %esp
pushl %ebp
movl 8(%ebp), %esi
movl 12(%ebp), %ecx
movl $1, %eax
testl %ecx, %ecx
jle
L25
movl $1, %eax
movl $0, %edx
L26:
imull %esi, %eax
incl %edx
cmpl %edx, %ecx
jne
L28
L25:
popl %esi
.globl _cp
_cp:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl $4, 4(%esp)
movl 8(%ebp), %eax
movl %eax, (%esp)
call _po
addl $42, %ebx
addl $24, %esp
ret
Descargar