07.05.2013 Views

Tema 3: El nivel de lenguaje máquina - Blearning

Tema 3: El nivel de lenguaje máquina - Blearning

Tema 3: El nivel de lenguaje máquina - Blearning

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.

Ejemplo para MIPS<br />

SP <br />

SP=SP-20 <br />

# Ejemplo para MIPS<br />

# Programa principal<br />

main: li $a0,5<br />

li $a1,8<br />

jal multi<br />

....................<br />

# comienzo <strong>de</strong>l procedimiento<br />

multi: addi $sp,$sp,-20 # Crea bloque <strong>de</strong> activación.<br />

# Salva registros. Crea variables locales si se necesitan.<br />

sw $fp, 16($sp) # guarda fp antiguo<br />

sw $ra, 12($sp) # guarda dirección <strong>de</strong> retorno<br />

sw $s0, 8($sp) # guarda $s0<br />

sw $s1, 4($sp) # guarda $s1<br />

sw<br />

addi<br />

$s2, 0($sp) # guarda $s2<br />

$fp,$sp,16 # nuevo fp<br />

# cuerpo procedimiento<br />

.....<br />

# Restaura registros<br />

lw $s2, 0($sp) # recupera $s2<br />

lw $s1, 4($sp) # recupera $s1<br />

lw $s0, 8($sp) # recupera $s0<br />

lw $ra, 12($sp) # recupera dirección <strong>de</strong> retorno<br />

lw $fp, 16($sp) # recupera fp antiguo<br />

addi $sp,$sp,20 # Destruye bloque activación<br />

jr $ra # retorna al programa principal<br />

Fundamento <strong>de</strong> Computadores (1º II) Cap 2: <strong>El</strong> <strong>nivel</strong> <strong>de</strong> <strong>lenguaje</strong> <strong>máquina</strong> 39 <strong>de</strong> 64<br />

$s2<br />

$s1<br />

$s0<br />

Registros salvados<br />

$ra: dir. retorno<br />

$fp: frame pointer<br />

Dirección baja<br />

<strong>de</strong> memoria<br />

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

Saved successfully!

Ooh no, something went wrong!