# # 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 2003. # Homepage : http://eia.udg.es/etc/ # # Module : Exercici 4. Càlcul de l'àrea d'un quadrat. # # File : quadrat.asm # Date : 30/06/2003 - 01/07/2003 # # Compiler : - # Libraries : - # # Notes : - El programa calcula l'àrea d'un quadrat a partir del costat, # és a dir, el quadrat d'un valor, utilitzant sumes successives. # - El resultat s'escriu a l'adreça 69h (105d). # - El paràmetre (costat del quadrat) està a l'adreça 68h (104d). # - Com que el quadrat d'un valor pot necessitar com a màxim el # el doble de bits d'aquest, el valor només pot ocupar 8 bits. # - S'utilitzen les adreces finals [7Dh .. 7Fh] per valors # temporals. # - El codi pot estar a qualsevol lloc de la memòria, mentre no # no ocupi les adreces 68h, 69h i el rang [7Dh .. 7Fh]. # # ---------------------------------------------------------------------------- # # Copyright (C) 2002-2003, 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. # # ---------------------------------------------------------------------------- # # Definició de les dades # ... ... ... 68h: 00XXh # Paràmetre 'Costat' amb el valor del costat als 8 bits de menys pes. 69h: YYYYh # Variable 'Area' on hi quedarà el resultat del càlcul de l'àrea. ... ... ... 7Dh: ZZZZh # Variable 'i' per realitzar el comptatge. 7Eh: 0001h # Constant 1. 7Fh: 0000h # Constant zero. # Implementació del programa # Area: MOV 7Fh, 69h # Area := 0 MOV 7Fh, 7Dh # i := 0 Loop: CMP 7Dh, 68h # Mentre ( i != Costat ) BEQ Fi ADD 68h, 69h # Area := Area + Costat ADD 7Eh, 7Dh # i := i + 1 CMP 7Fh, 7Fh # Salt incondicional a 'Loop' per fer la nova iteració BEQ Loop Fi: