Ensamblador - bucle y matriz

 
Vista:

bucle y matriz

Publicado por oscar (3 intervenciones) el 24/04/2007 19:18:14
Hola.
Estoy empezando en esto del ensamblador y hasta ahora bien. Pero estoy intentando hacer algo mas complicado y no tengo nada claro como hacerlo.

Necesito recorrer una matriz e ir comparando valores. Habia pensado en un bucle for anidado:Con el 1º bucle las filas
Con el 2º bucle las columnas que ha de tener cada fila

Me podeis echar una mano a implementarlo?

gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:bucle y matriz

Publicado por Asmprogramer (12 intervenciones) el 25/04/2007 01:38:56
A ver si te vale esto:

[email protected]

;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
; ;
; Email del Autor .... : [email protected] NUMERO ;
; ;
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
NUMERO MACRO FILA,COLUMNA
LOCAL no_es_cero,escribir_digitos,escribir,fin
LOCAL digitosnumero,findigitosnumero,otro_chr,sigue
LOCAL datanumero,loopear,detectado_primer_no_cero

; A esta MACRO hay que llamarla con el valor del
; n£mero en el registro DX.
;
; Por ejemplo :
;
; ÄÄ> mov dx,4593 <ÄÄ
; call numerar
; ret
; numerar:
; numero 10,10
; ret

digitos_16_bits EQU 5 ; Digitos que pueden representar 16 bits (65535)

push dx
push ax
push cx
push si
push di
push bx

mov ax,dx
mov si,10
mov cx,digitos_16_bits

no_es_cero:
xor dx,dx
div si
push dx
loop no_es_cero

mov bx,OFFSET DIGITOSNUMERO

mov cx,(digitos_16_bits)

escribir_digitos:
pop dx
call escribir
loop escribir_digitos
jmp fin
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
DIGITOSNUMERO LABEL BYTE
DATANUMERO DB digitos_16_bits DUP (0)
FINDIGITOSNUMERO LABEL BYTE
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
escribir PROC FAR

or dx,0000000000110000b
mov al,dl
mov cs:[bx],al
add bx,1

ret
escribir ENDP
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
fin:

mov di,(FILA - 1) * 160 + (COLUMNA - 1) * 2
mov si,OFFSET DIGITOSNUMERO

mov cx,(digitos_16_bits - 1)
otro_chr:
mov al,cs:[si]
cmp al,'0'
jz sigue
jmp detectado_primer_no_cero
sigue:
mov al,' '
mov ds:[di],al
add di,2
add si,1
loop otro_chr

detectado_primer_no_cero:
inc cx
loopear:
mov al,cs:[si]
mov ds:[di],al
add di,2
add si,1
loop loopear

pop bx
pop di
pop si
pop cx
pop ax
pop dx

ENDM

Continua........
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:bucle y matriz

Publicado por Asmprogramer (12 intervenciones) el 25/04/2007 01:44:05
......Viene del anterior......

;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
.MODEL SMALL
.CODE
ORG 100H
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
CERO EQU 0
UNO EQU 1
CGA EQU 0b800h
RASTREO_ESCAPE EQU UNO
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
MATRIZ PROC

push ax
push bx
push cx
push dx
push di
push si
push ds
push es

mov al,003h
mov ah,CERO
int 10h

mov ax,CGA
push ax
pop ds

call sub_cls
call sub_cuadro
call presentar_letras
call poner_frase
call comparar
call decir

hay_tecla_pulsada_?:
mov ah,UNO
int 16h
jnz hay_tecla_pulsada
jmp hay_tecla_pulsada_?
hay_tecla_pulsada:
mov ah,CERO
int 16h
es_escape_?:
cmp ah,rastreo_escape
jnz no_es_escape
jmp retorno
no_es_escape:
jmp hay_tecla_pulsada_?

retorno:
call sub_cls

pop es
pop ds
pop si
pop di
pop dx
pop cx
pop bx
pop ax

ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
sub_cls:

mov al,' '
mov di,380

mov cx,25
bucle_1:
push cx
push di
mov cx,80
bucle_2:
mov ds:[di],al
add di,2
loop bucle_2
pop di
add di,160
pop cx
loop bucle_1

ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
sub_cuadro:

mov di,380
mov si,OFFSET TABLERO

mov cx,7
buc_1:
push di
push cx
mov cx,9
buc_2:
mov al,cs:[si]
mov ds:[di],al
inc si
add di,2
loop buc_2
pop cx
pop di
add di,160
loop buc_1

ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
poner_frase:

mov di,1800
mov si,OFFSET FRASE

mov cx,2
buclecito_1:
push di
push cx
mov cx,((OFFSET FIN_FRASE - OFFSET FRASE) / 2)
buclecito_2:
mov al,cs:[si]
mov ds:[di],al
inc si
add di,2
loop buclecito_2
pop cx
pop di
add di,160
loop buclecito_1

ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
presentar_letras:

mov di,544
mov si,OFFSET LETRAS

mov cx,5
bu_1:
push cx
push di
mov cx,5
bu_2:
mov al,cs:[si]
mov ds:[di],al
add di,2
inc si
loop bu_2
pop di
add di,160
pop cx
loop bu_1

ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
comparar:

mov si,OFFSET LETRAS
mov dx,((5 * 5) - 1)

mov cx,((5 * 5) - 1)
bucL_1:
mov al,cs:[si]
mov bx,si
push cx
mov cx,dx
bucL_2:
inc bx
mov ah,cs:[bx]

COMMENT #
push ax ;
push bx ;
push cx ; Con estas instrucciones
push dx ; podras ver paso a paso
push di ; (pulsando una tecla)
push si ; las letras que se van comparando
push ds ; en cada iteracion
push es ;
;
mov ds:[0],al ;
mov ds:[2],ah ;
;
call decir ;
;
xor ax,ax ;
int 16h ;
;
pop es ;
pop ds ;
pop si ;
pop di ;
pop dx ;
pop cx ;
pop bx ;
pop ax ;
#

cmp al,ah
jz es_igual
jmp seguir_bucle
es_igual:
call incrementar_contador_igual
seguir_bucle:
loop bucL_2
dec dx
inc si
pop cx
loop bucL_1

ret
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:bucle y matriz

Publicado por Asmprogramer (12 intervenciones) el 25/04/2007 01:47:30
...... Viene del anterior.....


;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
incrementar_contador_igual:

push ax
push si

cmp al,'A'
jz es_a
cmp al,'B'
jz es_b
cmp al,'C'
jz es_c
cmp al,'D'
jz es_d
cmp al,'E'
jz es_e
cmp al,'F'
jz es_f
cmp al,'G'
jz es_g
cmp al,'H'
jz es_h
cmp al,'I'
jz es_i
cmp al,'J'
jz es_j
cmp al,'K'
jz es_k
cmp al,'L'
jz es_l
cmp al,'M'
jz es_m
cmp al,'N'
jz es_n
cmp al,'O'
jz es_o
cmp al,'P'
jz es_p
cmp al,'Q'
jz es_q
cmp al,'R'
jz es_r
cmp al,'S'
jz es_s
cmp al,'T'
jz es_t
cmp al,'U'
jz es_u
cmp al,'V'
jz es_v
cmp al,'W'
jz es_w
cmp al,'X'
jz es_x
cmp al,'Y'
jz es_y
cmp al,'Z'
jz es_z
es_otro_caracter:
call error_controlado ; Por aqui no debe de pasar
jmp salir_incrementar_contador_igual
es_a:
mov si,OFFSET LETRA_A
jmp incrementar_contador
es_b:
mov si,OFFSET LETRA_B
jmp incrementar_contador
es_c:
mov si,OFFSET LETRA_C
jmp incrementar_contador
es_d:
mov si,OFFSET LETRA_D
jmp incrementar_contador
es_e:
mov si,OFFSET LETRA_E
jmp incrementar_contador
es_f:
mov si,OFFSET LETRA_F
jmp incrementar_contador
es_g:
mov si,OFFSET LETRA_G
jmp incrementar_contador
es_h:
mov si,OFFSET LETRA_H
jmp incrementar_contador
es_i:
mov si,OFFSET LETRA_I
jmp incrementar_contador
es_j:
mov si,OFFSET LETRA_J
jmp incrementar_contador
es_k:
mov si,OFFSET LETRA_K
jmp incrementar_contador
es_l:
mov si,OFFSET LETRA_L
jmp incrementar_contador
es_m:
mov si,OFFSET LETRA_M
jmp incrementar_contador
es_n:
mov si,OFFSET LETRA_N
jmp incrementar_contador
es_o:
mov si,OFFSET LETRA_O
jmp incrementar_contador
es_p:
mov si,OFFSET LETRA_P
jmp incrementar_contador
es_q:
mov si,OFFSET LETRA_Q
jmp incrementar_contador
es_r:
mov si,OFFSET LETRA_R
jmp incrementar_contador
es_s:
mov si,OFFSET LETRA_S
jmp incrementar_contador
es_t:
mov si,OFFSET LETRA_T
jmp incrementar_contador
es_u:
mov si,OFFSET LETRA_U
jmp incrementar_contador
es_v:
mov si,OFFSET LETRA_V
jmp incrementar_contador
es_w:
mov si,OFFSET LETRA_W
jmp incrementar_contador
es_x:
mov si,OFFSET LETRA_X
jmp incrementar_contador
es_y:
mov si,OFFSET LETRA_Y
jmp incrementar_contador
es_z:
mov si,OFFSET LETRA_Z
jmp incrementar_contador

incrementar_contador:
mov al,cs:[si]
inc al
mov cs:[si],al

salir_incrementar_contador_igual:
pop si
pop ax

ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
error_controlado:

; Poner aqui la rutina de error
ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
decir:

xor dh,dh
mov dl,cs:[LETRA_B] ; Solo hay que cambiar la etiqueta
; para ver el resto de los contadores.

NUMERO 11,11

ret
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
TABLERO LABEL BYTE

DB 'ÚÄÄÄÄÄÄÄ¿'
DB '³ ³'
DB '³ ³'
DB '³ ³'
DB '³ ³'
DB '³ ³'
DB 'ÀÄÄÄÄÄÄÄÙ'

FINTABLERO LABEL BYTE
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
LETRAS LABEL BYTE
; En este ejemplo saldra 6 igualdades
DB "BBCDE" ; 1¦ "A" con 2¦ "A".
DB "FAGHA" ; 1¦ "A" con 3¦ "A".
DB "JBAAN" ; 1¦ "A" con 4¦ "A".
DB "OPARA" ; 2¦ "A" con 3¦ "A".
DB "TUBWX" ; 2¦ "A" con 4¦ "A".
; 3¦ "A" con 4¦ "A".
FIN_LETRAS LABEL BYTE
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
FRASE LABEL BYTE

DB ' PARA SALIR - ESCAPE '
DB 'EMAIL del Autor ..... : [email protected]'

FIN_FRASE LABEL BYTE
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
LETRA_A DB (0)
LETRA_B DB (0)
LETRA_C DB (0)
LETRA_D DB (0)
LETRA_E DB (0)
LETRA_F DB (0)
LETRA_G DB (0)
LETRA_H DB (0)
LETRA_I DB (0)
LETRA_J DB (0)
LETRA_K DB (0)
LETRA_L DB (0)
LETRA_M DB (0)
LETRA_N DB (0)
LETRA_O DB (0)
LETRA_P DB (0)
LETRA_Q DB (0)
LETRA_R DB (0)
LETRA_S DB (0)
LETRA_T DB (0)
LETRA_U DB (0)
LETRA_V DB (0)
LETRA_W DB (0)
LETRA_X DB (0)
LETRA_Y DB (0)
LETRA_Z DB (0)
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ;
MATRIZ ENDP
END MATRIZ

Espero que te sirva.

[email protected]
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:bucle y matriz

Publicado por oscar (3 intervenciones) el 01/05/2007 11:32:18
Puff
demasiado extenso

por lo que he visto compara todas las letras no?

A mi me es suficiente comparando que la posicion actual no este en blanco => ' '
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:bucle y matriz

Publicado por oscar (3 intervenciones) el 01/05/2007 11:32:31
Puff
demasiado extenso

por lo que he visto compara todas las letras no?

A mi me es suficiente comparando que la posicion actual no este en blanco => ' '

Gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar