Added unchecked assignment, untested codes, README & old git commit file.

This commit is contained in:
K
2024-06-10 11:35:19 +05:30
parent 757d1dc81c
commit b81b0e30c1
17 changed files with 1617 additions and 0 deletions
Binary file not shown.
+175
View File
@@ -0,0 +1,175 @@
;NAME:- Chinmay M. Mule
;CLASS:-SE COMP II SHIFT
;ROLLNO:-34 PRN:-S18111044
; Assignment Name:- Write X86 program to sort the list of integers in
; ascending order.
; Read the input from the text file and write the sorted
; data back to the same text file using bubble sort.
%include "macro.asm"
section .data
nline db 10
nline_len equ $-nline
ano db 10,10,10,10,"MPL assignment 07-Bubble sort using file operations"
db 10,"........................................",10
ano_len equ $-ano
filemsg db 10,"Enter filename of input data:"
filemsg_len equ $-filemsg
omsg db 10,"Sorting using bubble sort operation successful."
db 10,"Output stored in same file.....",10,10
omsg_len equ $-omsg
errmsg db 10,"ERROR in opening/reading/writing file..",10
errmsg_len equ $-errmsg
exitmsg db 10,10,"Exit from program....",10,10
exitmsg_len equ $-exitmsg
section .bss
buf resb 1024
buf_len equ $-buf ;buffer length
filename resb 50
filehandle resq 1
abuf_len resq 1 ;actual buffer length
array resb 10
n resq 1 ;passes
section .text
global _start
_start:
print ano,ano_len
print filemsg,filemsg_len
read filename,50
dec rax
mov byte[filename+rax],0 ; blank char/null char
fopen filename ;on success returns handle
cmp rax,-1H
je Error
mov[filehandle],rax
fread[filehandle],buf,buf_len
dec rax
mov [abuf_len],rax
call bsort
jmp Exit
Error:print errmsg,errmsg_len
Exit:print exitmsg,exitmsg_len
exit
;........................................................................
bsort: ;Bubble sort procedure
call buf_array
xor rax,rax
mov rbp,[n]
dec rbp
xor rcx,rcx
xor rdx,rdx
xor rsi,rsi
xor rdi,rdi
mov rcx,0 ;i=0
oloop:mov rbx,0 ;j=0
mov rsi,array ;a[j]
iloop:mov rdi,rsi ;a[j+1]
inc rdi
mov al,[rsi]
cmp al,[rdi]
jbe next
mov dl,0
mov dl,[rdi] ;swap
mov [rdi],al
mov [rsi],dl
next:inc rsi
inc rbx ; j++
cmp rbx,rbp
jb iloop
inc rcx
cmp rcx,rbp
jb oloop
fwrite [filehandle],omsg,omsg_len
fwrite [filehandle],array,[n]
fclose [filehandle]
print omsg,omsg_len
print array,[n]
ret
Error1:
print errmsg,errmsg_len
ret
;....................................................
buf_array:
xor rcx,rcx
xor rsi,rsi
xor rdi,rdi
mov rcx,[abuf_len]
mov rsi,buf
mov rdi,array
next_num:
mov al,[rsi]
mov [rdi],al
inc rsi ;number
inc rsi ;newline
inc rdi
inc byte[n] ; counter
dec rcx
dec rcx
jnz next_num
ret
; OUTPUT:-
;chinmay@ubuntu:~Desktop/MPL Programs/Assignment7$ nasm -f elf64 bsort.asm
;chinmay@ubuntu:~Desktop/MPL Programs/Assignment7$ ld -o b bsort.o
;chinmay@ubuntu:~Desktop/MPL Programs/Assignment7$ ./b
;MPL assignment 07-Bubble sort using file operations
;........................................
;Enter filename of input data:fl.txt
;Sorting using bubble sort operation successful.
;Output stored in same file.....
;12467
;Exit from program....
+6
View File
@@ -0,0 +1,6 @@
2
7
4
6
1
+57
View File
@@ -0,0 +1,57 @@
;macro.asm
%macro read 2
mov rax,0 ;read
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 ;open
mov rdi,%1 ;filename
mov rsi,2 ;mode RW
mov rdx,0777o ;File permissions(Read-4,Write-2,Execute-1)
syscall
%endmacro
%macro fread 3
mov rax,0 ;read
mov rdi,%1 ;filehandle
mov rsi,%2 ;buf
mov rdx,%3 ;buf_len
syscall
%endmacro
%macro fwrite 3
mov rax,0 ;write
mov rdi,%1 ;filehandle
mov rsi,%2 ;buf
mov rdx,%3 ;buf_len
syscall
%endmacro
%macro fclose 1
mov rax,3 ;close
mov rdi,%1;file handle
syscall
%endmacro
%macro exit 0
print nline,nline_len
mov rax,60
mov rdi,0
syscall
%endmacro