打印数组但突出显示特定值 {emu8086}

Printing an array but specific values highlighted {emu8086}

我想打印这个数组,同时突出显示该数组中的特定字符。这是我的代码:

include 'emu8086.inc'
.data
animales1   db 'BUBRPQYFODFZXIQ'
            db 'MSVDJVQDTLOEATF'
            db 'RCZPIFYGAZLPMFN'
            db 'LVWKFFBKDXHFIUW'
            db 'AOSEFQEMOOTGQUR'
            db 'ELLWTGNJJKAJISJ'
            db 'OVCOXLUEQTSDDSP'
            db 'UEAEMTNYOLVYMGI'
            db 'ORREPOMJZGYPHAI'
            db 'IFTLCBJFVOYHLUB'
            db 'WTOWZQFRAXQRLMR'
            db 'KGNYIIHHHKFUKIJ'
            db 'XMLSACGMVXEYSIT'
            db 'TSOESQVSEQRFNPU'
            db 'ODDQMDFWRGETDLY'

lenguajes2  db 'SLKFMBCULKVYUIM'
            db 'TWCDQFYIVIKUXKB'
            db 'GNIWEQBOSYEMDTJ'
            db 'WDHFZZPUIEDERYQ'
            db 'KMTGTKAKROMUSUV'
            db 'BELBLLTUVJQHCRW'
            db 'UPLUBYJKNUXORLF'
            db 'SGMAOOEENBOGIWR'
            db 'JVSTLPTEGPPNPJW'
            db 'YINCASSEMBLYTTU'
            db 'CHWTIOIWORDZDRV'
            db 'BRZCNRAVRWAMUNU'
            db 'KOMCOUKNGQEPQVS'
            db 'XXRXJUJUBEXVGGA'
            db 'MNKJQKZAACVCLDW'
            
char db 'a'
flag db 0
;Pez= 12,27,42
;Ave= 76,92,108 
            
indx db 5,11,26,41,45 dup (' ')
.stack
.code
.start up
mov ax,0000h  
mov bx,0000h
mov cx,0000h
mov dx,0000h
lea si, animales1
;call valueInArray
call printArrays




printArrays proc


mov bx,0000h
printArray:
mov dx,0000h
mov ah, 02h
mov dl,byte ptr[si+bx]
call valueinArray
cmp flag,1
jz printSpecial
int 21h
mov dl, 20h
int 21h
add bx, 1
add cl, 1
cmp cl,15
jz nextRow
jnz printArray


nextRow:
call nwLine
add ch,1
mov cl, 00h
cmp ch,15
jz finproc
jnz printArray

printSpecial:


lea di,char
mov byte ptr[di],dl
push ax
push bx
push cx
push dx

mov bp, offset char
mov dh,00h
mov al, 1
mov bh, 0
mov bl, 1111_0000b
mov cx, 1; calculate message size. 
mov dx,0000h
mov ah, 13h
int 10h
mov dl, 20h
mov ah, 02h
int 21h
pop dx
pop cx
pop bx
pop ax
add bx, 1
add cl, 1
cmp cl,15
jz nextRow
jnz printArray

finproc:

ret
printArrays endp

nwLine PROC
MOV AH,02h
MOV DX,0Ah; imprime asscii 10 (nueva linea)
INT 21h
MOV DX,0Dh; imprime asscii 13 (retorno de carro)
INT 21h
RET
nwLine ENDP

valueInArray proc

mov flag, 0
mov di,0001h
iterar:
mov dh, indx[di]
cmp dh,20h
jz finvalueproc
cmp bl,dh
jz found
add di,1
jmp iterar
found:
mov flag,1
jmp finvalueproc:



finvalueproc:
ret
valueInArray endp 

exit:
end

如您所见,数组 'indx' 具有我要突出显示的字符的位置(第一个数字是所述数组的有效长度),因此我检查 bx 是否位于说要打印的字符突出显示。 我现在有两个问题,第一个是突出显示的字符打印在一个有点随机的位置并且弄乱了其余部分,但我想我知道为什么打印的突出显示字符的位置是错误的,因为中断我使用 dh 和 dl 作为定位器,但我不知道如何制作它,所以它继续其余部分的流程。第二个问题是打印的字符是错误的,如果你 运行 它并检查变量 char,它有一个 'Z' 但它打印一个 'T'。我真的需要帮助。漂亮请。 :(

indx db 5,11,26,41,45 dup (' ')

可能这条线不是你想的那样!
看了你的解释,我想你的意思是:

indx db 5, 11, 26, 41, 45, ' '

数组的长度为 5,然后是突出显示字符的 4 个偏移量和作为列表终止符的 1 个 space 字符。


the first one is the highlighted characters are printing in a kinda random position and that messes up the rest, but I think I know why the position of the highlighted character that prints is wrong, because the interrupt that I use uses dh and dl as positioners but I do not know how to make it so it continues the flow of the rest.

因为您输出高亮字符的代码使用 mov dx,0000h,BIOS 函数 13h 将字符放在屏幕的左上角,而其他 'normal' 个字符将从那里继续。

你所要做的就是使用函数 03h:

询问 BIOS 此时光标在哪里

替换

mov cx, 1; calculate message size. 
mov dx,0000h
mov ah, 13h
int 10h

来自

 mov  ah, 03h   ; BIOS.GetCursorAndConfiguration
 int  10h       ; -> CX DX
 mov  cx, 1     ; message size
 mov  ah, 13h   ; BIOS.WriteString
 int  10h

函数 13h 从 ES:BP 获取。您是否设置了 ES 段寄存器?


The second problem is that the character that prints is wrong, if you run it and check the variable char, it has an 'Z' but it prints a 'T'.

可能解决第一个问题也会解决第二个问题。


有一种更好、更简单的方法来输出突出显示的字符。

printSpecial:
 push ax
 push bx
 push cx
 mov  cx, 1      ; ReplicationCount
 mov  bx, 00F0h  ; DisplayPage 0, Attribute BlackOnBrightWhite (11110000b)
 mov  al, dl     ; Character
 mov  ah, 09h    ; BIOS.WriteCharacterAndAttribute
 int  10h
 mov  ah, 0Eh    ; BIOS.TeletypeCharacter
 int  10h
 pop  cx
 pop  bx
 pop  ax
 ...

函数 09h 将用您需要的颜色写入您的字符,然后函数 0Eh 将正常移动光标。