Vistas de página en total

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

miércoles, 12 de junio de 2013

PASO A MAYUSCULAS

    Para crear lo básico de STRING, comenzaremos por la función de paso a mayusculas de una cadena. La función la llamo MAY aunque la macro se llama STRUPR.
   Esta función es necesaria para posteriormente convertir las cadenas en números en ATOI.



MAY.ASM

; 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
_modelo exe
_code 
rutina _may text
        push bx
        mov bx,[bp].text
mayusc:
        cmp byte ptr [bx],0
        je fin
        cmp byte ptr [bx],'a'
        jb otro
        cmp byte ptr [bx],'z'
        ja otro
        sub byte ptr [bx],'a'-'A'
        jmp otro1
otro:
        cmp byte ptr [bx],'¤'
        jne otro1
        mov byte ptr [bx],'¥'
otro1:
        inc bx
        jmp mayusc
fin:
        pop bx
        pop bp
        ret
endp
_data
_end

lunes, 10 de junio de 2013

DECLARACIÓN FUNCIONES DE CADENA

        Vamos a ver y crear parte de la librería STRING, la cual servirá para el manejo de cadenas. Es importante hacer parte de esta librería enseguida pues en ella tenemos la función itoa y atoi, que vamos a necesitar en las funciones Scanf y Prinf de la librería básica STDIO.
     Por ello comenzaré con la  cabecera STRING.MAC y posteriormente las funciones atoi y itoa, para poder realizar una parte muy importante de la librería que necesitaremos posteriormente para la librerías STDIO.
    Con esta parte de String y la posterior STDIO, estaremos ya en condiciones de hacer nuestros primeros programas de entrada y salida de texto y valores por pantalla.
 
     Como veis, no hace falta decir mucho de las funciones, pues son estructuras iguales a las anteriores, para las llamadas a las funciones auxiliares. Los nombres son parecidos a los usados en C.
      Con estas funciones podremos manejar los textos que entremos por teclado y presentarlos de forma adecuada. Igualmente, cuando más tarde creemos la librería FILE y IO, podremos crear bases de datos con sus ALTAS-BAJAS-MODIFICACIONES.
       Como podemos crear la macro, pero no usarla, podremos hacer el fichero .MAC con todas las funciones, pero solo implementar en la librería itoa y atoi. Lo haremos así, dejando el resto para después de los primeros ejemplos.


STRING.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/>.

;pasa el caracter al a mayusculas
; se le puede pasar o no parámetro.
; Si no se le pasa parámetro asume que se pasa a mayusculas al
upr macro letra 
local salir
ifnb <letra>
        mov al,letra

endif
        cmp  al,'a'
        jb salir
        cmp al,'z'
        ja salir
        sub al,'a'-'A'
salir:
ifnb <letra>
        mov letra,al

endif
        endm

;pasa la cadena a mayusculas
strupr macro direccion
ifndef _may
    extrn _may:near
endif
        lea ax,direccion
        push ax
        call _may
        pop ax
endm

;devuelve la longitud de la cadena
STRLEN MACRO CADENA
ifndef _strlen
    extrn _strlen:near
endif
       lea AX,CADENA
       PUSH AX
       CALL _STRLEN
       ADD SP,2
ENDM

;compara dos cadenas devuelve las banderas como en una comparacion normal
strcmp macro destino,fuente
ifndef _strcmp
    extrn _strcmp:near
endif
        lea ax,fuente
        push ax
        lea ax,destino
        push ax
        call _strcmp
        pop ax
        pop ax
 endm

strcpy macro destino,fuente
ifndef _strcpy
    extrn _strcpy:near
endif
        lea ax,fuente
        push ax
        lea ax,destino
        push ax
        call _strcpy
        pop ax
        pop ax
 endm

strcut macro destino,inic,fin,fuente
ifndef _strcut
     extrn _strcut:near
endif
        lea ax,fuente
        push ax
        mov ax,fin
        push ax
        mov ax,inic
        push ax
        lea ax,destino
        push ax
        call _strcut
        add sp,8
 endm

strcat macro destino,fuente1,fuente2
 ifndef _strcat
      extrn _strcat:near
 endif
        lea ax,fuente2
        push ax
        lea ax,fuente1
        push ax
        lea ax,destino
        push ax
        call _strcat
        add sp,6
  endm


atoi macro destino,texto,base
  ifndef _atoi
        extrn _atoi:near
  endif
  ifb <base>
        mov ax,10
  else
        mov ax,base
  endif
        push ax
        lea ax,texto
        push ax
        lea ax,destino
        push ax
        call _atoi
        add sp,6
   endm


itoa macro destino,numero,base
ifndef _itoa
        extrn _itoa:near
endif
ifb <base>
        mov ax,10
else
        mov ax,base
endif
        push ax
        lea ax,numero
        push ax
        lea ax,destino
        push ax
        call _itoa
        add sp,6
 endm