MIT Programmes....
-----------------------------------------------
Program 1:
-----------------------------------------------
;==============================================================================================================
;TITLE : Write X86/64 Assembly language program (ALP) to add array of N hexadecimal numbers stored in the
; memory. Accept input from the user.
;ASSIGNMENT NO. : 01
;GROUP : A
;ROLL NO. : 007
;BATCH : S1
;===============================================================================================================
section .data
msg1 db 10,13,'ACCEPT "N" HEXADECIMAL NUMBERS AND ADD THEM',10
msg1len equ $-msg1
msg2 db 10,13,'Enter how many numbers you want to enter : ',10
msg2len equ $-msg2
msg3 db 10,13,'Enter 64-bit hexadecimal numbers : ',10
msg3len equ $-msg3
msg4 db 10,13,'Addition of given numbers is : ',10
msg4len equ $-msg4
section .bss
nascii resb 3
nasciilen equ $-nascii
count resb 1
dispnum resb 16
resultl resq 1
resulth resq 1
buffer resb 17
bufferlen equ $-buffer
%macro display 2
mov rax,4
mov rbx,1
mov rcx,%1
mov rdx,%2
int 80h
%endmacro
%macro accept 2
mov rax,3
mov rbx,0
mov rcx,%1
mov rdx,%2
int 80h
%endmacro
section .text
global _start
_start:
display msg1,msg1len
display msg2,msg2len
accept nascii,nasciilen
call accept8
mov [count],bl
mov rdi,[count]
nextnum: display msg3,msg3len
accept buffer,bufferlen
call accept64
add [resultl],rbx
jnc next
inc word[resulth]
next:
dec rdi
jnz nextnum
display msg4,msg4len
mov rax,[resulth]
call display64
mov rax,[resultl]
call display64
mov rax,1
mov rbx,0
int 80h
accept8:
mov bl,00
mov rcx,02
mov rsi,nascii
l1:
shl bl,4
mov al,[rsi]
cmp al,39h
jbe sub30
sub al,07h
sub30:
sub al,30h
add bl,al
inc rsi
loop l1
ret
accept64:
mov rbx,00
mov ecx,16
mov esi,buffer
mov rax,00
L3:
shl rbx,4
mov al,[esi]
cmp al,39h
jbe skip2
sub al,07h
skip2:
sub al,30h
add rbx,rax
inc esi
loop L3
ret
display64:
mov rsi,dispnum+15 ; load last byte address of char_ans in rsi
mov rcx,16 ; number of digits
cnt:
mov rdx,0 ; make rdx=0 (as in div instruction rdx:rax/rbx)
mov rbx,16 ; divisor=16 for hex
div rbx ;rax/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
display dispnum,16 ; display result on screen
ret
;============================================================
; OUTPUT
;============================================================
aman@aman-230:~/Desktop/SE73$ ./ASSGN1_64
ACCEPT "N" HEXADECIMAL NUMBERS AND ADD THEM
Enter how many numbers you want to enter :
02
Enter 64-bit hexadecimal numbers :
1111111111111111
Enter 64-bit hexadecimal numbers :
1111111111111111
Addition of given numbers is :
00000000000000002222222222222222
aman@aman-230:~/Desktop/SE73$
-----------------------------------------------
Program 2:
-----------------------------------------------
;==============================================================================================================
;TITLE : Write X86/64 ALP to perform non-overlapped and overlapped
; block transfer (with and without string specific instructions). Block
; containing data can be defined in the data segment.
;ASSIGNMENT NO. : 02
;GROUP : A
;ROLL NO. : 007
;BATCH : S1
;===============================================================================================================
section .data
msg1 db 10,10,13,13,' *** PROGRAM TO PERFORM OVERLAPES/NON-OVERLAPPED TRANSFER *** ',10,10
db 10,10,13,'===== MENU ===='
db 10,10,10,'1] Overlapped block transfer without string'
db 10,'2] Overlapped block transfer with string'
db 10,'3] Non-overlapped block transfer without string'
db 10,'4] Non-overlapped block transfer with string'
db 10,'5] Exit'
db 10,10,13,'Enter your choice : '
msg1len equ $-msg1
msg2 db 10,13,' Enter number of blocks of data : ',10
msg2len equ $-msg1
msg3 db 10,13,' Enter elements in array : ',10
msg3len equ $-msg2
section .bss
choice resb 3
choicelen equ $-choice
count resb 1
data resb 40
datalen equ $-data
n resb 3
nlen equ $-count
buffer resb 17
bufferlen equ $-buffer
%macro Display 2
mov rax,4
mov rbx,1
mov rcx,%1
mov rdx,%2
int 80h
%endmacro
%macro Accept 2
mov rax,3
mov rbx,0
mov rcx,%1
mov rdx,%2
int 80h
%endmacro
section .text
global _start
_start:
display msg1,msg1len
cmp dl,'1'
jbe l1
cmp dl,'2'
jbe l2
cmp dl,'3'
jbe l3
cmp dl,'4'
jbe l4
cmp dl,'5'
jbe l5
Accept n,n_len
call AcceptChoice
L1 :
Display msg1,msg1len
Accept n,n_len
call AcceptCnt
mov [count],bl
mov rdi,[count]
Display msg2,msg2len
Accept buffer,buffer_len
mov rax,buffer
mov rsi,rax
inc rsi
dec rdi
jz L1
L2 :
Display msg1,msg1len
Accept n,n_len
call AcceptCnt
mov [count],bl
mov rdi,[count]
L3 :
Display msg1,msg1len
Accept n,n_len
call AcceptCnt
mov [count],bl
mov rdi,[count]
L4 :
Display msg1,msg1len
Accept n,n_len
call AcceptCnt
mov [count],bl
mov rdi,[count]
L5 :
Display msg1,msg1len
Accept n,n_len
call AcceptCnt
mov [count],bl
mov rdi,[count]
AcceptChoice :
mov bl,00
mov rcx,n
mov rsi,n
ret
AcceptCnt:
mov bl,00
mov rcx,02
mov rsi,n
ret
ret
-----------------------------------------------
Program 3:
-----------------------------------------------
;==============================================================================================================
;TITLE : Write 64 bit ALP to convert 4-digit Hex number into its equivalen BCD number and 5-digit BCD
; number into its equivalent HEX number. Make your program user friendly to accept the choice
; from user for:
; (a) HEX to BCD b) BCD to HEX (c) EXIT.
; Display proper strings to prompt the user while accepting the input and displaying the result.
; (use of 64-bit registers is expected)
;ASSIGNMENT NO. : 03
;GROUP : A
;ROLL NO. : 007
;BATCH : S1
;===============================================================================================================
;=========================================
; PROGRAM
;=========================================
section .data
menu db "=============================",10
db " MENU ",10
db "=============================",10
db " 1]. HEX to BCD conversion",10
db " 2]. BCD to HEX conversion",10
db " 3]. Exit",10
db "Enter your choice",10
menu_len:equ $-menu
hbmsg db 10,"Hex to BCD "
db 10,"Enter 4-digit Hex number: "
hbmsg_len: equ $-hbmsg
bhmsg db 10, "BCD to Hex "
db 10,"enter 5-digit BCD number: "
bhmsg_len: equ $-bhmsg
hmsg db 10,13,"Equivalent Hex number is: "
hmsg_len: equ $-hmsg
bmsg db 10,13,"Equivalent BCD number is: "
bmsg_len: equ $-bmsg
;=============================================================================================================
section .bss
buf resb 6
buf_len: equ $-buf
digitcount resb 1
ans resw 1
char_ans resb 4
%macro dispmsg 2 ;macro for display
mov rax,4 ;load system call for display
mov rbx,1 ;load standard output file descriptor
mov rcx,%1 ;load address of buffer
mov rdx,%2 ;load length of buffer
int 80h ;call to kernel
%endmacro
%macro accept 2 ;macro for accepting
mov rax,3 ;load system call for accept
mov rbx,1 ;load standard input file descriptor
mov rcx,%1 ;load address of buffer
mov rdx,%2 ;load length of buffer
int 80h
%endmacro
;===============================================================================================================
section .text
global _start
_start:
menum:
dispmsg menu, menu_len
accept buf,buf_len
mov al,[buf]
;****************************************
case1: cmp byte[buf],'1' ;comparison of choice
jne case2
call hex_bcd
case2: cmp byte[buf],'2' ;comparison of choice
jne case3
call bcd_hex
case3: cmp byte[buf],'3' ;comparison of choice
je ext
jmp menum
ext: ;exit
mov rax,1
mov rbx,0
int 80h
;*****************************************
hex_bcd:
dispmsg hbmsg, hbmsg_len
call accept_16
mov ax,bx
mov rbx,10
back:
xor rdx,rdx
div rbx
push dx
inc byte[digitcount]
cmp rax,0h
jne back
dispmsg bmsg, bmsg_len
print_bcd:
pop dx
add dl,30h
mov [char_ans],dl
dispmsg char_ans,1
dec byte[digitcount]
jnz print_bcd
ret
accept_16:
accept buf,5
xor bx,bx
mov rcx,4
mov rsi,buf
next_digit:
shl bx,04
mov al,[rsi]
cmp al,39h
jbe sub30
sub al,7h
sub30: sub al,30h
add bx,ax
inc rsi
loop next_digit
ret
;********************************************
bcd_hex:
dispmsg bhmsg, bhmsg_len
accept buf,buf_len
mov rsi,buf
xor rax,rax
mov rbx,10
mov rcx,05
back1: xor rdx,rdx
mul ebx
xor rdx,rdx
mov dl,[rsi]
sub dl,30h
add rax,rdx
inc rsi
dec rcx
jnz back1
mov [ans],ax
dispmsg hmsg, hmsg_len
mov ax,[ans]
call display_16
ret
display_16:
mov rsi,char_ans+3
mov rcx,4
cnt: mov rdx,0
mov rbx,16
div rbx
cmp dl, 09h
jbe add30
add dl, 07h
add30:
add dl,30h
mov [rsi],dl
dec rsi
dec rcx
jnz cnt
dispmsg char_ans,4
ret
;========================================================================================================================
OUTPUT
;========================================================================================================================
aman@aman-230:~/SE73/assgnmntA-03$ nasm -f elf64 assgn3.asm -o assgn3.o
aman@aman-230:~/SE73/assgnmntA-03$ ld -o assgn3 assgn3.o
aman@aman-230:~/SE73/assgnmntA-03$ ./assgn3
=============================
MENU
=============================
1]. HEX to BCD conversion
2]. BCD to HEX conversion
3]. Exit
Enter your choice
1
Hex to BCD
Enter 4-digit Hex number: 5F67
Equivalent BCD number is: 24423
=============================
MENU
=============================
1]. HEX to BCD conversion
2]. BCD to HEX conversion
3]. Exit
Enter your choice
2
BCD to Hex
enter 5-digit BCD number: 24423
Equivalent Hex number is: 5F67
=============================
MENU
=============================
1]. HEX to BCD conversion
2]. BCD to HEX conversion
3]. Exit
Enter your choice
3
aman@aman-230:~/SE73/assgnmntA-03$
-----------------------------------------------
Program 4:
-----------------------------------------------
;==============================================================================================================
;TITLE : Write X86/64 ALP for the following operations on the string entered by the user.(use of 64-bit
; registers is expected)
; a) Calculate Length of the string
; b) Reverse the string
; c) Check whether the string is palindrome
; OR
; Make your program user friendly by providing MENU like:
; (a) Enter the string b) Calculate length of string c) Reverse string d) Check
; palindrome e) Exit
; Display appropriate messages to prompt the user while accepting the input and
; displaying the result.
;ASSIGNMENT NO. : 04
;GROUP : A
;ROLL NO. :
;BATCH : S1
;===============================================================================================================
;=========================================
; PROGRAM
;=========================================
section .data
menu db 10,"---------------------"
db 10," MENU ";
db 10,"---------------------",10
db 10,"1]. Enter the string"
db 10,"2]. Find Length of the string"
db 10,"3]. Find Reverse of the string"
db 10,"4]. Check string for Palindrome"
db 10,"5]. Exit"
db 10,10," Enter your choice : "
menu_len: equ $-menu
strr db 10,10,"Enter the string : "
strr_len equ $-strr
strl db 10,10,"Length of the string is",10
strl_len equ $-strl
revs db 10,10,"Reverse of the string is:",10
rev_len equ $-revs
pal db 10,10,"Entered string is a palindrome",10,10
pal_len equ $-pal
npal db 10,"Entered string is not a palindrome",10,10
npal_len equ $-npal
;---------------------------------------------------------------------------
section .bss
length resb 2
revbuf resb 20
revbuflen equ $-revbuf
str1 resb 20
str1_len equ $-str1
choice resb 2
choice_len:equ $-choice
displen resb 2
%macro dispmsg 2 ;macro for display
mov rax,4 ;load system call for display
mov rbx,1 ;load standard output file descriptor
mov rcx,%1 ;load address of buffer
mov rdx,%2 ;load length of buffer
int 80h ;call to kernel
%endmacro
%macro accept 2 ;macro for accepting
mov rax,3 ;load system call for accept
mov rbx,0 ;load standard input file descriptor
mov rcx,%1 ;load address of buffer
mov rdx,%2 ;load length of buffer
int 80h
%endmacro
;------------------------------------------------------------------------
section .text
global _start:
_start:
MENU:
dispmsg menu,menu_len
accept choice,choice_len
case1: cmp byte[choice],'1' ;comparison of choice
jne case2
dispmsg strr,strr_len
accept str1,str1_len
dec ax
mov [length],ax
case2: cmp byte[choice],'2' ;comparison of choice
jne case3
dispmsg strl,strl_len
mov ax,[length]
call hextoascii
case3: cmp byte[choice],'3' ;comparison of choice
jne case4
mov rsi,str1
xor rcx,rcx ;Initialise rcx to '0'
mov rcx,[length]
add rsi,rcx
dec rsi
mov rdi,revbuf
mov rbp,rcx
l1:
mov al,[rsi]
mov [rdi],al
dec rsi
inc rdi
dec rbp
jnz l1
dispmsg revs,rev_len
dispmsg revbuf,revbuflen
case4: cmp byte[choice],'4' ;comparison of choice
jne case5
xor rcx,rcx ;Initialise rcx to '0'
mov rsi,str1
mov rdi,revbuf
mov rcx,20
shr rcx,1
P: mov al,[rsi]
cmp al,[rdi]
jne NP
dec rcx
jnz P
dispmsg pal,pal_len
jmp MENU
NP:
dispmsg npal,npal_len
jmp MENU
case5: cmp byte[choice],'5'
je ext
jmp MENU
ext: ;exit
mov rax,1
mov rbx,0
int 80h
hextoascii:
mov rcx,2
mov rsi,displen+1
l3: mov rdx,00
mov bx,10
div bx
cmp dl,09h
jbe add30
add dl,07h
add30:
add dl,30h
mov [rsi],dl
dec rsi
dec rcx
jnz l3
dispmsg displen,2
ret
;======================================================
OUTPUT
;======================================================
aman@aman-230:~/Desktop/SE61/Assgnmt04$ nasm -f elf64 assg4.asm -o assg4.o
aman@aman-230:~/Desktop/SE61/Assgnmt04$ ld -o assg4 assg4.o
aman@aman-230:~/Desktop/SE61/Assgnmt04$ ./assg4
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 1
Enter the string : madam
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 2
Length of the string is
05
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 3
Reverse of the string is:
madam
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 4
Entered string is a palindrome
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 5
aman@aman-230:~/Desktop/SE61/Assgnmt04$ ./assg4
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 1
Enter the string : adarsh
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 2
Length of the string is
06
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 3
Reverse of the string is:
hsrada
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 4
Entered string is not a palindrome
---------------------
MENU
---------------------
1]. Enter the string
2]. Find Length of the string
3]. Find Reverse of the string
4]. Check string for Palindrome
5]. Exit
Enter your choice : 5
aman@aman-230:~/Desktop/SE61/Assgnmt04$
-----------------------------------------------
Program 5:
-----------------------------------------------
;================================================================================================================
Assignment No.o6
Ttle:Write X86/64 ALP to perform multiplication of two 8-bit hexadecimal numbers. Use
successive addition and add and shift method. Accept input from the user. (use of 64-bit registers is expected).
Roll No.:
Batch:s1
;================================================================================================================
section .data
;================================================================================================================
menumsg db 10,10, '--------------MENU---------------'
db 10, '1.MULTIPLICATION USING SUCCESSIVE ADDITION'
db 10, '2.MULTIPLICATION USING SHIFT AND ADD'
db 10, '3.EXIT'
db 10,'Enter Your Choice??'
menumsglen equ $-menumsg
msg1 db 'ENTER THE 1ST 8 BIT HEX NOS?? ',10
msg1len equ $-msg1
msg2 db 10,'ENTER THE 2ND 8 BIT HEX NOS??',10
msg2len equ $-msg2
msg3 db 10,'THE MULTIPLICATION IS',10
msg3len equ $-msg3
;================================================================================================================
section .bss
;================================================================================================================
res resb 4
multi1 resb 1
multi1_len: equ $-multi1
multi2 resb 1
multi2_len: equ $-multi2
asc1 resb 3
asc1_len: equ $-asc1
asc2 resb 3
asc2_len: equ $-asc2
dispnum resb 4
dispnum_len: equ $-dispnum
cho resb 2
chlen equ $-cho
resl resb 1
resh resb 1
%macro accept 2 ;macro for read
mov rax,3 ;system call for read
mov rbx,1
mov rcx,%1
mov rdx,%2 ;format for collecting arguments(as buffer_name & buffer_size)
int 80h
%endmacro
%macro disp 2 ;macro for display
mov rax,4 ;system call for display
mov rbx,1
mov rcx,%1 ;format for collecting arguments(as buffer_name & buffer_size)
mov rdx,%2
int 80h
%endmacro
;================================================================================================================
section .text
;================================================================================================================
global _start
_start:
mn:disp menumsg,menumsglen
accept cho,chlen
case1:
cmp byte[cho],'1' ;compare choice
jne case2
disp msg1,msg1len ;display msg1
accept asc1,asc1_len
mov rsi,asc1 ;mov ascii to rsi
call accept8
mov [multi1],bl ;mov content of bl to multi1
disp msg2,msg2len ;display msg1
accept asc2,asc2_len
mov rsi,asc2 ;move ascii to rsi
call accept8 ;call to accept8
mov [multi2],bl ;point bl to 2nd no
xor eax,eax ;clear reg
xor ecx,ecx ;clear reg
mov al,[multi1] ;mov 1st no to al
mov bl,[multi2] ;mov 2nd no to al
mov dx,00 ;clear reg
next:
add ecx,eax ;add eax to ecx reg
dec bl ;decreament bl reg
jnz next ;jump if not zero back to next
mov [res],ecx
disp msg3,msg3len ;display msg3
mov eax,[res] ;mov ecx to eax reg
call display16 ;call to display16
;-------------------------------------------------
case2:
cmp byte[cho],'2' ;compare choice
jne case3
disp msg1,msg1len ;display msg1
accept asc1,asc1_len
mov rsi,asc1 ;mov ascii to rsi
call accept8
mov [multi1],bl ;mov content of bl to multi1
disp msg2,msg2len ;display msg1
accept asc2,asc2_len
mov rsi,asc2 ;move ascii to rsi
call accept8 ;call to accept8
mov [multi2],bl ;point bl to 2nd no
mov al,[multi1] ;mov content of multi1 to al reg
mov cl,00 ;clear cl reg
mov edx,0 ;clear edx reg
mov edx,08h ;mov 08h to edx
L1: rcr al,01 ;raotate al reg. with 01 carry to right
jnc L2
mov bh,00h ;clear bh reg.
shl bx,cl ;shift left cl to bx
add [resl],bx ;add bx to resl
mov bl,[multi2] ;mov 2nd number into bl
L2:
inc cl ;increament cl
dec edx ;decreament edx
jnz L1 ;jump if not zero back to l1
disp msg3,msg3len ;display msg3
mov ax,[resl] ;mov content of resl to ax
call display16 ;call to display16
;----------------------------------------------
case3: cmp byte[cho],'3'
je ext
jmp mn
exit:
mov rax,1 ;mov 01 to rax
mov rbx,0 ;mov 0 to rbx
int 80h ;call int 80h
;------------------------------------------------
accept8: ;accept procedure
xor rbx,rbx ;clear rbx reg.
mov rcx,02 ;mov 02 into rcx reg.
L12:
shl bx,4 ;shift left bx with 4bit
mov al,[rsi] ;mov content of rsi to al
cmp al,39h ;compare al with 39
jbe sub30
sub al,7h ;substract al by 7
sub30:
sub al,30h ;subtract al with 30
add bl,al ;add al to bl reg.
inc rsi ;increament rsi reg.
loop L12
;--------------------------------------------------
display16:
mov rsi,dispnum+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,16 ; divisor=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
disp dispnum,4 ; display result on screen
ret
;------------------------------------------------------------
OUTPUT
;-------------------------------------------------------------
aman@aman-230:~/Desktop/se04$ nasm -f elf64 as6.asm
aman@aman-230:~/Desktop/se04$ ld -o as6 as6.o
aman@aman-230:~/Desktop/se04$ ./as6
--------------MENU---------------
1.MULTIPLICATION USING SUCCESSIVE ADDITION
2.MULTIPLICATION USING SHIFT AND ADD
3.EXIT
Enter Your Choice??1
ENTER THE 1ST 8 BIT HEX NOS??
10
ENTER THE 2ND 8 BIT HEX NOS??
10
THE MULTIPLICATION IS
0100
--------------MENU---------------
1.MULTIPLICATION USING SUCCESSIVE ADDITION
2.MULTIPLICATION USING SHIFT AND ADD
3.EXIT
Enter Your Choice??2
ENTER THE 1ST 8 BIT HEX NOS??
12
ENTER THE 2ND 8 BIT HEX NOS??
12
THE MULTIPLICATION IS
0144
--------------MENU---------------
1.MULTIPLICATION USING SUCCESSIVE ADDITION
2.MULTIPLICATION USING SHIFT AND ADD
3.EXIT
Enter Your Choice??3
aman@aman-230:~/Desktop/se04$
-----------------------------------------------
Program 6:
-----------------------------------------------
/***************************************************************************************************************
TITLE : Write 8087ALP to obtain:
i) Mean ii) Variance iii) Standard Deviation
For a given set of data elements defined in data segment. Also display result.
ASSIGNMENT NO. : 07
GROUP : B
ROLL NO. :
BATCH : S
*****************************************************************************************************************/
section .data
welmsg db 10,"***WELCOME TO 64 BIT PROGRAMMING***"
welmsg_len equ $-welmsg
meanmsg db 10,"CALCULATED MEAN IS:-"
meanmsg_len equ $-meanmsg
sdmsg db 10,"CALCULATED STANDARD DEVIATION IS:-"
sdmsg_len equ $-sdmsg
varmsg db 10,"CALCULATED VARIANCE IS:-"
varmsg_len equ $-varmsg
array dd 100.56,200.21,50.67,230.78,67.93
arraycnt dw 05
dpoint db '.'
hdec dq 100
section .bss
dispbuff resb 1
resbuff rest 1
mean resd 1
variance resd 1
%macro disp 2 ;macro call for display
mov rax,4 ;load system call for display
mov rbx,1 ;load standard output file to display
mov rcx,%1 ;load the address of buffer
mov rdx,%2 ;load length of buffer
int 80h ;call to kernel
%endmacro
%macro accept 2 ;macro call for accept
mov rax,3 ;load system call for display
mov rbx,0 ;load standard output file to display
mov rcx,%1 ;load the address of buffer
mov rdx,%2 ;load length of buffer
int 80h ;call to kernel
%endmacro
section .text
global _start
_start:
disp welmsg,welmsg_len ;display msg
finit
fldz
mov rbx,array ;move array into rbx
mov rsi,00 ;clear rsi reg.
xor rcx,rcx ;clear rcx reg.
mov cx,[arraycnt] ;mov arraycnt into cx reg.
up: fadd dword[RBX+RSI*4]
inc rsi ;inc rsi
loop up
fidiv word[arraycnt]
fst dword[mean]
disp meanmsg,meanmsg_len ;display msg
call dispres ;call disperse
MOV RCX,00 ;clear rcx reg.
MOV CX,[arraycnt] ;mov arraycnt into cx reg.
MOV RBX,array ;mov array into rbx reg.
MOV RSI,00 ;clear rsi reg.
FLDZ
up1: FLDZ
FLD DWORD[RBX+RSI*4]
FSUB DWORD[mean]
FST ST1
FMUL
FADD
INC RSI
LOOP up1
FIDIV word[arraycnt]
FST dWORD[variance]
FSQRT
disp sdmsg,sdmsg_len ;display msg
CALL dispres ;call to disprse
FLD dWORD[variance]
disp varmsg,varmsg_len ;displa msg
CALL dispres ;call to dispse
exit: mov rax,60 ;move to rax reg.
mov rdi,0 ;clear rdi reg.
int 80h ;system call
disp8_proc:
mov rdi,dispbuff ;mov dispbuff t rdi reg.
mov rcx,02 ;mov 02 to rcx reg.
back: rol bl,04
mov dl,bl ;mov bl int dl
and dl,0FH
cmp dl,09 ;compare dl with 09
jbe next1
add dl,07H ;add dl with 07h
next1: add dl,30H ;add dl with 30h
mov [rdi],dl ;mov dl into rdi
inc rdi ;increament rdi
loop back
ret ;return
dispres:
fimul dword[hdec]
fbstp tword[resbuff]
xor rcx,rcx ;clear rcx reg.
mov rcx,09H ;mov 09 into rcx reg.
mov rsi,resbuff+9 ;mov resbuf+9 int rsi
up2: push rcx ;push rcx reg.
push rsi ;push rsi
mov bl,[rsi] ;mov contents of rsi int bl reg.
call disp8_proc ;call to dis8_proc
disp dispbuff,2 ;display dispbuf
pop rsi ;pop rsi
dec rsi ;decreament rsi reg.
pop rcx ;pop rcx reg.
loop up2
disp dpoint,1 ;display dpoint
mov bl,[resbuff] ;mov resbuff into bl reg.
call disp8_proc ;call to disp8_proc
disp dispbuff,2 ;display dispbuff
ret ;return
//================================Output=======================================//
aman@aman-230:~$ cd Desktop/
aman@aman-230:~/Desktop$ cd se55
aman@aman-230:~/Desktop/se55$ nasm -f elf64 pr7.asm -o pr7.o
aman@aman-230:~/Desktop/se55$ ld -o pr7 pr7.o
aman@aman-230:~/Desktop/se55$ ./pr7
***WELCOME TO 64 BIT PROGRAMMING***
CALCULATED MEAN IS:-000000000000000130.30
CALCULATED STANDARD DEVIATION IS:-000000000000000072.32
CALCULATED VARIANCE IS:-000000000000005219.39
aman@aman-230:~/Desktop/se55$
-----------------------------------------------
Program 7:
-----------------------------------------------
;--------------------------------------------------------------------------
ASSIGNMENT : 5(group A)
TITLE : Write 8086 ALP to perform string manipulation. The strings to
be accepted from the user is to be stored in data segment of
program_l and write FAR PROCEDURES in code segment program_2
for following operations on the string:(a) Concatenation of
two strings (b) Number of occurrences of a sub-string in the
given string Use PUBLIC and EXTERN directive. Create .OBJ
files of both the modules and link them to create an EXE file
R_NO : 14
BATCH : S1
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
section .data
;---------------------------------------------------------------------------
menumsg db 10,'----------------MENU-----------------'
db 10,'1.CONCATINATION'
db 10,'2.SUBSTRING'
db 10,'3.EXIT'
db 10,'ENTER YOUR CHOICE'
db 10,'-------------------------------------'
menumsgln equ $-menumsg
msg1 db 'ENTER THE MAIN STRING',10
msg1ln equ $-msg1
msg2 db 'ENTER THE SUB STRING',10
msg2ln equ $-msg2
;---------------------------------------------------------------------------
section .bss
;---------------------------------------------------------------------------
%include "ass5B.asm"
global mstr,mlen,substr,slen,concatstr,concatstrln ;used in another program
EXTERN proc_concat ,proc_substring ;refferde from another program
mstr resb 20
mstrln: equ $-mstr
substr resb 20
substrln: equ $-substr
concatstr resb 50
concatstrln: equ $-concatstr
mlen resb 2
slen resb 2
cnt resb 1
choice resb 2
choiceln equ $-choice
;---------------------------------------------------------------------------
section .text
;---------------------------------------------------------------------------
global _start
_start:
disp msg1,msg1ln ;taking 1st string
read mstr,mstrln
dec eax
mov [mlen],ax ;taking 1st stringlen
disp msg2,msg2ln ;taking 2nd string
read substr,substrln
dec eax
mov [slen],ax ;taking 2nd string
ms:
disp menumsg,menumsgln ;display menumsg
read choice,choiceln
;----------------------------------------------------------------------------
case_1:
cmp byte[choice],'1'
jne case_2
call proc_concat ;calling proc_concat
jmp ms
case_2:
cmp byte[choice],'2'
jne case_3
call proc_substring ;calling proc_substring
jmp ms
case_3:
mov eax,1 ;exit
mov ebx,0
int 80h
;-----------------------------------------------------------------------------
;---------------------------------------------------------------------------
%macro read 2 ;macro for accepting data
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro
%macro disp 2 ;macro for displaying data
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
section .data
;---------------------------------------------------------------------------
msg3 db 'CONCATINATED STRING IS',10
msg3ln equ $-msg3
msg4 db 'COUNT OF THE SUB STRING',10
msg4ln equ $-msg4
;---------------------------------------------------------------------------
section .bss
;---------------------------------------------------------------------------
dispnum resb 2
displen: equ $-dispnum
cnt resb 1
EXTERN mstr,mlen,substr,slen,concatstr,concatstrln
%include "ass5B.asm"
;---------------------------------------------------------------------------
section .text
;---------------------------------------------------------------------------
global _main
_main:
global proc_concat,proc_substring ;used in another program
;---------------------------------------------------------------------------
proc_concat:
xor rbx,rbx
xor rcx,rcx ;clearing registers
mov esi,mstr ;esi points to main string
mov edi,concatstr ;esi points to concated string
mov cx,[mlen] ;taking lenght of main string in cx
call l1
mov esi,substr ;esi points to sub string
mov cx,[slen] ;taking lenght of sub string in cx
call l1
disp msg3,msg3ln
disp concatstr,concatstrln ;displaying concated string
ret
l1:mov al,[esi]
mov [edi],al
inc esi
inc edi
dec ecx
jnz l1
ret
;---------------------------------------------------------------------------
proc_substring:
xor rbx,rbx ;clearing registers
xor rcx,rcx
mov ebp,mstr ;ebp points to main string
mov esi,mstr ;esi points to main string
mov edi,substr ;edi points to sub string
mov bx,[mlen] ;taking lenght of main string in bx
mov cx,[slen] ;taking lenght of sub string in cx
sub ebx,ecx ;subtracting ecx from ebx
inc ebx ;increament ebx
l2:cld
repe cmpsb ;comparing subsrting with main string
jne l3
inc byte[cnt]
l3:inc ebp
mov esi,ebp
mov edi,substr
mov cx,[slen]
dec ebx
jnz l2
disp msg4,msg4ln
xor rax,rax ;clearing register
mov al,[cnt]
call display8 ;displaying count of substring
ret
;----------------------------------------------------------------------------
display8: ;procedure for displaying 8
; bit number
mov ecx,2
mov esi,dispnum + 1
l4:mov dl,00
mov ebx,10
div ebx
cmp dl,09h
jbe skip
add dl,7h
skip:add dl,30h
mov [esi],dl
dec esi
dec ecx
jnz l4
disp dispnum,2
ret
-------------------------------------------------------------------------
OUTPUT
-------------------------------------------------------------------------
aman@aman-230:~/Desktop/MIT/se14$ nasm -f elf64 ass5A.asm -o ass5A.o
aman@aman-230:~/Desktop/MIT/se14$ nasm -f elf64 ass5B.asm -o ass5B.o
aman@aman-230:~/Desktop/MIT/se14$ nasm -f elf64 ass5C.asm -o ass5C.o
aman@aman-230:~/Desktop/MIT/se14$ ld -o output1 ass5A.o ass5C.o
aman@aman-230:~/Desktop/MIT/se14$ ./output1
ENTER THE MAIN STRING
ashwini
ENTER THE SUB STRING
ash
----------------MENU-----------------
1.CONCATINATION
2.SUBSTRING
3.EXIT
ENTER YOUR CHOICE
-------------------------------------1
CONCATINATED STRING IS
ashwiniash
----------------MENU-----------------
1.CONCATINATION
2.SUBSTRING
3.EXIT
ENTER YOUR CHOICE
-------------------------------------2
COUNT OF THE SUB STRING
01
----------------MENU-----------------
1.CONCATINATION
2.SUBSTRING
3.EXIT
ENTER YOUR CHOICE
-------------------------------------3
ENTER THE MAIN STRING
ashjasioasfhas
ENTER THE SUB STRING
as
----------------MENU-----------------
1.CONCATINATION
2.SUBSTRING
3.EXIT
ENTER YOUR CHOICE
-------------------------------------1
CONCATINATED STRING IS
ashjasioasfhasas
----------------MENU-----------------
1.CONCATINATION
2.SUBSTRING
3.EXIT
ENTER YOUR CHOICE
-------------------------------------2
COUNT OF THE SUB STRING
04
----------------MENU-----------------
1.CONCATINATION
2.SUBSTRING
3.EXIT
ENTER YOUR CHOICE
-------------------------------------3
-----------------------------------------------
Program 8:
-----------------------------------------------
=============================================================================================
ASSIGNMENT NO:
GROUP: B
TITLE: Perform an experiment to establish communication between two 8251 systems A and B. Program 8251
system A in asynchronous transmitter mode and 8251 system B in asynchronous receiver mode. Write an
ALP to transmit the data from system A and receive the data at system B. The requirements are as follows:
Transmission:
• message is stored as ASCII characters in the memory.
• message specifies the number of characters to be transmitted as the first byte.
Reception:
• Message is retrieved and stored in the memory.
• Successful reception should be indicated.
BATCH:
ROLL NO:
===============================================================================
DYNA-86>A 1000 ;startting address
MOV AL,4D
OUT 31,AL
OUT 39,AL
MOV AL,11
OUT 31,AL
MOV AL,36
OUT 39,AL
MOV SI,2000 ;souce address
MOV DI,3000 ;destinetion address
MOV CL,05 ;5 numbers is transferd
L1:
` IN AL,31
AND AL,01
JZ L1;
MOV AL,[SI]
OUT 30,AL
L2:
IN AL,39
AND AL,02
JZ L2
IN AL,38
MOV [DI],AL
INC SI
INC DI
DEC CL
JNZ L1
INT 3
//OUTPUT
DYNA-86>E 2000 ;startting address
61 62 AF FF 46
DYNA-86>G 1000
DYNA-86>D 3000 ;destination address
-----------------------------------------------
Program 9:
-----------------------------------------------
-----------------------------------------------------------------------------------
ASSIGNMENT NO:
GROUP NO:
BATCH:S
ROLL NO:
-----------------------------------------------------------------------------------
Title:
Write 8086 ALP to interface DAC and generate
following waveforms on oscilloscope,
(i) Square wave - Variable Duty Cycle and Frequency.
(ii) Ramp wave - Variable direction, (iii) Trapezoidal wave
(iv) Stair case wave
A)//SQURE WAWEFORM//
MOV AL,80 ;load 80 in AL
OUT 67,AL ;send AL to control word reg
MOV AL,00 ;load 00 in AL reg
OUT 63,AL ;send AL to port B
MOV AL,00 ;load 00 in AL
OUT 61,AL ;send AL to port A
L1: CALL DELAY
MOV AL,FF ;load FF in AL
OUT 61,AL ;send AL to port A
CALL DELAY
JMP L1
INT 3
-----------------------------------------------------------------
B)//TRIANGULAR WAWEFORM//
MOV AL,80 ;load 80 in AL
OUT 67,AL ;send AL to port B
MOV AL,01 ;load 01 in AL
OUT 63,AL ;send AL to port A
L1: MOV AL,00 ;load 00 in AL
L2: OUT 61,AL ;send AL to port A
INC AL
CMP AL,11 ;compare AL with 11
JNE L2 ;if not equal,jump to L2
L3: OUT 61,AL ;else,send AL to port A
DEC AL
CMP AL,00 ;compare AL with 00
JNE L3 ;if not equal,jump to L3
JMP L2
-----------------------------------------------------------
(C) RAMP WAVE:
2000:MOV AL,89 ;move 89 in AL
OUT 67,AL ;send AL to port B
MOV AL,01 ;move 01 in AL
OUT 63,AL ;send AL to port B
L4:INC AL ;increment AL
OUT 61,AL ;send AL to port A
JMP L4
--------------------------------------------------------
Delay Routine
DYNA-86>A 2000 ;Delay address
PUSH BX
PUSH CX
L2: MOV BX,000F
MOV CX,00FF
L3:LOOP L3
DEC BX
JNZ L2
POP CX
POP BX
RET
-----------------------------------------------------
-----------------------------------------------
Program 10:
-----------------------------------------------
-----------------------------------------------------------------------------------
ASSIGNMENT NO:
GROUP NO:
BATCH:S
ROLL NO:
-----------------------------------------------------------------------------------
TITLE:-write 8086 ALP to program 8279 in left/right entry
A)Eight 8 bit character display left entry
DYNA- 86> A 2000
MOV CL,08 ;load counter
MOV AL,00 ;load 00 in AL(Eight 8 bit character display left entry)
OUT 31,AL ;sent AL to command port
MOV BX,1000 ;load address(1000) in BX
L1: MOV AL,[BX] ;load contents of BX in AL
OUT 30,AL ;send AL to data port
INC BX
DEC CL
JNZ L1 ;jump to l1,if count is not zero
INT 3
---------------------------------------------------------------------------------
B)Eight 8 bit character display right entry
DYNA- 86> A 2000
MOV AL,10 ;load 10 in AL(Eight 8 bit character display right entry)
OUT 31,AL ;sent AL to command port
MOV BX,1000 ;load address(1000) in BX
MOV CL,08 ;load counter
L1: MOV AL,[BX] ;load contents of BX in AL
OUT 30,AL ;send AL to data port
call Delay
INC BX
DEC CL
JNZ L1 ;jump to l1,if count is not zero
MOV CL,08
L2: MOV AL,00
OUT 30,AL ;send AL to data port
DEC CL
JNZ L2 ;jump to l2,if count is not zero
JMP L1
INT 3
-----------------------------------------------------------------------------------
DYNA-86>U 2000 ;Enter delay code
;------------------------------------------------------
Delay Routine
DYNA-86>A 2000 ;Delay address
PUSH BX
PUSH CX
L2: MOV BX,000F
MOV CX,00FF
L3:LOOP L3
DEC BX
JNZ L2
POP CX
POP BX
RET
-----------------------------------------------
Program 11:
-----------------------------------------------
===================================================================================
TITLE:-(c) Write 8086 ALP to rotate a stepper motor for given number of steps at a given
angle and in the given direction of rotation based on the user choice such as
(i) clockwise rotation, (ii) anticlockwise rotation. (iii) 1/2 clockwise
(iv)Anti-clock wise rotation. Also write routines to accelerate and
deaccelerate the motor.
==================================================================================
A) Full step clockwise:
-------------------------------------------------------------------------------
DYNA-86>A 1000 ;Starting Address
MOV AL,80 ;load 80 in AL
OUT 67,AL ;send AL to control word(67)
L1: MOV AL,0A ;load 0A in AL
OUT 61,AL ;send to port A
CALL delay
MOV AL,09 ;load 09 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,05 ;load 05 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,06 ;load 06 in AL
OUT 61,AL ;send AL to port A
CALL delay
JMP L1
INT 3 ;Press ENTER twice
------------------------------------------------------------------------------------
B) Full step Anticlockwise:
------------------------------------------------------------------------------------
DYNA-86>A 1000 ;Starting Address
MOV AL,80 ;load 80 in AL
OUT 67,AL ;send AL to control word(67)
L1: MOV AL,06 ;load 06 in AL
OUT 61,AL ;send AL to port A
CALL delay ;call delay(2000)
MOV AL,05 ;load 05 in AL
OUT 61,AL ;send AL to port A
CALL delay ;call delay(2000)
MOV AL,09 ;load 09 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,0A ;load 0A in AL
OUT 61,AL ;send AL to port A
CALL delay
JMP L1
INT 3 ;Press ENTER twice
------------------------------------------------------------------------------------
C) Half step clockwise:
-----------------------------------------------------------------------------------
DYNA-86>A 1000 ;Starting Address
MOV AL,80 ;load 80 in AL
OUT 67,AL ;send AL to control word(67)
L1: MOV AL,0A ;load 0A in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,08 ;load 08 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,09 ;load 09 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,01 ;load 01 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,05 ;load 05 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,04 ;load 04 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,06 ;load 06 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,02 ;load 02 in AL
OUT 61,AL ;send AL to port A
CALL delay
JMP L1
INT 3 ;Press ENTER twice
------------------------------------------------------------------------------------
D) Half step Anticlockwise:
-------------------------------------------------------------------
DYNA-86>A 1000 ;Starting Address
MOV AL,80 ;load 80 in AL
OUT 67,AL ;send AL to control word(67)
L1: MOV AL,02 ;load 02 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,06 ;load 06 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,04 ;load 04 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,05 ;load 05 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,01 ;load 01 in AL
OUT 61,AL ;send AL to port A
CALL 2000
MOV AL,09 ;load 09 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,08 ;load 08 in AL
OUT 61,AL ;send AL to port A
CALL delay
MOV AL,0A ;load 0A in AL
OUT 61,AL ;send AL to port A
CALL delay
JMP L1
INT 3 ;Press ENTER twice
;------------------------------------------------------
DYNA-86>U 2000 ;Enter delay code
;------------------------------------------------------
Delay Routine
DYNA-86>A 2000 ;Delay address
PUSH BX
PUSH CX
L2: MOV BX,000F
MOV CX,00FF
L3:LOOP L3
DEC BX
JNZ L2
POP CX
POP BX
RET