# # Autor(s) : Jordi Ferrer Plana # e-mail : jferrerp@eia.udg.es # Branch : - # # Working Group : Departament d'Electrònica, Informàtica i Automàtica # Project : Examen d'ETIS/ETIG d'Estructura i Tecnologia de Computadors, # 1era convocatòria, any 2006. # Homepage : http://eia.udg.es/etc/ # # Module : Problema 5: BMP | PMB (MIPS). Capgirar una Imatge. # # File : capgirar.s # Date : 03/06/2006 - 03/06/2006 # # Compiler : Spim >= 6.3 # Libraries : - # # Notes : - La Imatge es defineix de 19x14 enlloc de 192x144 perquè # es pugui comprovar el resultat. # - En els comentaris s'utilitzen els noms de variables del # codi en C per poder comparar la traducció feta. # # ---------------------------------------------------------------------------- # # Copyright (C) 2004-2005, Jordi Ferrer Plana # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License (http://www.gnu.org/copyleft/) # for more details. # # ---------------------------------------------------------------------------- # .data # Width : .half 192 # Amplada de la Imatge # Height: .half 144 # Altura de la Imatge # Image : .space 110592 # Espai: 192 x 144 * 4 Bytes = 110592 Width : .half 19 # Amplada de la Imatge Height: .half 14 # Altura de la Imatge Image : .space 1064 # Espai: 19 * 14 * 4 Bytes = 1064 Espai : .asciiz " " # Un Espai en Blanc Return: .asciiz "\n" # Un Return .end .text # # void capgirar ( Image : Adreça, Width: Natural, Height : Natural ); # # NOTES: # En conveni MIPS: # Es pot utilitzar $t0 - $t9 dins la funció sense guardar-los. # Els paràmetres estaran a: # $a0: Adreça de la Imatge (Enter sense signe). # $a1: Width (Enter sense signe). # $a2: Height (Enter sense signe). # # No es guardarà res a la pila ja que no cal. # capgirar: srl $t0, $a2, 1 # $t0 <- Height / 2 li $t1, 0 # i <- 0 fori: bge $t1, $t0, exiti # Mentre i < ( Height / 2 ) mul $t2, $t1, $a1 # SrcOffs <- i * Width subu $t3, $a2, $t1 # DstOffs <- Height - i addi $t3, $t3, -1 # DstOffs <- Height - i - 1 mul $t3, $t3, $a1 # DstOffs <- ( Height - i - 1 ) * Width li $t4, 0 # j <- 0 forj: bge $t4, $a1, exitj # Mentre j < Width add $t5, $t2, $t4 # SrcOffs + j sll $t5, $t5, 2 # ( SrcOffs + j ) * 4 add $t5, $t5, $a0 # Image + ( SrcOffs + j ) * 4 add $t6, $t3, $t4 # DstOffs + j sll $t6, $t6, 2 # ( DstOffs + j ) * 4 add $t6, $t6, $a0 # Image + ( DstOffs + j ) * 4 lw $t7, 0($t5) # Intercanviar els píxels lw $t8, 0($t6) # de la fila superior pels sw $t7, 0($t6) # de la parella corresponent sw $t8, 0($t5) # de la fila inferior. addi $t4, $t4, 1 # j++ j forj # Propera iteració exitj: addi $t1, $t1, 1 # i++ j fori # Propera iteració exiti: jr $ra # Retonar a l'invocador .end .text # # void main ( void ) # # Exemple de crida a capgirar ( Image, Width, Height ); # main: subu $sp, $sp, 4 # Fer espai a la pila sw $ra, 0($sp) # Guardar l'adreça de retorn # Els tres paràmetres per registre: la $a0, Image # Adreça de la Imatge lhu $a1, Width($0) # Amplada lhu $a2, Height($0) # Altura jal capgirar # Cridar a "capgirar" lw $ra, 0($sp) # Recuperar adreça de retorn addu $sp, $sp, 4 # Desempilar jr $ra # Retonar a l'invocador .end