Programas en lenguaje ensamblador.

Programas en lenguaje ensamblador.


A continuación, se muestran los programas desarrollados en lenguaje ensamblador que se realizaron desde el programa emu8086.

Programa 1:
Programa que muestra un mensaje en pantalla "Hola mundo".




.model small se utiliza para establecer el tamaño del programa en ensamblador, como en este caso realizamos un programa pequeño seleccionamos la palabra small.
.model small
.data
saludo db " HOLA MUNDO CYNTHIA " , "$"
.code
programa:
mov ax, seg saludo
mov ds, ax
mov ah, 09h
lea dx, saludo
int 21h
mov ax, 4c00h
int 21h
end programa
view raw Programa1.asm hosted with ❤ by GitHub


Programa 2
Programa que convierte números decimales a binarios.
name "Decimal a Binario"
org 100h
jmp start
;mensaje en pantalla:
msg1 db 0Dh,0Ah, "Ingrese cualquier numero de -32768 a 65535, o presione cero para salir: $"
msg2 db 0Dh,0Ah, "El numero binario es: $"
;buffer para int 21/0ah
;primer byte es en el tamano del buffer,
;segundo byte es el numero de chars actualmente leidos (establecer por int 21h/0ah).
buffer db 7,?,5dup (0), 0, 0
;para resultados
binary dw ?
start:
; imprime mensaje de bienvenida:
mov dx, offset msg1
mov ah, 9
int 21h
; input string:
mov dx, offset buffer
mov ah, 0ah
int 21h
;presionar 0 para terminar:
mov bx, 0
mov bl, buffer[1]
mov buffer[bx+2], 0
lea si, buffer + 2 ; buffer inicia el 3er byte.
call tobin
; el numero se guarda en el registro cx.
; de '-1234' it's 0fb2eh
mov binary, cx
jcxz stop
; imprime el pre resultado:
mov dx, offset msg2
mov ah, 9
int 21h
;imprime en forma binaria
mov bx, binary
mov cx, 16
print: mov ah, 2 ;imprime funcion
mov dl, '0'
test bx, 1000000000000000b ;teste el primer byte.
jz zero
mov dl, '1'
zero: int 21h
shl bx, 1
loop print
; imprime el suffix:
mov dl, 'b'
int 21h
jmp start ; loop
stop:
ret ; regresar el sistema del control.
; este procedimiento convierte un numero a string a
; numero binario. el numero puede tener el signo ('-').
; el resultado esta guardado en el registro cx.
; parametros:
; si - direccion de numero string (cero terminado).
tobin proc near
push dx
push ax
push si
jmp process
; === variables locales ===
make_minus db ? ; usando como una bandera.
ten dw 10 ; usando un multiplier.
;=========================
process:
; reiniciar el acumulador:
mov cx, 0
; resetear la bandera:
mov cs: make_minus, 0
next_digit:
; leer char a al y
; apuntar a el siguiente byte:
mov al,[si]
inc si
; checar el final del string:
cmp al, 0 ;termina el string?
jne not_end
jmp stop_input
not_end:
; chequeo para el minimo:
cmp al, '-'
jne ok_digit
mov cs:make_minus, 1 ;establecer bandera!
jmp next_digit
ok_digit:
; multiplicar cx por 10 (primera vez que el resultado es cero)
push ax
mov ax, cx
mul cs:ten ; dx:ax = ax*10
mov cx, ax
pop ax
; es asumido que dx is cero - overflox no cheacado
; convertir de codigo ascill :
sub al, 30h
; agregar al to cx:
mov ah, 0
mov dx, cx ; respaldo, en caso que el resultado sea muy grande.
add cx, ax
; agregar - overflow no checado
jmp next_digit
stop_input:
;checar bandera, si numero string tenia '-'
; estar seguro que el resultado es negativo:
cmp cs:make_minus, 0
je not_minus
neg cx
not_minus:
pop si
pop ax
pop dx
ret
tobin endp
view raw Programa2.asm hosted with ❤ by GitHub

Programa 3:
Programa que convierte las palabras minúsculas ingresadas desde el teclado a mayúsculas.

name "int02"
ORG 100H
lectura:
mov ah,7
int 21h
mov tecla, al
cmp al,13
jz fin:
cmp tecla, 122 ;si tecla es mayor a 122 entonces ir a fin3 (tecla > 122)
ja fin3
cmp tecla,96 ;si tecla no es mayor a 96 ir a fin3 (tecla <= 96)
jng fin3
sub tecla, 32 ;si es 'a' hasta 'z' entonces restarle 32
fin3:
mov ah,2
mov dl,tecla
int 21h
jmp lectura
fin:
ret
tecla db 0
view raw Programa3.asm hosted with ❤ by GitHub

Programa 4:
Programa que imprime un marco.

title programa que imprime un marco
.model small
.stack 64
.data
car db '*','$'
col db 0
ren db 0
.code
begin proc far
mov ax,@data
mov ds,ax
;limpiar pantalla
mov ax,0600h
mov bh,71h
mov cx,0000h
mov dx,184fh
int 10h
;imprimir lineas horizontales
mov cx,80
a10:
;colocar cursor
mov ah,02h
mov bh,00
mov dh,0 ;renglon 0
mov dl,col ;columna
int 10h
;imprimir *
mov ah,09h
lea dx,car
int 21h
;colocar cursor
mov ah,02h
mov bh,00
mov dh,22
mov dl,col
int 10h
;imprimir *
mov ah,09h
lea dx,car
int 21h
inc col
loop a10
;imprimir lineas verticales
mov cx,23
a20:
;colocar cursor
mov ah,02h
mov bh,00
mov dh,ren
mov dl,0
int 10h
;imprimir
mov ah,09h
lea dx,car
int 21h
;colocar cursor
mov ah,02h
mov bh,00
mov dh,ren
mov dl,79
int 10h
;imprimir
mov ah,09h
lea dx,car
int 21h
inc ren
loop a20
mov ax,4c00h
int 21h
begin endp
end begin
view raw Progrma4.asm hosted with ❤ by GitHub

Programa 5:
Programa que cuenta con una variable para guardar nombre completo, otra para guardar nombre y otra para guardar apellido, el programa debe pasar el contenido de la variable nombre a la de nombre completo y posteriormente hacer lo mismo con la de apellido.

.stack 64
.data
nom db 'CYNTHIA ','$'
ape db 'RAMIREZ','$'
nomcom db 'ABCDEFGHIJKLMNO','$'
.code
begin proc far
mov ax,@data
mov ds,ax
mov es,ax
mov cx,08
lea si,nom
lea di,nomcom
b20:
mov al,[si]
mov [di],al
inc si
inc di
dec cx
jnz b20
mov cx,07
lea si,ape
b21:
mov al,[si]
mov [di],al
inc si
inc di
dec cx
jnz b21
mov ah,09h ;peticion para desplegar
lea dx,nomcom ;carga la direccion de la indicacion
int 21h ;llama al dos
mov ax,4c00h
int 21h
begin endp
end begin
view raw Programa 5 hosted with ❤ by GitHub

Programa 6:
Programa que permite generar la serie: X= 1 / 1 + 1 / 2 + 1 / 3 + 1 / 4 + 1 / 5 + 1 / 6 + 1 / 7 + 1 / 8 + 1 / 9.

.model small
.stack 64
.data
num db 0
alta db 0
baja db 0
msjr db '1 / $'
.code
inicio:
mov dx, @data
mov ds, dx
mov cx, 09h
serie:
lea dx, msjr
mov ah, 9h
int 21h
add num, 01h
mov al, num
aam
mov alta, ah
mov baja, al
mov ah, 02h
mov dl, alta
add dl, 30h
int 21h
mov ah, 02h
mov dl, baja
add dl, 30h
int 21h
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl, 0dh
int 21h
loop serie
mov ax, 4c00h
int 21h
end
view raw Programa 6.asm hosted with ❤ by GitHub


Programa 7:
Programa que permite generar la serie X= 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0.

.model small
.stack 64
.data
num db 11
alta db 0
baja db 0
.code
inicio:
mov dx, @data
mov ds, dx
mov cx, 11
serie:
sub num, 01h
mov al, num
aam
mov alta, ah
mov baja, al
mov ah, 02h
mov dl, alta
add dl, 30h
int 21h
mov ah, 02h
mov dl, baja
add dl, 30h
int 21h
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl, 0dh
int 21h
loop serie
mov ax, 4c00h
int 21h
end
view raw Programa7.asm hosted with ❤ by GitHub


Programa 8:
Programa que permite generar la siguiente serie: X = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.


.model small
.stack 64
.data
num db 0
alta db 0
baja db 0
.code
inicio:
mov dx, @data
mov ds, dx
mov cx, 10
serie:
add num, 01h
mov al, num
aam
mov alta, ah
mov baja, al
mov ah, 02h
mov dl, alta
add dl, 30h
int 21h
mov ah, 02h
mov dl, baja
add dl, 30h
int 21h
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl, 0dh
int 21h
loop serie
mov ax, 4c00h
int 21h
end
view raw Programa7.asm hosted with ❤ by GitHub

Programa 9:
Programa que permite generar la siguiente serie: X = 2 / 1 + 4 / 2 + 6 / 3 + 8 / 4 + 10 / 5 + 12 / 6 + 14 / 7 + 16 / 8 + 18 / 9.



.model small
.stack 64
.data
num db 0
alta db 0
baja db 0
nro db 0
alt db 0
baj db 0
msjr db ' / $'
.code
inicio:
mov dx, @data
mov ds, dx
mov cx, 09h
serie:
add num, 02h
mov al, num
aam
mov alta, ah
mov baja, al
mov ah, 02h
mov dl, alta
add dl, 30h
int 21h
mov ah, 02h
mov dl, baja
add dl, 30h
int 21h
lea dx, msjr
mov ah, 9h
int 21h
;segundo proceso
add nro, 01h
mov al, nro
aam
mov alt, ah
mov baj, al
mov ah, 02h
mov dl, alt
add dl, 30h
int 21h
mov ah, 02h
mov dl, baj
add dl, 30h
int 21h
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl, 0dh
int 21h
loop serie
mov ax, 4c00h
int 21h
end
view raw Programa8.asm hosted with ❤ by GitHub

Programa 10:
Programa que permite generar la siguiente serie: X = 2 / 3 + 4 / 6 + 6 / 9 + 8 / 12 + 10 /1 5 + 12 / 18 + 14 / 21 + 16 / 24 + 18 / 27.

.model small
.stack 64
.data
num db 0
alta db 0
baja db 0
nro db 0
alt db 0
baj db 0
msjr db ' / $'
.code
inicio:
mov dx, @data
mov ds, dx
mov cx, 09h
serie:
add num, 02h
mov al, num
aam
mov alta, ah
mov baja, al
mov ah, 02h
mov dl, alta
add dl, 30h
int 21h
mov ah, 02h
mov dl, baja
add dl, 30h
int 21h
lea dx, msjr
mov ah, 9h
int 21h
;segundo proceso
add nro, 03h
mov al, nro
aam
mov alt, ah
mov baj, al
mov ah, 02h
mov dl, alt
add dl, 30h
int 21h
mov ah, 02h
mov dl, baj
add dl, 30h
int 21h
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl, 0dh
int 21h
loop serie
mov ax, 4c00h
int 21h
end
view raw Programa10.asm hosted with ❤ by GitHub

Programa 11:
Programa que permite generar los primeros 12 términos de la tabla de multiplicar del 4. Ejemplo: 4 x 1 = 4 … 4 x 12 = 48.

.model small
.stack 64
.data
num db 0
alta db 0
baja db 0
nro db 0
alt db 0
baj db 0
msjr db '4 x $'
msj1 db ' = $'
.code
inicio:
mov dx, @data
mov ds, dx
mov cx, 12
serie:
lea dx, msjr
mov ah, 9h
int 21h
add num, 01h
mov al, num
aam
mov alta, ah
mov baja, al
mov ah, 02h
mov dl, alta
add dl, 30h
int 21h
mov ah, 02h
mov dl, baja
add dl, 30h
int 21h
lea dx, msj1
mov ah, 9h
int 21h
;segundo proceso
add nro, 04h
mov al, nro
aam
mov alt, ah
mov baj, al
mov ah, 02h
mov dl, alt
add dl, 30h
int 21h
mov ah, 02h
mov dl, baj
add dl, 30h
int 21h
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl, 0dh
int 21h
loop serie
mov ax, 4c00h
int 21h
end
view raw Programa11.asm hosted with ❤ by GitHub


Programa 12:
Programa que permite generar los primeros 12 términos de la tabla de multiplicar del 3. Ejemplo: 3 x 1 = 3 … 3 x 12 = 36.

.model small
.stack 64
.data
num db 0
alta db 0
baja db 0
nro db 0
alt db 0
baj db 0
msjr db '3 x $'
msj1 db ' = $'
.code
inicio:
mov dx, @data
mov ds, dx
mov cx, 12
serie:
lea dx, msjr
mov ah, 9h
int 21h
add num, 01h
mov al, num
aam
mov alta, ah
mov baja, al
mov ah, 02h
mov dl, alta
add dl, 30h
int 21h
mov ah, 02h
mov dl, baja
add dl, 30h
int 21h
lea dx, msj1
mov ah, 9h
int 21h
;segundo proceso
add nro, 03h
mov al, nro
aam
mov alt, ah
mov baj, al
mov ah, 02h
mov dl, alt
add dl, 30h
int 21h
mov ah, 02h
mov dl, baj
add dl, 30h
int 21h
mov ah, 02h
mov dl, 0ah
int 21h
mov ah, 02h
mov dl, 0dh
int 21h
loop serie
mov ax, 4c00h
int 21h
end
view raw Programa12.asm hosted with ❤ by GitHub

Programa 13:
Programa que imprime X en la pantalla hasta que es presionada la tecla ESC.

name "keybrd"
org 100h
; print a welcome message:
mov dx, offset msg
mov ah, 9
int 21h
;============================
; eternal loop to get
; and print keys:
wait_for_key:
; check for keystroke in
; keyboard buffer:
mov dh, pos
mov dl, pos
mov bh, 0
mov ah, 2
int 10h ;Movemos el cursor
mov al,'X'
mov bh,0
mov bl,1
mov cx,1
mov ah,09h
inc pos ;Imprimimos una x
int 10h
mov ah, 1
int 16h
jz wait_for_key
; get keystroke from keyboard:
; (remove from the buffer)
mov ah, 0
int 16h
; print the key:
mov ah, 0eh
int 10h
; press 'esc' to exit:
cmp al, 1bh
jz exit
jmp wait_for_key
;============================
exit:
ret
msg db "Type anything...", 0Dh,0Ah
db "[Enter] - carriage return.", 0Dh,0Ah
db "[Ctrl]+[Enter] - line feed.", 0Dh,0Ah
db "You may hear a beep", 0Dh,0Ah
db " when buffer is overflown.", 0Dh,0Ah
db "Press Esc to exit.", 0Dh,0Ah, "$"
pos db 1
end
view raw Programa13.asm hosted with ❤ by GitHub

Comentarios

Entradas más populares de este blog

Lista de mnemónicos para lenguaje ensamblador

1.4 Aspectos matemáticos de la graficación (geometría fractal)

¿Qué es PIP para Python?