ðH www.oocities.org/ar /moni2201/edusumar.htm www.oocities.org/ar/moni2201/edusumar.htm .delayed x 7€ÕJ ÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ `hˆ T² OK text/html pÑ2÷ T² ÿÿÿÿ b‰.H Wed, 26 Jun 2002 14:07:49 GMT D Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98) en, * 5€ÕJ T²
;El siguiente programa nos permite representar las
operaciones que se realiza durante una
;suma,describiendo cada numero y representarlo en cada renglon
.MODEL
SMALL
.STACK
200h
.DATA
.CODE
;------------------------------------------------------------------------------------------------------------------------
.DATA
;===================================================================
;INTRODUCCION DE DATOS
;DEFINICION
DE DATOS
;se
escriben los datos de texto y los espacios para pasar a otro renglon
nombre DB “Programa que realiza la suma de dos
numeros de cuatro digitos $”
Espacio2
DB “
$”
PrimerNumero DB "
Primer numero: $"
;primer texto
Espacio DB “
$”
SegundoNumero
DB “Segundo numero: $”
Resultado DB “Resultado de la suma : $”
;observar que al terminar el string se
coloca el signo $
.CODE
;====================================================================
;COMIENZO
DEL PROGRAMA
START:
;---------------------------------------------------------------------------------------------------------------------------
;se
escribe el nombre del progama: Programa que realiza la suma de dos numeros de
cuatro digitos
mov
ax,seg nombre
mov
ds,ax
mov
dx,offset nombre
mov
ah,9h
int
21h
mov
ax,seg espacio2
mov
ds,ax
mov
dx,offset espacio2
mov
ah,9h
int
21h
;------------------------------------------------------------------------------------------------------------------------------
;se
escribe el primer texto PRIMER NUMERO
MOV AX, SEG PrimerNumero ; Move the segment
where PrimerNumero is located
MOV DS, AX
; into AX, and now into DS
MOV
DX, OFFSET PrimerNumero ;
Offset of PrimerNumero -> DX
MOV AH, 9h
; Print string subfunction
;======================================================================
; Introduccion del primer
numero y su presentacion en pantalla
;trasnferimos
el valor de CX a BX para generar un lugar de memoria conocido
TRANSFERIR:
MOV
BX,CX
;---------------------------------------------------------------------------------------------------------------------------
;esta operacion introduce el dato
del teclado y lo guarda en AL
MOV AH,7h
INT 21h
MOV
DL,AL ;hacemos AL ---> DL ya que DL sera lo que se
imprima
; esta operacion imprime
lo guardado en DL
MOV
AH,2h
INT
21h
;-----------------------------------------------------------------------------------------------------
SUB
AL,030h ;convierte el
numero ascii a hex
;------------------------------------------------------------------------------------------------------
;transferimos
el dato al lugar de memoria
MOV
[BX],AL
;------------------------------------------------------------------------------------------------------
;aumentamos
al contador en 1
ADD
CX,1h
;------------------------------------------------------------------------------------------------------
;comparamos
para saber si llegamos a la cantidad de lugares de memoria en este
;caso
4,con esto definimos el largo del numero
CMP
CX,04h
JZ
TERMINAR
;si llega a 4 terminamos el primer numero
JMP
TRANSFERIR ;si
no llega a 4 continuamos
terminar:
;-----------------------------------------------------------------------------------------------------------------------------
;lo siguiente es una tecnica para pasar al otro renglon
MOV AX, SEG Espacio ; Move the segment
where Espacio is located
MOV DS, AX
; into AX, and now into DS
MOV
DX, OFFSET Espacio ; Offset
of Espacio -> DX
MOV AH, 9h
; Print string subfunction
INT 21h
; Generate interrupt 21h
;====================================================================
;INTRODUCCION DEL SEGUNDO NUMERO
MOV AX, SEG SegundoNumero ; Move the segment
where SegundoNumero is located
MOV DS, AX
; into AX, and now into DS
MOV
DX, OFFSET SegundoNumero ;
Offset of SegundoNumero -> DX
MOV AH, 9h
; Print string subfunction
INT 21h
; Generate interrupt 21h
;----------------------------------------------------------------------------------------------------------------------------
;introducir
el dato numerico y lo presentamos en pantaya
;trasnferimos
el valor de CX a BX para generar un lugar de memoria conocido
TRANSFERIRa:
MOV
BX,CX
;------------------------------------------------------------------------------------------------------
;esta operacion introduce el dato
del teclado y lo guarda en AL
INT 21h
MOV
DL,AL ;hacemos AL ---> DL ya que DL sera lo que se
imprima
; esta operacion
imprime lo guardado en DL
MOV
AH,2h
INT
21h
;-----------------------------------------------------------------------------------------------------
SUB
AL,030h ;convierte el
numero ascii a hex
;------------------------------------------------------------------------------------------------------
;transferimos
el dato al lugar de memoria
MOV
[BX],AL
;------------------------------------------------------------------------------------------------------
;aumentamos
al contador en 1
ADD
CX,1h
;------------------------------------------------------------------------------------------------------
;comparamos
para saber si llegamos a la cantidad de lugares de memoria en este
;caso
4,con esto definimos el largo del numero
CMP
CX,08h
JZ
TERMINARa
;si llega a 4 terminamos el primer numero
JMP
TRANSFERIRa ;si
no llega a 4 continuamos
TERMINARa:
;------------------------------------------------------------------------------------------------------------------------------
;lo siguiente es una tecnica para pasar al otro renglon
MOV AX, SEG Espacio
; Move the segment where Espacio is located
MOV DS, AX
; into AX, and now into DS
MOV
DX, OFFSET Espacio1
; Offset of Espacio1 -> DX
MOV AH, 9h
; Print
string subfunction
INT 21h
; Generate interrupt 21h
;-----------------------------------------------------------------------------------------------------------------------------
MOV AX, SEG Resultado
; Move the segment where Resultado is located
MOV DS, AX
; into AX, and now into DS
MOV
DX, OFFSET Resultado
; Offset of Resltado -> DX
MOV AH,
9h
; Print string subfunction
INT 21h
; Generate interrupt 21h
;----------------------------------------------------------------------------------------------------------------------------
;dar a la variable
contador de suma el valor 3h y usar la posicion de memoria 8h
mov bx,08h
mov ax,03h
mov [bx],ax
;dar a la variable
acarreo el valor 0h,usar la posicion de memoria 9h
mov bx,09h
mov ax,0h
mov [bx],ax
;extraer de memoria el
valor del contador suma
mov bx,08h
mov cx,[bx]
sumar:
;extraer de la posicion
de memoria dada por el contador suma el numero a sumar
mov bl,cl
mov bh,0h
;transferirlo a AL
mov al,[bx]
;averiguar si variable
acarreo es igual a 1h
mov bx,09h
mov dx,[bx]
cmp dx,1h
jz sumar_acarreo
jmp no_sumar_acarreo
sumar_acarreo:
add al,dl
no_sumar_acarreo:
;guardar el valor del
contador suma en la posicion de memoria 8h
mov bx,8h
mov [bx],cl
;sumar al contador suma
4h
add cx,04h
;sacar de memoria el
otro numero a sumar
mov bl,cl
mov bh,0h
mov dx,[bx]
mov ah,dl
;sumar
add ah,al
;BLOQUE BETA
CMP AH,0h
JZ PRESENTAR_CERO
JMP UNO
PRESENTAR_CERO:
MOV
DL,30h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
UNO:
CMP AH,1h
JZ PRESENTAR_UNO
JMP DOS
PRESENTAR_UNO:
MOV
DL,31h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
DOS:
CMP AH,2h
JZ PRESENTAR_DOS
JMP TRES
PRESENTAR_DOS:
MOV
DL,32h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
TRES:
CMP AH,3h
JZ PRESENTAR_TRES
JMP CUATRO
PRESENTAR_TRES:
MOV
DL,33h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
;------------------------------------------------------------------------------------------------------
CUATRO:
CMP AH,4h
JZ PRESENTAR_CUATRO
JMP SINCO
PRESENTAR_CUATRO:
MOV
DL,34h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
SINCO:
CMP AH,5h
JZ PRESENTAR_SINCO
JMP SEIS
PRESENTAR_SINCO:
MOV
DL,35h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
SEIS:
CMP AH,6h
JZ PRESENTAR_SEIS
JMP SIETE
PRESENTAR_SEIS:
MOV
DL,36h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
SIETE:
CMP AH,7h
JZ PRESENTAR_SIETE
JMP OCHO
PRESENTAR_SIETE:
MOV
DL,37h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
OCHO:
CMP AH,8h
JZ PRESENTAR_OCHO
JMP NUEVE
PRESENTAR_OCHO:
MOV
DL,38h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
NUEVE:
CMP AH,9h
JZ PRESENTAR_NUEVE
JMP DIEZ
PRESENTAR_NUEVE:
MOV
DL,39h ; DL sera lo que se
guarda
;si
no hay resto guardamos en 09h =0h
MOV
BX,09h
MOV
AL,0h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
DIEZ:
CMP AH,0Ah
JZ PRESENTAR_DIEZ
JMP ONCE
PRESENTAR_DIEZ:
MOV
DL,30h ; DL sera lo que se
guarda
;si
hay resto guardamos en la posicion de memoria 09h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
ONCE:
CMP AH,0Bh
JZ PRESENTAR_ONCE
JMP DOCE
PRESENTAR_ONCE:
MOV
DL,31h
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
DOCE:
CMP AH,0Ch
JZ PRESENTAR_DOCE
JMP TRECE
PRESENTAR_DOCE:
MOV
DL,32h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
TRECE:
CMP AH,0Dh
JZ PRESENTAR_TRECE
JMP CATORCE
PRESENTAR_TRECE:
MOV
DL,33h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
CATORCE:
CMP AH,0Eh
JZ PRESENTAR_CATORCE
JMP QUINCE
PRESENTAR_CATORCE:
MOV
DL,34h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
QUINCE:
CMP AH,0Fh
JZ PRESENTAR_QUINCE
JMP DIEZYSEIS
PRESENTAR_QUINCE:
MOV
DL,35h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
DIEZYSEIS:
CMP AH,10h
JZ PRESENTAR_DIEZYSEIS
JMP DIEZYSIETE
PRESENTAR_DIEZYSEIS:
MOV
DL,36h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
DIEZYSIETE:
CMP AH,11h
JZ PRESENTAR_DIEZYSIETE
JMP DIEZYOCHO
PRESENTAR_DIEZYSIETE:
MOV
DL,37h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
DIEZYOCHO:
CMP AH,12h
JZ PRESENTAR_DIEZYOCHO
JMP DIEZYNUEVE
PRESENTAR_DIEZYOCHO:
MOV
DL,38h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
;------------------------------------------------------------------------------------------------------
DIEZYNUEVE:
CMP AH,13h
JZ PRESENTAR_DIEZYNUEVE
PRESENTAR_DIEZYNUEVE:
MOV
DL,39h ; DL sera lo que se
guarda
;si
hay resto guardamos en 09h =01h
MOV
BX,09h
MOV
AL,01h
MOV
[BX],AL
JMP
PI
PI:
;guardar el contenido de
dl en la ultima posicion de memoria de los mumeros a sumar
mov bl,cl
mov bh,0h
sub cx,04h
mov dh,cl
mov [bx],dl
;extraer el valor del
contador suma de la memoria
mov bx,08h
mov cl,[bx]
;decrementar al contador
suma
dec cx
mov bx,08h
mov [bx],cl
;comparar el valor del
contador suma con –1d
cmp cx,0ffffh
jz terminar_suma
jmp sumar
terminar_suma:
;extraer
el resultado
mov
cx,04h
mov
bx,09h
mov
dl,[bx]
cmp
dl,1h
jz
impuno
jmp
seguir
impuno:
mov
dl,31h
mov
ah,2h
int
21h
seguir:
mov
bx,cx
mov
dl,[bx]
INT
21h
Add
cx,1h
Cmp
cx,8h
Jz
termina
Jmp
seguir
Termina:
;se
sale a DOS
MOV AX, 4C00h
; Exit to DOS sufunction
INT 21h
; Generate interrupt 21h