Vistas de página en total

Mostrando entradas con la etiqueta WHILE. Mostrar todas las entradas
Mostrando entradas con la etiqueta WHILE. Mostrar todas las entradas

martes, 20 de agosto de 2013

USO DE WHILE...ENDWHILE

    Este sería un ejemplo del uso de la macro while....endwhile. Como se ve es idéntico a como sería en basic.
   En este caso imprime 5 veces un mensaje indicando el contador de cada mensaje.




EJEMPLO FOR.MAC
; Copyright (C) 2013  José Ángel Moneo Fernández

;    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 3 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 for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.

include main.mac
include stdio.mac
include Hi_nivel.mac

.model compact,pascal
.stack 100

.data
valor db 0,0,0,0
msgtexto db "Mensaje ",0

.code
p proc 
          main
         clrscr
     while valor,b,5
          gotoxy 10,valor
          mov ax,word ptr valor
          mov word ptr numero,ax
          puts msgtexto
          printf numero
         inc valor
     endwhile
        exit 0
p endp
end p


sábado, 17 de agosto de 2013

DIRECTIVAS PROGRAMACIÓN ESTRUCTURADA

   Hoy voy a enseñar como podemos crear directivas bucles de alto nivel para simplificar algunos programas.
   En concreto voy a exponer una cabecera donde definiremos directivas para realizar las instrucciones WHILE y FOR.
    Podía hacer la instrucción do..while, pero esta es demasiado simple da realizar directamente en ensamblador, ya que la comparación con salto atrás es directamente esta estructura. por ello no vale pena.
    La idea de estas estructuras de alto nivel es seguir aclarando el programa, de manera que se pueda distinguir de un vistazo la estructura del programa.
    En ensamblador, como todos sabemos, seguir un programa es muy laborioso, incluso para el programador que lo hizo, si ha pasado tiempo desde que lo creó.
     Todas las funciones, macros, y directivas que voy exponiendo, no hacen nada que no se pueda hacer directamente, pero aclaran la estructura, de forma que resulta muy sencilla de seguir, incluso después de 20 años, como estoy haciendo yo ahora.



HI_LEVEL.MAC
; Copyright (C) 2013  José Ángel Moneo Fernández

;    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 3 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 for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;definiciones de controles de estructuras complejas para
;;programación estructurada

;***** for var=ini to fin*****
for macro var,ini,fin
        mov var,ini
        $salvar
        cmp var,fin
        jb $ + 5
        $salvar
        nop
        nop
        nop
   endm


;***** next var*******
next macro var
        $recup
$hueco = $simbolo
        $recup
$bucle = $simbolo
        inc var
        jmp $bucle
$fin = this near
        org $hueco
        jmp $fin
        org $fin
  endm


;****while op1 (a es >,e es =,b es <,ae es >=,be es <=) op2***********
while macro op1,oper,op2
        $salvar
        cmp op1,op2
        j&oper $ + 5
        $salvar
        nop
        nop
        nop
   endm


;************endwhile
endwhile macro
        $recup
$hueco = $simbolo
        $recup
$bucle = $simbolo
        jmp $bucle
$fin = this near
        org $hueco
        jmp $fin
        org $fin
  endm


$salvar macro
        ifndef $i
           $i = 0
        endif
        $i = $i + 1
        $salvar1 %$i
endm

$salvar1 macro $i
$sim_&$i = this near
endm

$recup macro
      $recup1 %$i
$i = $i - 1
endm

$recup1 macro $i
        ifndef $sim_&$i
         .lall
         .sall
       endif
$simbolo = $sim_&$i
endm