Welcome to ARC Forums

Join our group of tech enthusiasts and Android developers

count character occurrence in of string in file nasm

Discussion in 'Programming' started by Rushi Chaudhari, Mar 16, 2017.

Tags:
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  1. Rushi Chaudhari

    Rushi Chaudhari HummingBird

    5
    3
    320
    Ratings:
    +3 / 0 / -0
    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
     
  2. Arjun Chandran

    Arjun Chandran Super Samurai
    Staff Member

    342
    130
    1,800
    Ratings:
    +130 / 0 / -0
  3. Rushi Chaudhari

    Rushi Chaudhari HummingBird

    5
    3
    320
    Ratings:
    +3 / 0 / -0
    I solved it , if anyone wants the code comment here ill post it
     
    • Like Like x 1

Share This Page