domingo, 20 de noviembre de 2016
emu8086 pregunta (10)
ejemplo 1
org 100h
comienzo:
mov si, x
mov al, msg2[si]
cmp msg[si], al ;comparar letra por letra las cadenas, si uno no coincide manda directamente a fin y termina el programa
jne fin:
cmp msg[si], "$" ;si es el final y el programa llega aca, quiere decir que son iguales
jz final:
inc x
loop comienzo
final:
mov dx, offset msg3
mov ah, 9
int 21h
fin:
ret
msg db "hello world $"
msg2 db "hello world $"
msg3 db "Son iguales $"
x dw 0
ejemplo 2
ORG 100h
MOV SI, 0 ;ponemos si en 0
comienzo:
MOV AL, msg2[0] ;copiar la primera letra de la palabra a al
CMP msg[SI],"$" ;si es el fin de la cadena mandar a final
JZ final
CMP msg[SI], AL ;comparar si encuentra la primera letra de la cadena
JNE seguir
MOV DI, 1 ;poner en 1 di
comprobar:
MOV AL, msg2[DI]
MOV BX, DI
CMP msg[SI+BX], AL ;posicion de la letra coincidente + di, comparar con la cadena
JNE seguir ;si no coincide mandar a seguir
INC DI ;incrementar di para seguir recorriendo cadena
CMP msg2[DI],"$" ;si es el fin de la cadena y el programa llego aca quiere decir que la cadena es parte de la palabra
JZ resultado
LOOP comprobar ;bucle para recorrer cadena
seguir:
INC SI ;para seguir recorriendo la palabra
LOOP comienzo ;bucle principal para recorrer palabra
resultado:
MOV DX, OFFSET msg3 ;copiar msg3 a dx
MOV AH, 9 ;preparar ah con 9 para la interrupcion 21h
INT 21h ;mostrar contenido en dx
final:
RET
msg DB "Hola Mundo$"
msg2 DB "ola$"
msg3 DB "Si es subcadena$"
ejemplo 3
name "calc-sum"
ORG 100h ; directive make tiny com file.
; calculate the sum of elements in vector,
; store result in m and print it in binary code.
; number of elements:
MOV CX, 5
; al will store the sum:
MOV AL, 0
; bx is an index:
MOV BX, 0
; sum elements:
next: ADD AL, vector[BX]
; next byte:
INC BX
; loop until cx=0:
LOOP next
; store result in m:
MOV m, AL
; print result in binary:
MOV BL, m
MOV CX, 8
print: MOV AH, 2 ; print function.
MOV DL, '0'
TEST BL, 10000000b ; test first bit.
JZ zero
MOV DL, '1'
zero: INT 21h
SHL BL, 1
LOOP print
; print binary suffix:
MOV DL, 'b'
INT 21h
MOV DL, 0ah ; new line.
INT 21h
MOV DL, 0dh ; carrige return.
INT 21h
; print result in decimal:
MOV AL, m
CALL print_al
; wait for any key press:
MOV AH, 0
INT 16h
RET
; variables:
vector DB 5, 4, 5, 2, 1
m DB 0
print_al PROC
CMP AL, 0
JNE print_al_r
PUSH AX
MOV AL, '0'
MOV AH, 0eh
INT 10h
POP AX
RET
print_al_r:
PUSHA
MOV AH, 0
CMP AX, 0
JE pn_done
MOV DL, 10
DIV DL
CALL print_al_r
MOV AL, AH
ADD AL, 30h
MOV AH, 0eh
INT 10h
JMP pn_done
pn_done:
POPA
RET
ENDP
ejemplo 4
org 100h;
jmp inicio;
titulo db "Presentacion de Integrantes!! $";
integrante1 db "Primer Integrante $";
nombre1 db " Mi Nombre es Diana $";
Edad1 db "Mi Edad: Tengo 21 Años $";
Vivo1 db "Vivo en: Cerca del Portal 80 Barrio Bolivia $"
MeGusta db "Me gustan los Perros $";
integrante2 db "Segundo Integrante $";
nombre2 db " Mi Nombre es Edgar Andres Ortiz $";
Edad2 db "Mi Edad: Tengo 26 Anos $";
Vivo2 db "Vivo en: Suba Barrio Nueva Tibabuyes $";
Trabajo db "Trabajo como Coordinador TIC en una empresa de Gestión Documental$";
inicio:;
mov ah,9;
mov dx,offset titulo;
int 21h;
mov ah,9;
mov dx,offset integrante1;
int 21h;
mov ah,9;
mov dx,offset nombre1;
int 21h;
mov ah,9;
mov dx,offset Edad1;
int 21h;
mov ah,9;
mov dx,offset Vivo1;
int 21h;
mov ah,9;
mov dx,offset MeGusta;
int 21h;
mov ah,9;
mov dx,offset integrante2;
int 21h;
mov ah,9;
mov dx,offset nombre2;
int 21h;
ejemplo 5
name "calc-sum"
ORG 100h ; directive make tiny com file.
; calculate the sum of elements in vector,
; store result in m and print it in binary code.
; number of elements:
MOV CX, 5
; al will store the sum:
MOV AL, 0
; bx is an index:
MOV BX, 0
; sum elements:
next: ADD AL, vector[BX]
; next byte:
INC BX
; loop until cx=0:
LOOP next
; store result in m:
MOV m, AL
; print result in binary:
MOV BL, m
MOV CX, 8
print: MOV AH, 2 ; print function.
MOV DL, '0'
TEST BL, 10000000b ; test first bit.
JZ zero
MOV DL, '1'
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario