0

Here is a new update on what i'm doing currently. I'm confused on how to use the data i stored in S2 to search the same word in the whole screen. If found highlight the word.

DOSBOX - compiler : A86

org 100h
;-----------------------------------------------------
lea bp, S1    
mov cx, 35 
mov al, 1   
mov ah, 13h 
mov bh, 0 
mov dl, 0
mov dh, 25
mov bl, 7
int 10h   
;----------------------------------------------------------            ; Asks input'
mov di,1
start:
mov ah, 0
int 16h
mov dx,ax
mov ah, 0eh
cmp dx,4d00h 
je start2
int 10h
mov S2[di], al
inc di
jmp start 

start2 :
mov cx,di
mov di,1
mov si,0

relop :
mov ah,[si]
cmp ah,S2[di]

mov al, 13h
    mov ah, 0
    int 10h     ; set graphics video mode. 
    mov al, 1100b
    mov cx, 10
    mov dx, 20
    mov ah, 0ch
    int 10h     ; set pixel. 

inc di
add si,2
je  relop 

mov ah, 13h 
lea bp, S2
mov al, 1
mov bh, 0
mov bl, 7
mov dl, 0
mov dh, 25
int 10h 



MOV AH, 4CH
INT 21H







S1 DB "EENTER THE WORD TO FIND ON SCREEN : "  
S2 db 1 dup (?) 







; ========= data ===============

I can't use int 21h for input and output but only to end the program ( return )

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
will
  • 1
  • 1
  • 3
  • 1
    It's not clear your question. Which Assembler are you using? Why don't you move directly the S2 contents to video memory if you don't want to utilize INT 21? – David BS Aug 10 '16 at 14:18
  • i can't use video memory because i need to use the string i saved to search for something. like, how do i print what i saved in S2 back on the screen but it should be in the middle of ' ERROR -> ' and ' COULD NOT BE FOUND ' – will Aug 10 '16 at 14:22
  • How is your code supposed to work? There are no comments to indicate what you think should happen. – Peter Cordes Aug 10 '16 at 14:30
  • 2
    You may divide the ERROR message in two parts S2 (ERROR ->) and S3 (COULD NOT BE FOUND. Create a S4 to contain the data you dodn't find. So, you will print (or show) S2 + S4 + S3. There is no way to change the contents of S2 without transpassing its original size and contents. – David BS Aug 10 '16 at 14:31
  • Well, you can change the contents of S2, but only by overwriting the single ? byte. Storing to that byte doesn't move the later bytes. I think David's right, you're trying to put a string into a single byte in S2 or something. – Peter Cordes Aug 10 '16 at 14:33
  • 1
    I thought that (?) means an array of values depending on how much your DI increments ? David has a point. I'll test that out. will update as soon as possible. Thanks – will Aug 10 '16 at 14:36
  • I still don't get that reason why you can't use video memory directly. You can build the correct string directly in video memory (copying the beginning part, then search string, then end part). Also I don't see why you can't use `int 21h`, yet you use it to exit the program (not that you need it, writing directly to VRAM or using slow `int 10h` should be enough). – Ped7g Aug 10 '16 at 15:43
  • 1
    The `?` in `DB` is single byte, uninitialized. As you put it inside other initialized bytes, it will land into initialized executable section inside executable, so it will very likely contain zero. Assemblers usually have some way how to do "many ?", for example in TASM `DB 33 DUP (?)` means allocating 33 uninitialized bytes. Either you would need to specify fixed-size space in that error string, like "error -> [...fixed 20 bytes...] not found", then overwrite only those 20 bytes (by truncated/padded string), or you can split it. Or create C-like `sprintf` (most complex and powerful solution). – Ped7g Aug 10 '16 at 15:55
  • Updated with new current code. still confused on how to approach this – will Aug 11 '16 at 15:12

1 Answers1

1
mov dl, 0
mov dh, 25

You're printing the prompt beyond the screen! Coords are zero-based and for the row they range from 0 to 24 on the standard text screen.


 mov si,0
relop :
 mov ah,[si]
 cmp ah,S2[di]
 mov al, 13h
 mov ah, 0
 int 10h     ; set graphics video mode. 

If you want to read from the screen then you definitely should not be setting up a new screen on each iteration of this retrievel loop! Furthermore initializing the SI register to 0 won't get to the first character of the inputted word.

Solution:

Display your 35 character long prompt at the first row of the screen (mov dh,0). Now you know the inputted word will be at video memory offset address 70, but in the video memory segment.

 mov ax,0B800h
 mov es,ax
 mov si,70
relop :
 es mov ah,[si]  <-- This is the ASCII code of the 1st inputted character

Best also make these corrections:

S1 DB "ENTER THE WORD TO FIND ON SCREEN : "  
S2 db 44 dup (?)
Fifoernik
  • 9,779
  • 1
  • 21
  • 27