MPL10
MPL10
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
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