# # 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, # 2ona convocatòria, any 2005. # Homepage : http://eia.udg.es/etc/ # # Module : Problema 5. Histogram. # # File : histogram.s # Date : 30/06/2004 - 06/07/2004 # # Compiler : Spim >= 6.3 # Libraries : - # # Notes : - # # ---------------------------------------------------------------------------- # # 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 # No cal guardar les mides a memòria WIDTH=192 # Amplada de les imatges HEIGHT=144 # Altura de les imatges N=27648 # 192 x 144 * 1 Byte = 27648 SrcGrayImg: .space N # Espai per la Imatge # Com que la imatge és de 27648 pixels # (bytes), el maxim valor per qualsevol # posició de l'histograma necessita 15 # bits com a mínim. Histogram: .space 512 # Espai per l'histograma (256 * 2) .end .text # # void histogram ( char *SrcGrayImg, unsigned short Histogram[256], # unsigned int Width, unsigned int Height ); # # # 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: Adreça de l'Histograma : Enter sense signe. # a2: Width : Enter. # a3: Height : Enter. # # No es guardarà res a la pila ja que no cal. # histogram: # Inicialitzar totes les posicions li $t0, 0 # de l'histograma a 0 fori: bge $t0, 256, exitfi # Mentre no s'arribi a 256 add $t1, $a1, $t0 # $t1 <- @Histogram + Posicio $t0 sh $0, 0($t1) # Copiar un 0 (de 16 bits) a la # posició $t2 addi $t0, $t0, 2 # i += 2 (Següent posició) j fori # Propera iteració exitfi: # Calcular l'histograma mul $t1, $a2, $a3 # $t1 <- Width * Height li $t0, 0 # i = 0 forj: bge $t0, $t1, exitfj # while i < Mida Imatge add $t2, $a0, $t0 # $t2 <- @SrcGrayImg + Offs pixel lbu $t2, 0($t2) # $t2 <- Nivell de gris # Calcular l'offset de l'histograma sll $t2, $t2, 1 # Offset = Nivell gris * 2 add $t2, $a1, $t2 # $t2 <- @Histograma + Offset lhu $t3, 0($t2) # Valor actual de l'histograma addiu $t3, $t3, 1 # Incrementar 1 unitat sh $t3, 0($t2) # Guardar el nou valor addi $t0, $t0, 1 # i++ (Següent pixel) j forj # Propera iteració exitfj: jr $ra # Retonar a l'invocador .end .text # # int main ( void ) # # Exemple de crida a histogram ( SrcGrayImg, Histogram, WIDTH, HEIGHT ); # main: subu $sp, $sp, 4 # Fer espai a la pila sw $ra, 0($sp) # Guardar l'adreça de retorn # Quatre paràmetres per registre: la $a0, SrcGrayImg # Adreça de la Imatge la $a1, Histogram # Adreça de l'histograma li $a2, WIDTH # Amplada li $a3, HEIGHT # Altura jal histogram # Crida a "histogram" lw $ra, 0($sp) # Recuperar adreça de retorn addu $sp, $sp, 4 # Desempilar li $v0, 0 # Valor 0 de retorn a l'invocador jr $ra # Retonar a l'invocador .end