Added unchecked assignment, untested codes, README & old git commit file.
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
"Welcome!!!"
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
;macros as per 64 bit conventions
|
||||
|
||||
%macro read 2
|
||||
mov rax,0 ;read
|
||||
mov rdi,0 ;stdin/keyboard
|
||||
mov rsi,%1 ;buf
|
||||
mov rdx,%2 ;buf_len
|
||||
syscall
|
||||
%endmacro
|
||||
|
||||
%macro print 2
|
||||
mov rax,1 ;print
|
||||
mov rdi,1 ;stdout/screen
|
||||
mov rsi,%1 ;msg
|
||||
mov rdx,%2 ;msg_len
|
||||
syscall
|
||||
%endmacro
|
||||
|
||||
%macro fopen 1
|
||||
mov rax,2 ;open
|
||||
mov rdi,%1 ;filename
|
||||
mov rsi,2 ;mode RW
|
||||
mov rdx,0777o ;File permissions
|
||||
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,1 ;write/print
|
||||
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 ;exit
|
||||
mov rdi,0
|
||||
syscall
|
||||
%endmacro
|
||||
@@ -0,0 +1,108 @@
|
||||
;NAME:- Chinmay M. Mule
|
||||
;CLASS:-SE COMP II SHIFT
|
||||
;ROLLNO:-34 PRN:-S18111044
|
||||
;Assignment no. :5
|
||||
;Assignment Name :X86/64 Assembly language program (ALP) to find
|
||||
; a) Number of Blank spaces
|
||||
; b) Number of lines
|
||||
; c) Occurrence of a particular character.
|
||||
;Accept the data from the text file. The text file has to be accessed during Program_1 execution.
|
||||
;Write FAR PROCEDURES in Program_2 for the rest of the processing.
|
||||
;Use of PUBLIC/GLOBAL and EXTERN directives is mandatory.
|
||||
;------------------------------------------------------------------------
|
||||
|
||||
extern far_proc ; [ FAR PROCRDURE
|
||||
; USING EXTERN DIRECTIVE ]
|
||||
|
||||
global filehandle, char, buf, abuf_len
|
||||
|
||||
%include "macro.asm"
|
||||
|
||||
;------------------------------------------------------------------------
|
||||
section .data
|
||||
nline db 10
|
||||
nline_len equ $-nline
|
||||
|
||||
ano db 10,10,10,10,"ML assignment 05 :- String Operation using Far Procedure"
|
||||
db 10,"---------------------------------------------------",10
|
||||
ano_len equ $-ano
|
||||
|
||||
filemsg db 10,"Enter filename for string operation : "
|
||||
filemsg_len equ $-filemsg
|
||||
|
||||
charmsg db 10,"Enter character to search : "
|
||||
charmsg_len equ $-charmsg
|
||||
|
||||
errmsg db 10,"ERROR in opening File...",10
|
||||
errmsg_len equ $-errmsg
|
||||
|
||||
exitmsg db 10,10,"Exit from program...",10,10
|
||||
exitmsg_len equ $-exitmsg
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
section .bss
|
||||
buf resb 4096
|
||||
buf_len equ $-buf ; buffer initial length
|
||||
|
||||
filename resb 50
|
||||
char resb 2
|
||||
|
||||
filehandle resq 1
|
||||
abuf_len resq 1 ; actual buffer length
|
||||
|
||||
;--------------------------------------------------------------------------
|
||||
section .text
|
||||
global _start
|
||||
|
||||
_start:
|
||||
print ano,ano_len ;assignment no.
|
||||
|
||||
print filemsg,filemsg_len
|
||||
read filename,50
|
||||
dec rax
|
||||
mov byte[filename + rax],0 ; blank char/null char
|
||||
|
||||
print charmsg,charmsg_len
|
||||
read char,2
|
||||
|
||||
fopen filename ; on succes returns handle
|
||||
cmp rax,-1H ; on failure returns -1
|
||||
jle Error
|
||||
mov [filehandle],rax
|
||||
|
||||
fread [filehandle],buf, buf_len
|
||||
mov [abuf_len],rax
|
||||
|
||||
call far_proc
|
||||
jmp Exit
|
||||
|
||||
Error: print errmsg, errmsg_len
|
||||
|
||||
Exit: print exitmsg,exitmsg_len
|
||||
exit
|
||||
;--------------------------------------------------------------------------------
|
||||
|
||||
; OUTPUT:-
|
||||
;chinmay@ubuntu:~Desktop/Assignment5$ nasm -f elf64 program1.asm
|
||||
;chinmay@ubuntu:~Desktop/Assignment5$ nasm -f elf64 program2.asm
|
||||
;chinmay@ubuntu:~Desktop/Assignment5$ ld -o FN program1.o program2.o
|
||||
;chinmay@ubuntu:~Desktop/Assignment5$ ./FN
|
||||
|
||||
|
||||
|
||||
|
||||
; ML assignment 05 :- String Operation using Far Procedure
|
||||
;---------------------------------------------------
|
||||
|
||||
;Enter filename for string operation : fle.txt
|
||||
|
||||
;Enter character to search : e
|
||||
|
||||
;No. of spaces are : 0000
|
||||
;No. of lines are : 0002
|
||||
;No. of character occurances are : 0002
|
||||
|
||||
;Exit from program...
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
;---------------------------------------------------------------------
|
||||
section .data
|
||||
nline db 10,10
|
||||
nline_len: equ $-nline
|
||||
|
||||
smsg db 10,"No. of spaces are : "
|
||||
smsg_len: equ $-smsg
|
||||
|
||||
nmsg db 10,"No. of lines are : "
|
||||
nmsg_len: equ $-nmsg
|
||||
|
||||
cmsg db 10,"No. of character occurances are : "
|
||||
cmsg_len: equ $-cmsg
|
||||
|
||||
;---------------------------------------------------------------------
|
||||
section .bss
|
||||
|
||||
scount resq 1
|
||||
ncount resq 1
|
||||
ccount resq 1
|
||||
|
||||
char_ans resb 16
|
||||
|
||||
;---------------------------------------------------------------------
|
||||
global far_proc
|
||||
|
||||
extern filehandle, char, buf, abuf_len
|
||||
|
||||
%include "macro.asm"
|
||||
;---------------------------------------------------------------------
|
||||
section .text
|
||||
global _main
|
||||
_main:
|
||||
|
||||
far_proc: ;FAR Procedure
|
||||
|
||||
xor rax,rax
|
||||
xor rbx,rbx
|
||||
xor rcx,rcx
|
||||
xor rsi,rsi
|
||||
|
||||
mov bl,[char]
|
||||
mov rsi,buf
|
||||
mov rcx,[abuf_len]
|
||||
|
||||
again: mov al,[rsi]
|
||||
|
||||
case_s: cmp al,20h ;space : 32 (20H)
|
||||
jne case_n
|
||||
inc qword[scount]
|
||||
jmp next
|
||||
|
||||
case_n: cmp al,0Ah ;newline : 10(0AH)
|
||||
jne case_c
|
||||
inc qword[ncount]
|
||||
jmp next
|
||||
|
||||
case_c: cmp al,bl ;character
|
||||
jne next
|
||||
inc qword[ccount]
|
||||
|
||||
next: inc rsi
|
||||
dec rcx ;
|
||||
jnz again ;loop again
|
||||
|
||||
print smsg,smsg_len
|
||||
mov rax,[scount]
|
||||
call display
|
||||
|
||||
print nmsg,nmsg_len
|
||||
mov rax,[ncount]
|
||||
call display
|
||||
|
||||
print cmsg,cmsg_len
|
||||
mov rax,[ccount]
|
||||
call display
|
||||
|
||||
fclose [filehandle]
|
||||
ret
|
||||
|
||||
;------------------------------------------------------------------
|
||||
display:
|
||||
mov rsi,char_ans+3 ; load last byte address of char_ans in rsi
|
||||
mov rcx,4 ; number of digits
|
||||
|
||||
cnt:mov rdx,0 ; make rdx=0 (as in div instruction rdx:rax/rbx)
|
||||
mov rbx,10 ; divisor=10 for decimal and 16 for hex
|
||||
div rbx
|
||||
; cmp dl, 09h ; check for remainder in RDX
|
||||
; jbe add30
|
||||
; add dl, 07h
|
||||
;add30:
|
||||
add dl,30h ; calculate ASCII code
|
||||
mov [rsi],dl ; store it in buffer
|
||||
dec rsi ; point to one byte back
|
||||
|
||||
dec rcx ; decrement count
|
||||
jnz cnt ; if not zero repeat
|
||||
|
||||
print char_ans,4 ; display result on screen
|
||||
ret
|
||||
;----------------------------------------------------------------
|
||||
|
||||
Binary file not shown.
@@ -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....
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
2
|
||||
7
|
||||
4
|
||||
6
|
||||
1
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
;Y=100-60 cos((pi/180)*x)
|
||||
;Bit 7 6 5 4 3 2 1 0
|
||||
;Data R R R G G G B B
|
||||
|
||||
.387
|
||||
.model small
|
||||
|
||||
.stack 100
|
||||
|
||||
.data
|
||||
msg db 10,13,'this is COS wave$'
|
||||
one_eighty dw 180
|
||||
scale dw 30
|
||||
hundred dw 100
|
||||
rint dw 0
|
||||
x dw 0
|
||||
|
||||
.code
|
||||
main:
|
||||
mov ax,@data ; Initialize DS (needed for .exe-program)
|
||||
mov ds, ax
|
||||
mov ax, 0A000h ; Segment to video memory
|
||||
mov es, ax
|
||||
|
||||
mov ax, 13h ;Standard video graphics mode
|
||||
int 10h ; switch to 320x200 mode
|
||||
|
||||
mov cx,0
|
||||
|
||||
l1:
|
||||
push cx ; store CX
|
||||
call get_cos
|
||||
|
||||
mov bx, cx
|
||||
call vector_to_memory
|
||||
mov di, ax
|
||||
mov al, 03h ; color
|
||||
mov [es:di], al ; put pixel
|
||||
pop cx ; restore CX
|
||||
inc cx ; CX = CX + 1
|
||||
cmp cx, 320 ; right boarder reached?
|
||||
jne l1 ; no, next degree
|
||||
|
||||
mov ah,09h ; display message
|
||||
lea dx,msg
|
||||
int 21h
|
||||
|
||||
xor ah, ah
|
||||
int 16h ; keyboard (wait for key)
|
||||
mov ax, 3
|
||||
int 10h ; go to text mode
|
||||
mov ax, 4C00h
|
||||
int 21h ; return to DOS, exit code 0
|
||||
|
||||
get_cos: ; Args: CX = angle (degree!)
|
||||
mov word[x],cx
|
||||
fldpi ; ST(0)=Pi, ST(1)=CX
|
||||
fimul word[x] ; ST(0)=Pi*CX
|
||||
|
||||
fidiv word[one_eighty] ; ST(0)=(Pi*CX)/180(degree to rad)
|
||||
fcos ; ST(0)=sine (rad)
|
||||
fimul word[scale] ; ST(0)=sine*scale
|
||||
fild hundred
|
||||
fsub st,st(1) ;ST(0)=100-60*SIN((Pi*CX)/180)
|
||||
fist word [rint] ; store integer with rounding
|
||||
mov ax, word[rint] ; AX = Y
|
||||
ret ; Return: AX = Y (signed!)
|
||||
|
||||
vector_to_memory: ; Calculate offset=Y*320+X
|
||||
;Args: BX = X, AX = Y
|
||||
push dx ; mul changes dx too
|
||||
mov cx, 320 ; video mode width
|
||||
mul cx ; DX:AX = AX * CX
|
||||
add ax, bx ; left indentation
|
||||
pop dx
|
||||
ret ; Return: AX = offset in memory
|
||||
|
||||
end main
|
||||
@@ -0,0 +1,87 @@
|
||||
;NAME:- Chinmay M. Mule
|
||||
;CLASS:-SE COMP II SHIFT
|
||||
;ROLLNO:-34 PRN:-S18111044
|
||||
;Assignment Name:-Write 80387 ALP to plot Sine Wave, Cosine Wave. Access
|
||||
; video memory directly for plotting.
|
||||
|
||||
|
||||
|
||||
.387
|
||||
.MODEL SMALL
|
||||
.DATA
|
||||
X DW 1
|
||||
Y DW 0
|
||||
Xrad DQ ?
|
||||
D60 DW 60
|
||||
D100 DW 100
|
||||
D180 DW 180
|
||||
PIby180 DQ ?
|
||||
TAB DB 80H,40H,20H,10H,8H,4,2,1
|
||||
OFS DW 0
|
||||
|
||||
.CODE
|
||||
START: MOV AX,@DATA
|
||||
MOV DS,AX
|
||||
|
||||
MOV AH,00 ;Set video mode
|
||||
MOV AL,06 ;Mode 6 i.e. 640 by 200 Graphics
|
||||
INT 10H
|
||||
|
||||
FINIT
|
||||
FLDPI
|
||||
FIDIV D180
|
||||
FSTP PIby180
|
||||
DRAWSINE:
|
||||
FILD X ;Load angle
|
||||
FLD PIby180 ;Convert to radian
|
||||
FMUL ;i.e. multiply by Pi/180
|
||||
FST Xrad
|
||||
FSIN ;Calculate sine
|
||||
FDIV Xrad
|
||||
FILD D60 ;Load amplitude
|
||||
FMUL ;Calculate Amplitude x sin
|
||||
FILD D100
|
||||
FSUBR
|
||||
FISTP Y
|
||||
|
||||
CALL OFSCAL
|
||||
INC X ;Next angle
|
||||
CMP X,639 ;Last point on X axis
|
||||
JNE DRAWSINE
|
||||
EXIT:
|
||||
MOV AH,0
|
||||
INT 16H
|
||||
|
||||
MOV AH,00 ;Set video mode
|
||||
MOV AL,02 ;Mode 2 i.e. 80 by 25 text
|
||||
INT 10H
|
||||
|
||||
MOV AH,4CH
|
||||
INT 21H
|
||||
|
||||
OFSCAL PROC NEAR
|
||||
MOV AX,Y
|
||||
AND AX,1
|
||||
JZ L1
|
||||
MOV OFS,2000H
|
||||
L1: MOV AX,Y
|
||||
SHR AX,1
|
||||
MOV BX,50H
|
||||
MUL BX
|
||||
ADD OFS,AX
|
||||
MOV AX,X
|
||||
MOV CL,3
|
||||
SHR AX,CL
|
||||
ADD OFS,AX
|
||||
LEA BX,TAB
|
||||
MOV AX,X
|
||||
AND AX,07
|
||||
XLAT
|
||||
MOV BX,OFS
|
||||
MOV DX,0B800H
|
||||
MOV ES,DX
|
||||
OR ES:[BX],AL
|
||||
MOV OFS,0
|
||||
RET
|
||||
OFSCAL ENDP
|
||||
END START
|
||||
Reference in New Issue
Block a user