Sorry, Frank! I'm very sorry....
I'm using linux! And I'm trying to simulate a simple grep instruction called FIND! It ask for the filename and the word to look for from the user and the program searches this word... The problem is that I don't exactly know where to put the code snippet that searches for the word... Our teacher only gives us a handouts sometime last week and we only studied it only for a short period of time which is not enough to be totally comprehended. He requires us to submit a project, simple grep, which is due next week. Given these constriants, we are arnt sure we cn cope w/ this. Heres the code we have made. This only diplays the particular portion of the file. This is just a test and if it proves to be successful we could proceed to of project proper. Could you give me a hint how to?
section .data
prompt1: db 'Filename: ',0
prompt1len: equ $-prompt1
prompt2: db 'Find: ',0
prompt2len: equ $-prompt2
section .bss
file resd 20 ;container for filename
look resb 20 ;container for the word to look for
size resb 1 ;container of the size the word to look for
words resb 1 ;container
buf resb 800 ;buffer
fd resd 1 ;file descriptor
section .text
global _start
_start:
;displays "Filename: "
mov eax,4 ;syscall # for write
mov ebx,1 ;file descriptor # for stdout
mov ecx,prompt1 ;the message
mov edx,prompt1len ;length of the message
int 80h
;capture input from keyboard
mov eax,3 ;syscall # for read
mov ebx,0 ;file descriptor # for stdin
mov ecx,file ;input buffer
mov edx,20 ;size of buffer
int 80h
;omit the newline character
sub eax,1
mov ebx,0
mov [file + eax],ebx
;displays "Find: "
mov eax,4
mov ebx,1
mov ecx,prompt2
mov edx,prompt2len
int 80h
;capture input from the keyboard
mov eax,3
mov ebx,0
mov ecx,look
mov edx,20
int 80h
mov [size],eax
;omit newline character
sub eax,1
mov ebx,0
mov [look + eax],ebx
;open
mov eax,5
mov ebx,file ;This has no bracket bec. this refers to the address of the
mov ecx,0 ;filename. When you put a brachet this will return the
mov edx,0 ;value of the filename at that address.
int 80h
mov [fd],eax
;read
mov eax,3
mov ebx,[fd]
mov ecx,buf
mov edx,800
int 80h
; THIS PART HERE DOWN IS THE PROB!
mov ecx,0
while:
mov [size],ecx
cmp ecx,5
je exit
mov ebx,[buf+ecx]
mov [words+ecx],ebx
add ecx,1
jmp while
; print the word
exit:
mov eax,4
mov ebx,1
mov ecx,words
mov edx,size
int 80h
;close the file
mov eax,6
mov ebx,[fd]
int 80h
;exit code
mov eax,1
mov ebx,0
int 80h
We know our limits and for the mean time, we accept that we lack exact understand of the system calls. Hope you could help us.
good day