0% found this document useful (0 votes)
2 views4 pages

MPL10

The document contains assembly code for a file handling program that reads from 'abc.txt' and counts spaces, newline characters, and specific character occurrences. It includes two main assembly files, p1.asm for file operations and p2.asm for character counting. The program outputs the number of spaces, newline characters, and occurrences of a user-specified character after successfully opening the file.

Uploaded by

yojitwaghmare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

MPL10

The document contains assembly code for a file handling program that reads from 'abc.txt' and counts spaces, newline characters, and specific character occurrences. It includes two main assembly files, p1.asm for file operations and p2.asm for character counting. The program outputs the number of spaces, newline characters, and occurrences of a user-specified character after successfully opening the file.

Uploaded by

yojitwaghmare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

--------------FILE HANDLING PROGRAM IN ASSEMBLY--------------

abc.txt

hii hello
how are you
i am fine
where is my manjar
my mau

p1.asm

%macro scall 4
mov rax, %1
mov rdi, %2
mov rsi, %3
mov rdx, %4
syscall
%endmacro

Section .data
title: db 0x0A,"-----ASSIGNMENT NO 10-------", 0x0A
title_len: equ $-title
openmsg:db "File Opened Successfullly", 0x0A
openmsg_len: equ $-openmsg
errormsg: db"Failed to open File ", 0x0A
errormsg_len:equ $-errormsg

fname:db'abc.txt', 0

Section .bss
global cnt1, cnt2, cnt3, buffer, bufferlen, fdis
cnt1: resb 8
cnt2: resb 8
cnt3: resb 8
bufferlen: resb 8
buffer: resb 200
fdis: resb 8

Section .text
global _start
extern CSPACE, CNEWLINE, CCHAR
_start:
scall 1, 1, title, title_len
scall 2, fname, 2, 777

mov qword[fdis], rax


bt rax, 63
jc next
scall 1, 1,openmsg, openmsg_len
jmp next1
next:
scall 1, 1, errormsg, errormsg_len
jmp EXIT
next1:
scall 0, [fdis], buffer, 200
mov qword[bufferlen], rax
mov qword[cnt1], rax
mov qword[cnt2], rax
mov qword[cnt3], rax
call CCHAR
call CSPACE
call CNEWLINE
mov rax, 3
mov rdi, fname
syscall
EXIT:
mov rax, 60
mov rdi, 0
syscall

p2.asm

%macro scall 4
mov rax, %1
mov rdi, %2
mov rsi, %3
mov rdx, %4
syscall
%endmacro

Section .data
spacemsg:db 0x0A, "Spaces ="
spacemsg_len: equ $-spacemsg
newlinemsg:db 0x0A, "Retuirn (Enter) chars ="
newlinemsg_len: equ $-newlinemsg
chms:db 0x0A, "Character Count :"
chms_len:equ $-chms
chinput:db 0x0A, "Character Input :"
chinput_len:equ $-chinput
scnt: db 00H
ncnt: db 00H
chcnt: db 00H
hexcnt2: db 00H

Section .bss
extern cnt1, cnt2, cnt3, buffer, bufferlen
spacecount: resb 2
ch1: resb 2
newlinecount: resb 2
chcount: resb 2

Section .text
global _start2
global CSPACE,CNEWLINE,CCHAR
_start2:
mov rax,60
mov rdi,0
syscall

CSPACE:
mov rsi,buffer
up:
mov al,byte[rsi]
cmp al,20H
je next2
inc rsi
dec qword[cnt1]
jnz up
jmp next3

next2:
inc byte[scnt]
inc rsi
dec qword[cnt1]
jmp up

next3:
mov bl,byte[scnt]
mov rdi,spacecount
call HtoA

scall 1,1,spacemsg,spacemsg_len
scall 1,1,spacecount,2
ret

CNEWLINE:
mov rsi,buffer
up2:
mov al,byte[rsi]
cmp al,0x0A
je next4
inc rsi
dec qword[cnt2]
jnz up2
jmp next5

next4:
inc byte[ncnt]
inc rsi
dec qword[cnt2]
jnz up2

next5:
mov bl,byte[ncnt]
mov rdi,newlinecount
call HtoA

scall 1,1,newlinemsg,newlinemsg_len
scall 1,1,newlinecount,2

CCHAR:
scall 1,1,chinput,chinput_len
scall 0, 0, ch1, 2
mov rsi, buffer
up3:
mov al, byte[rsi]
cmp al, byte[ch1]
je nextl
inc rsi
dec qword[cnt3]
jnz up3
jmp next7

nextl:
inc byte[chcnt]
inc rsi
dec qword[cnt3]
jnz up3

next7:
mov bl, byte[chcnt]
mov rdi, chcount
call HtoA
scall 1, 1, chcount, 2
ret

HtoA:
mov byte[hexcnt2], 02H
aup1:

rol bl, 04
mov cl, bl
and cl, 0FH
CMP CL, 09H
jbe ANEXT1
ADD cl, 07H

ANEXT1:
add cl, 30H
mov byte[rdi], cl
INC rdi
dec byte[hexcnt2]
JNZ aup1
ret

OUTPUT :-
[student@localhost ~]$ nasm -f elf64 p1.asm
[student@localhost ~]$ nasm -f elf64 p2.asm
[student@localhost ~]$ ld -o prog p1.o p2.o
[student@localhost ~]$ ./prog

-----ASSIGNMENT NO 10-------
File Opened Successfullly

Character Input :m
05
Spaces =09
Return (Enter) chars =05

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy