Vistas de página en total

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

jueves, 4 de julio de 2013

CONCATENAR CADENAS


    Esta función completa las funciones de manejo de cadenas. En este caso concatena dos cadenas.
    En este caso vamos a sumar dos cadenas y las vamos a trasladar a una nueva.
    Los parámetros se pasan por pila. En este programa usaré la versión para ASM. En TASM 2.0 podremos substituir [bp].fuente1 por fuente1 usando el comando user . 

    Ver el paso a TASM en http://myassembler.blogspot.com/2013/08/pasamos-integrar-tasm-20.html

STRCAT.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
extrn _strcpy:near
extrn _strlen:near
_modelo exe

_code
rutina _strcat  dest,fuent1,fuent2
        push bx                                           ;Salva registro usado en el programa
        mov ax,[bp].fuent1                       ;toma los parámetros pasados por pila
        push ax                                           ;lo guarda como fuente para la 1ª  llamada a strcpy
        mov ax,[bp].dest                            ;toma los parámetros pasados por pila
        push ax                                           ;lo guarda como destino para la 1ª  llamada a strcpy
        call _strcpy                                     ; llama a copia de string
        pop ax                                             ;recupera la dirección destino de pila
        pop bx                                             ;elimina el otro dato de pila
        mov bx,ax                                       ;guarda la dirección del destino para luego en bx
        push ax                                           ; lo almacena en piula para strlen
        call _strlen                                        ;calcula la longitud
        add sp,2                                             ;elimina los datos de pila
        add bx,ax                                         ;suma al offset de destino, la longitud de destino
        mov ax,[bp].fuent2                         ;Toma la dirección del segundo string 
        push ax                                              ;lo almacena en pila para llamada a strcpy
        push bx                                            ; almacena el offset de destino, que ahora es nuevo
        call _strcpy                                         ;llama a copia de string
        add sp,4                                            ;recupera la pila
        pop bx                                               ;recupera el registro bx
rutina_end    
_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