Welcome to our Community
Wanting to join the rest of our members? Feel free to sign up today.
Sign up

count character occurrence in of string in file nasm

Feb 22, 2017
48
1
1,860
It should print the first character given in file specified by user.Actually i was writing code to count how many times a particular letter repeats in the string found in file.But the code is not complete.
the print r8,1 is printing blank answer


Code:
section .data
 msg1 db "File Handling Menu",10
      db "1.Find Character Occourence",10
      db "2.Find Blank Spaces",10
        
  msg1_len equ $-msg1
 
 msg2 db "Enter The Name Of The File" ,10       
 msg2_len equ $-msg2
 
 errmsg db "File Not Found"
 errmsg_len equ $-errmsg
 
 
 section .bss

char resb 1
filename resb 100
choice resb 2
filehandle resq    1
buf resb 4096
buf_len equ $-buf
abuf_len resq 2

%macro read 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro fopen 1
Mov  rax,2
Mov  rdi, %1
Mov  rsi, 2
mov  rdx, 777o
syscall
%endmacro
        
%macro fread 3
Mov  rax,0
Mov  rdi, %1
Mov  rsi, %2
mov  rdx, %3
syscall
%endmacro

section .code
global _start
_start:

print msg2,msg2_len
read filename,100
dec rax
mov byte[filename+rax],0
fopen filename
mov [filehandle],rax
cmp rax,-1H

jle error


fread [filehandle],buf,buf_len
print buf,buf_len

print msg1,msg1_len
read choice,2
cmp byte[choice],31h
je procedure1

jmp exit

error:
print errmsg,errmsg_len         
exit:mov rax,60
     mov rbx,60
     syscall
procedure1:
mov rsi,buf
mov r8,[rsi]
print r8,1
gdx:
print msg2,msg2_len
  jmp exit