MIT PROGRAMS



                                   
                                                Assignment No.1
section .data
msg1           db      10,10,"Add an array of n hexadecimal no. and display the result"
msg1_len    equ    $-msg1



amsg2                   db      10,10,"Enter a size of Array : "
amsg2_len  equ    $-amsg2     



msg3           db      10,"Enter data "
msg3_len    equ    $-msg3



msg4           db      10,10,"Result = "
msg4_len    equ    $-msg4



msg5           db      10,10,"You hav entered Invalid data"
msg5_len    equ    $-msg5






section .bss
buf    resb   5        ;4digit+enter
buf_len       equ    $-buf
size    resw  1        ;16 bit(1digit=4bit so 4digit*4=16bit)
resl    resw  1
resh   resw  1



char_ans     resb   4






%macro print 2
mov rax,1  ;System call for print
mov rdi,1    ;file standard output
mov rsi,%1           ;address of message
mov rdx,%2         ;maximum number of bytes to write
syscall
%endmacro



%macro read 2
mov rax,0   ;System call for read
mov rdi,0    ;file standard input
mov rsi,%1 ;address of message
mov edx,%2         ;maximum number of bytes to read
syscall
%endmacro



%macro exit 0
mov rax,60 ;System call for exit
mov rbx,0   ;clear the contents
syscall
%endmacro



section .text
          global _start
_start:



          print msg1,msg1_len
          print amsg2,amsg2_len
          read   buf,buf_len
          call    accept_16            ;convert ascii to hex
          mov   [size],bx
          mov   rbp,[size]



next_num:
          print  msg3,msg3_len
          read   buf,buf_len
          call    accept_16
          add    [resl],bx
          jnc     next
          inc     word[resh]
next:
          dec    rbp
          jnz     next_num
         
          print  msg4,msg4_len
          mov   rax,[resh]
          call    display_16
          mov   rax,[resl]
          call    display_16



exit



accept_16:



          xor    bx,bx
          mov   rcx,04
          mov   rsi,buf



next_digit:



          rol     bx,04
          mov   al,[rsi]
          cmp   al,'0'
          jb       error
          cmp   al,'9'
          jbe     sub30
          cmp   al,'A'
          jb       error
          cmp   al,'F'
          jbe     sub37
          cmp   al,'a'
          jb       error
          cmp   al,'f'
          jbe     sub57



error:
          print  msg5,msg5_len



exit



sub57:
          sub    al,20H
sub37:
          sub    al,07H
sub30:
          sub    al,30H



add    bx,ax
inc     rsi
dec    rcx
jnz     next_digit
ret






display_16:
          mov   rsi,char_ans+3           ;16 bit=3,8bit=1
          mov   rcx,4
          mov   rbx,16



next_digit1:
          xor    rdx,rdx
          div     rbx
          cmp   dl,09H
          jbe     add30
          add    dl,07H



add30:
          add    dl,30H
          mov   [rsi],dl
          dec    rsi
          dec    rcx
          jnz     next_digit1
          print  char_ans,4              ;16 bit=4,8bit=2
         
ret    
.......................................................................................................................................
                                               
                                                          Output



sunil@ubuntu:~/Desktop/mit$ nasm -f elf64 Ass1.asm -o Ass1.o
sunil@ubuntu:~/Desktop/mit$ ld -o Ass1 Ass1.o
sunil@ubuntu:~/Desktop/mit$ ./Ass1






Add an array of n hexadecimal no. and display the result



Enter a size of Array : 0004



Enter data 0001



Enter data 0002



Enter data 0003



Enter data 0004









Result = 0000000Asunil@ubuntu:~/Desktop/mit$



-----------------------------------------------------------------------------------------------------



                                   
                                                Assignment No.2.1
section .data



msg1           db      10,10,"Block Tranfer without overlap"
msg1_len    equ    $-msg1



amsg2                   db      10,10,"Before block tranfer content is   "
amsg2_len  equ    $-amsg2     



msg3           db      10,10,10,"After block tranfer content is  "
msg3_len    equ    $-msg3



msg4           db      10,10,"source block content is : "
msg4_len    equ    $-msg4



msg5           db      10,10,"destination block content is :"
msg5_len    equ    $-msg5



space          db      " "



line              db      10
line_len       equ    $-line



line1            db      10,10
line1_len     equ    $-line1



sblock         db      10h,20h,30h,40h,50h
dblock         times 5 db   0



section .bss
char_ans     resb   2         ;16bit=4,8bit=2



%macro print 2
mov rax,1  ;System call for print
mov rdi,1    ;file standard output
mov rsi,%1           ;address of message
mov rdx,%2         ;maximum number of bytes to write
syscall
%endmacro



%macro exit 0
mov rax,60 ;System call for exit
mov rdi,0    ;clear the contents
syscall
%endmacro



section .text
          global _start
_start:
         
          print msg1,msg1_len
          print amsg2,amsg2_len
         
        print   msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp



          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock
          call    block_disp
          call    block_transfer



          print  msg3,msg3_len



          print msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp



          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock
          call    block_disp
          print  line1,line1_len



exit   



block_disp:
          mov   rbp,5
next_num:
          mov   al,[rsi]
          push  rsi
          call    display_8
          print  space,1      
          pop   rsi
          inc     rsi
          dec    rbp
          jnz     next_num
ret    



block_transfer:
          mov   rsi,sblock
          mov   rdi,dblock
          mov   rcx,5
loop:
          mov   al,[rsi]
          mov   [rdi],al
          inc     rsi
          inc     rdi
          dec    rcx
          jnz     loop



ret
display_8:
          mov   rsi,char_ans+1           ;16 bit=3,8bit=1
          mov   rcx,2                    ;;16 bit=4,8bit=2
          mov   rbx,16



next_digit1:
          xor    rdx,rdx
          div     rbx
          cmp   dl,09H
          jbe     add30
          add    dl,07H



add30:
          add    dl,30H
          mov   [rsi],dl
          dec    rsi
          dec    rcx
          jnz     next_digit1
          print  char_ans,2              ;16 bit=4,8bit=2
         
ret    
...........................................................................................................................................................



                                                          output:






student@OS18:~/179$ nasm -f elf64 blocktr.asm -o blocktr.o
student@OS18:~/179$ ld -o blocktr blocktr.o
student@OS18:~/179$ ./blocktr



Block Tranfer without overlap



Before block tranfer content is  



source block content is :
10 20 30 40 50



destination block content is :
00 00 00 00 00






After block tranfer content is 



source block content is :
10 20 30 40 50



destination block content is :
10 20 30 40 50



student@OS18:~/179$



---------------------------------------------------------------------------------------------------



                                   
                                                Assignment No.2.2
section .data



msg1           db      10,10,"Block Tranfer without overlap using string instuction"
msg1_len    equ    $-msg1



amsg2                   db      10,10,"Before block tranfer content is   "
amsg2_len  equ    $-amsg2     



msg3           db      10,10,10,"After block tranfer content is  "
msg3_len    equ    $-msg3



msg4           db      10,10,"source block content is : "
msg4_len    equ    $-msg4



msg5           db      10,10,"destination block content is :"
msg5_len    equ    $-msg5



space          db      " "



line              db      10
line_len       equ    $-line



line1            db      10,10
line1_len     equ    $-line1



sblock         db      10h,20h,30h,40h,50h
dblock         times 5 db   0



section .bss
char_ans     resb   2         ;16bit=4,8bit=2



%macro print 2
mov rax,1  ;System call for print
mov rdi,1    ;file standard output
mov rsi,%1           ;address of message
mov rdx,%2         ;maximum number of bytes to write
syscall
%endmacro



%macro exit 0
mov rax,60 ;System call for exit
mov rdi,0    ;clear the contents
syscall
%endmacro



section .text
          global _start
_start:
         
          print msg1,msg1_len



          print amsg2,amsg2_len
         
        print   msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp



          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock
          call    block_disp
          call    block_transfer



          print  msg3,msg3_len
          print msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp



          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock
          call    block_disp
          print  line1,line1_len



exit   



block_disp:
          mov   rbp,5
next_num:
          mov   al,[rsi]
          push  rsi



          call    display_8
          print  space,1      
         
          pop   rsi
          inc     rsi
          dec    rbp
          jnz     next_num
ret    



block_transfer:
          mov   rsi,sblock
          mov   rdi,dblock
          mov   rcx,5
loop:
          CLD
          rep    movsb
                  
ret
         



display_8:
          mov   rsi,char_ans+1           ;16 bit=3,8bit=1
          mov   rcx,2                    ;;16 bit=4,8bit=2
          mov   rbx,16



next_digit1:
          xor    rdx,rdx
          div     rbx
          cmp   dl,09H
          jbe     add30
          add    dl,07H



add30:
          add    dl,30H
          mov   [rsi],dl
          dec    rsi
          dec    rcx
          jnz     next_digit1
          print  char_ans,2              ;16 bit=4,8bit=2
         
ret              
...........................................................................................................................................................



                                                          output:



student@OS18:~/179$ nasm -f elf64 blocktr1.asm -o blocktr1.o
student@OS18:~/179$ ld -o blocktr1 blocktr1.o
student@OS18:~/179$ ./blocktr1



Block Tranfer without overlap using string instuction



Before block tranfer content is  



source block content is :
10 20 30 40 50
destination block content is :
00 00 00 00 00



After block tranfer content is 
source block content is :
10 20 30 40 50



destination block content is :
10 20 30 40 50



student@OS18:~/179$



-------------------------------------------------------------------------------------------------------



                                   
                                                Assignment No.2.3
section .data



msg1           db      10,10,"Block Tranfer with overlap"
msg1_len    equ    $-msg1



amsg2                   db      10,10,"Before block tranfer content is   "
amsg2_len  equ    $-amsg2     



msg3           db      10,10,10,"After block tranfer content is  "
msg3_len    equ    $-msg3



msg4           db      10,10,"source block content is : "
msg4_len    equ    $-msg4



msg5           db      10,10,"destination block content is :"
msg5_len    equ    $-msg5



space          db      " "



line              db      10
line_len       equ    $-line



line1            db      10,10
line1_len     equ    $-line1



sblock         db      10h,20h,30h,40h,50h
dblock         times 5 db   0



section .bss
char_ans     resb   2         ;16bit=4,8bit=2



%macro print 2
mov rax,1  ;System call for print
mov rdi,1    ;file standard output
mov rsi,%1           ;address of message
mov rdx,%2         ;maximum number of bytes to write
syscall
%endmacro



%macro exit 0
mov rax,60 ;System call for exit
mov rdi,0    ;clear the contents
syscall
%endmacro



section .text
          global _start
_start:
         
          print msg1,msg1_len



          print amsg2,amsg2_len
         



        print   msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp






          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock-2
          call    block_disp
          call    block_transfer



          print  msg3,msg3_len
          print msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp



          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock-2
          call    block_disp
          print  line1,line1_len



exit   



block_disp:
          mov   rbp,5
next_num:
          mov   al,[rsi]
          push  rsi



          call    display_8
          print  space,1      
         
          pop   rsi
          inc     rsi
          dec    rbp
          jnz     next_num
ret    



block_transfer:
          mov   rsi,sblock+4
          mov   rdi,dblock+2
          mov   rcx,5
loop:
          mov   al,[rsi]
          mov   [rdi],al
          dec    rsi
          dec    rdi
          dec    rcx
          jnz     loop



ret
         
display_8:
          mov   rsi,char_ans+1           ;16 bit=3,8bit=1
          mov   rcx,2                    ;;16 bit=4,8bit=2
          mov   rbx,16



next_digit1:
          xor    rdx,rdx
          div     rbx
          cmp   dl,09H
          jbe     add30
          add    dl,07H



add30:
          add    dl,30H
          mov   [rsi],dl
          dec    rsi
          dec    rcx
          jnz     next_digit1
          print  char_ans,2              ;16 bit=4,8bit=2
         
ret                        
.......................................................................................................................................
                                                          output:



student@OS18:~/179$ nasm -f elf64 blocktr2.asm -o blocktr2.o
student@OS18:~/179$ ld -o blocktr2 blocktr2.o
student@OS18:~/179$ ./blocktr2



Block Tranfer with overlap



Before block tranfer content is  
source block content is :
10 20 30 40 50
destination block content is :
40 50 00 00 00



After block tranfer content is 
source block content is :
10 20 30 40 50



destination block content is :
10 20 30 10 20



student@OS18:~/179$ 



--------------------------------------------------------------------------------------------------



                                   
                                                Assignment No.2.4
section .data



msg1           db      10,10,"Block Tranfer with overlap using string instuction"
msg1_len    equ    $-msg1



amsg2                   db      10,10,"Before block tranfer content is   "
amsg2_len  equ    $-amsg2     



msg3           db      10,10,10,"After block tranfer content is  "
msg3_len    equ    $-msg3



msg4           db      10,10,"source block content is : "
msg4_len    equ    $-msg4



msg5           db      10,10,"destination block content is :"
msg5_len    equ    $-msg5



space          db      " "



line              db      10
line_len       equ    $-line



line1            db      10,10
line1_len     equ    $-line1



sblock         db      10h,20h,30h,40h,50h,60h,70h,80h,90h,11h
dblock         times 10 db 0



section .bss
char_ans     resb   2         ;16bit=4,8bit=2



%macro print 2
mov rax,1  ;System call for print
mov rdi,1    ;file standard output
mov rsi,%1           ;address of message
mov rdx,%2         ;maximum number of bytes to write
syscall
%endmacro






%macro exit 0
mov rax,60 ;System call for exit
mov rdi,0    ;clear the contents
syscall
%endmacro



section .text
          global _start
_start:
         
          print msg1,msg1_len



          print amsg2,amsg2_len
         



        print   msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp






          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock-4
          call    block_disp






          call    block_transfer



          print  msg3,msg3_len



          print msg4,msg4_len
          print  line,line_len
          mov   rsi,sblock
          call    block_disp



          print msg5,msg5_len
          print  line,line_len
          mov   rsi,dblock-4
          call    block_disp
          print  line1,line1_len



exit   



block_disp:
          mov   rbp,10
next_num:
          mov   al,[rsi]
          push  rsi



          call    display_8
          print  space,1      
         
          pop   rsi
          inc     rsi
          dec    rbp
          jnz     next_num
ret    



block_transfer:
          mov   rsi,sblock+9
          mov   rdi,dblock+5
          mov   rcx,10
loop:
          std
          rep    movsb
ret
         



display_8:
          mov   rsi,char_ans+1           ;16 bit=3,8bit=1
          mov   rcx,2                    ;;16 bit=4,8bit=2
          mov   rbx,16



next_digit1:
          xor    rdx,rdx
          div     rbx
          cmp   dl,09H
          jbe     add30
          add    dl,07H



add30:
          add    dl,30H
          mov   [rsi],dl
          dec    rsi
          dec    rcx
          jnz     next_digit1
          print  char_ans,2              ;16 bit=4,8bit=2
         
ret    
...........................................................................................................................................................



                                                          output:
tudent@OS18:~/179$ nasm -f elf64 blocktr3.asm -o blocktr3.o
student@OS18:~/179$ ld -o blocktr3 blocktr3.o
student@OS18:~/179$ ./blocktr3





Block Tranfer with overlap using string instuction


Before block tranfer content is  



source block content is :
10 20 30 40 50 60 70 80 90 11
destination block content is :
70 80 90 11 00 00 00 00 00 00



After block tranfer content is 
source block content is :
10 20 30 40 50 60 10 20 30 40
destination block content is :
10 20 30 40 50 60 70 80 90 11



student@OS18:~/179$



-------------------------------------------------------------------------------------------------------



                                   
                                                Assignment No.3
section .data
msg1           db      10,10,"Convert hex to bcd and bcd to hex"
msg1_len    equ    $-msg1



menu           db      10,10,"1.hex to bcd"
                   db      10,"2.bcd to hex"
                   db      10,"3.exit",10
                   db      "Enter ur choice"
menu_len    equ    $-menu



amsg2                   db      10,10,"Enter 5 digit bcd no. "
amsg2_len  equ    $-amsg2     



msg3           db      10,10,"bcd no. is  "
msg3_len    equ    $-msg3



msg4           db      10,"hex no. is "
msg4_len    equ    $-msg4



amsg21                 db      10,10,"Enter 4 digit hex no. "
amsg21_len equ    $-amsg21   



msg31                  db      10,10,"hex no. is  "
msg31_len  equ    $-msg31



msg41                  db      10,"bcd no. is "
msg41_len  equ    $-msg41



msg5           db      10,10,"You hav entered Invalid data",10
msg5_len    equ    $-msg5



em               db      10,"Enter valid option "
em_len        equ    $-em



line1            db      10,10
line1_len     equ    $-line1



section .bss
buf    resb   5        ;4digit+enter
buf_len       equ    $-buf
size    resw  1        ;16 bit(1digit=4bit so 4digit*4=16bit)
resl    resw  1
resh   resw  1



char_ans     resb   4



ans    resw  1        ;temp variable






%macro print 2
mov rax,1  ;System call for print
mov rdi,1    ;file standard output
mov rsi,%1           ;address of message
mov rdx,%2         ;maximum number of bytes to write
syscall
%endmacro



%macro read 2
mov rax,0   ;System call for read
mov rdi,0    ;file standard input
mov rsi,%1 ;address of message
mov edx,%2         ;maximum number of bytes to read
syscall
%endmacro



%macro exit 0
mov rax,60 ;System call for exit
mov rbx,0   ;clear the contents
syscall
%endmacro



section .text
          global _start
_start:



          Menu:        
                   print msg1,msg1_len
                   print menu,menu_len
                   read   buf,2                     ;(1 digit + enter)
                   mov   al,[buf]         
                  
          c1:    
                   cmp   al,'1'
                   jne     c2
                   call    hex_to_bcd
                   jmp   Menu






          c2:    
                   cmp   al,'2'
                   jne     c3
                   call    bcd_to_hex
                   jmp   Menu



          c3:    
                   cmp   al,'3'
                   jne     error
                   exit
          error:
                   print  em,em_len
                   jmp   Menu
exit
                   ;bcd to hex
bcd_to_hex:
          print amsg2,amsg2_len
          read   buf,6
          print  msg3,msg3_len
          print buf,6
          mov   rsi,buf
          xor    ax,ax
          mov   rbp,5
          mov   rbx,10
                  
back:
          xor    cx,cx
          mul    bx
          mov   cl,[rsi]
          sub    cl,30h
          add    ax,cx
          inc     rsi
          dec    rbp
          jnz     back
         
          mov   [ans],ax
          print  msg4,msg4_len
          mov   ax,[ans]
          call    display_16
ret
         
                   ;hex to bcd
hex_to_bcd:
          print amsg21,amsg21_len
          read   buf,buf_len
          print  msg31,msg31_len
          print buf,buf_len
          call    accept_16
          mov  ax,bx
          mov  bx,10
          mov   bp,bp
back2:
          xor    dx,dx
          div     bx
          push  dx
          inc     bp
          cmp   ax,0
          jne     back2
          print  msg41,msg41_len
back1:
          pop   dx
          add    dl,30h
          mov   [char_ans],dl
          print  char_ans,1
          dec    bp
          jne     back1
          print line1,line1_len
ret
         
accept_16:



          xor    bx,bx
          mov   rcx,04
          mov   rsi,buf



next_digit:



          rol     bx,04
          mov   al,[rsi]
          cmp   al,'0'
          jb       error2
          cmp   al,'9'
          jbe     sub30
          cmp   al,'A'
          jb       error2
          cmp   al,'F'
          jbe     sub37
          cmp   al,'a'
          jb       error2
          cmp   al,'f'
          jbe     sub57



error2:
          print  msg5,msg5_len



exit



sub57:
          sub    al,20H
sub37:
          sub    al,07H
sub30:
          sub    al,30H



add    bx,ax
inc     rsi
dec    rcx
jnz     next_digit
ret



display_16:
          mov   rsi,char_ans+3           ;16 bit=3,8bit=1
          mov   rcx,4
          mov   rbx,16



next_digit1:
          xor    rdx,rdx
          div     rbx
          cmp   dl,09H
          jbe     add30
          add    dl,07H



add30:
          add    dl,30H
          mov   [rsi],dl
          dec    rsi
          dec    rcx
          jnz     next_digit1
          print  char_ans,4              ;16 bit=4,8bit=2
          print  line1,line1_len     
ret    
         
...........................................................................................................................................................



                                                          output:
sunil@ubuntu:~/Desktop/mit$ nasm -f elf64 convesion.asm -o convesion.o
sunil@ubuntu:~/Desktop/mit$ ld -o convesion convesion.o
sunil@ubuntu:~/Desktop/mit$ ./convesion



Convert hex to bcd and bcd to hex



1.hex to bcd
2.bcd to hex
3.exit
Enter ur choice2



Enter 5 digit bcd no. 00009



bcd no. is  00009
hex no. is 0009



Convert hex to bcd and bcd to hex



1.hex to bcd
2.bcd to hex
3.exit
Enter ur choice1



Enter 4 digit hex no. 000A



hex no. is  000A
bcd no. is 10



Convert hex to bcd and bcd to hex



1.hex to bcd
2.bcd to hex
3.exit
Enter ur choice3
sunil@ubuntu:~/Desktop/mit$



------------------------------------------------------------------------------------------------------



                                   
                                                Assignment No.4
section        .data

          amsg           db      10,10,"String Operation (Length,Reverse,Palindrome)"
          amsg_len    equ    $-amsg      

          emsg           db      10,10,"Enter a String "
          emsg_len              equ    $-emsg

          smsg           db      10,10,"String is : "
          smsg_len     equ    $-smsg

   
          Menu        db      10,"1.String length "
         
                           db      10,"2.Reverse String "
         
                             db      10,"3.Palindrome opration"
         
                             db      10,"4.Exit"
         
                      
    Menulen    equ    $-Menu
         
          lmsg            db      10,"String length is : "
          lmsg_len     equ    $-lmsg

          rmsg           db      10,10,"Reverse String is : "
          rmsg_len     equ    $-rmsg

       
          pmsg           db      10,10,"String is palindrome"
          pmsg_len              equ    $-pmsg

          npmsg                  db      10,10,"String is not Palindrome"
          npmsg_len  equ    $-npmsg

    em               db      10,"Enter valid option "
        em_len        equ    $-em

          space          db      " "

          line              db      10
          line_len       equ    $-line

          line1            db      10,10
          line1_len     equ    $-line1

section                  .bss
        
          buf              resb   6        ;4digit+enter
          buf_len                 equ    $-buf         

          source                   resb   20
          source_len  equ    $-source

          dest             resb   20
          dest_len      equ    $-dest

          len               resw  1      

          char_ans     resb   4         ;16bit=4,8bit=2

%macro                print 2

          mov rax,1  ;System call for print
          mov rdi,1    ;file standard output
          mov rsi,%1           ;address of message
          mov rdx,%2         ;maximum number of bytes to write
          syscall       
%endmacro

%macro                read   2

          mov rax,0   ;System call for read
          mov rdi,0    ;file standard input
          mov rsi,%1 ;address of message
          mov edx,%2         ;maximum number of bytes to read
          syscall
%endmacro

%macro                exit    0

          mov rax,60 ;System call for exit
          mov rdi,0    ;clear the contents
          syscall
%endmacro

section                  .text
          global _start       

_start:

menu:

          print  amsg,amsg_len
          print Menu,Menulen
          read   buf,2                     ;(1 digit + enter)
          mov   al,[buf]    
          c1:   
                   cmp   al,'1'
                   jne     c2
                   print  emsg,emsg_len
                   read   source, source_len
                   dec    rax
                   mov   [len],rax
   
                   print  smsg,smsg_len
                   print  source, source_len

                   print  lmsg,lmsg_len
                   call    str_len
                   jmp   menu
     c2:  
                   cmp   al,'2'
                   jne     c3
                   print  emsg,emsg_len
                   read   source, source_len
                   dec    rax
                   mov   [len],rax
   
                   print  smsg,smsg_len
                   print  source, source_len

                   print  rmsg,rmsg_len
                   call    str_rev
                   jmp   menu
    c3:  
                   cmp   al,'3'
                   jne     c4
                  print  emsg,emsg_len
                  read   source, source_len
                  dec    rax
                  mov   [len],rax
   
                  print  smsg,smsg_len
                  print  source, source_len

                  call    str_pal
                  jmp   menu
    c4:  
                  cmp   al,'4'
                  jne     error
                  exit
    error:
                 print em,em_len  

exit
       
str_len:
          xor    rax,rax
          mov   rax,[len]
        
          call display_16
ret

str_rev:

          mov   rdi,dest
          xor    rcx,rcx
          mov   cx,[len]
          mov   rsi,source
          add    rsi,rcx
          dec    rsi

next:
          mov   al,[rsi]
          mov   [rdi],al
        
          inc     rdi
          dec    rsi
          dec    rcx
          jnz     next
          print  dest,dest_len
          print  line1,line1_len
ret

str_pal:

        
    mov RSI,source
    mov RDI,source
   
    XOR RCX,RCX
        mov CX,[len]
   
    add RDI,RCX
    dec RDI
    SHR RCX,1           ;rcx=rcx/2   
   
next_bytes:
    mov AL,[RSI]
    cmp [RDI],AL
    JE next_p
   
    print npmsg,npmsg_len
    RET
   
next_p:   
    inc RSI
    dec RDI
    dec RCX
   
    JNZ next_bytes
   
   
    print pmsg,pmsg_len
RET
        
display_16:
          mov   rsi,char_ans+3           ;16 bit=3,8bit=1,32bit=7
          mov   rcx,4                    ;16 bit=4,32bit=8
          mov   rbx,16

next_digit1:
          xor    rdx,rdx
          div     rbx
          cmp   dl,09H
          jbe     add30
          add    dl,07H

add30:
          add    dl,30H
          mov   [rsi],dl
          dec    rsi
          dec    rcx
          jnz     next_digit1
          print  char_ans,4              ;16 bit=4,8bit=2 ,32bit=8
          print  line1,line1_len    
ret               …......................................................................................................................................
                                                          output:
sunil@ubuntu:~/Desktop/MIT$ nasm -f elf64 41.asm -o 41.o
sunil@ubuntu:~/Desktop/MIT$ ld -o 41 41.o
sunil@ubuntu:~/Desktop/MIT$ ./41


String Operation (Length,Reverse,Palindrome)
1.String length
2.Reverse String
3.Palindrome opration
4.Exit1


Enter a String sunil


String is : sunil

String length is : 0005



String Operation (Length,Reverse,Palindrome)
1.String length
2.Reverse String
3.Palindrome opration
4.Exit2


Enter a String PCCOE


String is : PCCOE


Reverse String is : EOCCP



String Operation (Length,Reverse,Palindrome)
1.String length
2.Reverse String
3.Palindrome opration
4.Exit3


Enter a String MOM


String is : MOM
E


String is palindrome

String Operation (Length,Reverse,Palindrome)
1.String length
2.Reverse String
3.Palindrome opration
4.Exit3


Enter a String MIT


String is : MIT
E


String is not Palindrome

String Operation (Length,Reverse,Palindrome)
1.String length
2.Reverse String
3.Palindrome opration
4.Exit4
sunil@ubuntu:~/Desktop/MIT$



---------------------------------------------------------------------------------------------------------
  
                                     Assignment no.5

section .data
msg1        db    10,10,"Multiplication of two hex numbers"
msg1_len    equ    $-msg1
  

n1        db    10,10,"Enter 1st number "
n1_len    equ    $-n1

n2        db    10,"Enter 2nd number "
n2_len    equ    $-n2

res        db    10,10,"Multilication of given hex no. is : "
res_len    equ    $-res

msg5        db    10,10,"You hav entered Invalid data"
msg5_len    equ    $-msg5

line1        db    10,10
line1_len    equ    $-line1

em        db    10,"Enter valid option "
em_len    equ    $-em

menu        db    10,10,"1.Multiplication Using sucessive addition method"
        db    10,"2.Mulitplication using add_shift method"
        db    10,"3.exit",10
        db    "Enter ur choice"
menu_len    equ    $-menu


section .bss
buf    resb    5    ;4digit+enter
buf_len    equ    $-buf
size    resw    1    ;16 bit(1digit=4bit so 4digit*4=16bit)
resl    resw    1
resh    resw    1

f    resw    1
s    resw    1
ans    resd    1       
char_ans    resb    4


%macro print 2
mov rax,1      ;System call for print
mov rdi,1      ;file standard output
mov rsi,%1     ;address of message
mov rdx,%2     ;maximum number of bytes to write
syscall
%endmacro

%macro read 2
mov rax,0    ;System call for read
mov rdi,0    ;file standard input
mov rsi,%1    ;address of message
mov edx,%2    ;maximum number of bytes to read
syscall
%endmacro

%macro exit 0
mov rax,60    ;System call for exit
mov rbx,0    ;clear the contents
syscall
%endmacro

section .text
    global _start
_start:

;......................................................................................................................
   
Menu:   
        print     msg1,msg1_len
        print     menu,menu_len
        read    buf,2            ;(1 digit + enter)
        mov    al,[buf]         
       
    c1:   
        cmp    al,'1'
        jne    c2
        call s_add
        jmp    Menu


    c2:   
        cmp    al,'2'
        jne    c3
        call add_shift
        jmp    Menu

    c3:   
        cmp    al,'3'
        jne    error
        exit
    error:
        print    em,em_len
        jmp     Menu
exit

;......................................................................................................................

s_add:
    mov    word[resl],0
    mov    word[resh],0
   
    print    n1,n1_len
    read    buf,buf_len
    call    accept_16
    mov    [f],bx   

    print    n2,n2_len
    read    buf,buf_len
    call    accept_16
    mov    [s],bx

    mov    ax,[f]
    mov    cx,[s]
   
    cmp    cx,0
    je    final
loop:
    add    [resl],ax
    jnc    next0
    inc    word[resh]

next0:
    dec    cx
    jnz    loop

final:
    print res,res_len
   
    mov    ax,[resh]
    call    display_16
   
    mov    ax,[resl]
    call    display_16
    print    line1,line1_len
ret       

;......................................................................................................................

add_shift:

    mov    dword[ans],0

    print    n1,n1_len
    read    buf,buf_len
    call    accept_16
    mov    [f],bx   
   
    print    n2,n2_len
    read    buf,buf_len
    call    accept_16
    mov    [s],bx

    xor    rax,rax
    xor    rbx,rbx

    mov    ax,[f]
    mov    bx,[s]

    mov    cx,16
    mov     ebp,0

back:
    shl    ebp,1
    shl    ax,1
    jnc    next10
    add    ebp,ebx
   
next10:
    loop back

    mov    [ans],ebp
    print    res,res_len
    mov    eax,[ans]
    call    display_32
ret   

;......................................................................................................................

accept_16:

    xor    bx,bx
    mov    rcx,04
    mov    rsi,buf

next_digit:

    rol    bx,04
    mov    al,[rsi]
    cmp    al,'0'
    jb    error10
    cmp    al,'9'
    jbe    sub30
    cmp     al,'A'
    jb    error10
    cmp    al,'F'
    jbe    sub37
    cmp    al,'a'
    jb    error10
    cmp    al,'f'
    jbe    sub57

error10:
    print    msg5,msg5_len
    print    line1,line1_len

exit

sub57:
    sub    al,20H
sub37:
    sub    al,07H
sub30:
    sub    al,30H

add     bx,ax
inc    rsi
dec    rcx
jnz    next_digit
ret

;......................................................................................................................

display_16:
    mov     rsi,char_ans+3           ;16 bit=3,8bit=1
    mov    rcx,4
    mov    rbx,16

next_digit1:
    xor    rdx,rdx
    div    rbx
    cmp    dl,09H
    jbe    add30
    add    dl,07H

add30:
    add    dl,30H
    mov    [rsi],dl
    dec    rsi
    dec    rcx
    jnz    next_digit1
    print    char_ans,4              ;16 bit=4,8bit=2
   
   
ret   

;......................................................................................................................

display_32:
    mov     rsi,char_ans+7           ;16 bit=3,8bit=1,32bit=7
    mov    rcx,8                    ;16 bit=4,32bit=8
    mov    rbx,16

next_digit11:
    xor    rdx,rdx
    div    rbx
    cmp    dl,09H
    jbe    add301
    add    dl,07H

add301:
    add    dl,30H
    mov    [rsi],dl
    dec    rsi
    dec    rcx
    jnz    next_digit11
    print    char_ans,8              ;16 bit=4,8bit=2 ,32bit=8
    print    line1,line1_len   
ret   

;................................................................................................
                                        output

student@OS18:~/179$ nasm -f elf64 Ass5M.asm -o Ass5M.o
student@OS18:~/179$ ld -o Ass5M Ass5M.o
student@OS18:~/179$ ./Ass5M


Multiplication of two hex numbers

1.Multiplication Using sucessive addition method
2.Mulitplication using add_shift method
3.exit
Enter ur choice1


Enter 1st number 0010

Enter 2nd number 0050


Multilication of given hex no. is : 00000500



Multiplication of two hex numbers

1.Multiplication Using sucessive addition method
2.Mulitplication using add_shift method
3.exit
Enter ur choice2


Enter 1st number 1234

Enter 2nd number 0002


Multilication of given hex no. is : 00002468



Multiplication of two hex numbers

1.Multiplication Using sucessive addition method
2.Mulitplication using add_shift method
3.exit
Enter ur choice3
student@OS18:~/179$

 ;.....................................................................................................



                                          Assignment No.6 
       6A.asm
   ....................



global str1,str1_size,str2,str2_size,str1_len,str2_len
%include    "macro.asm"
extern    con_proc
extern    sub_proc
extern     str_name_len

;-------------------------------------------------------------------------------------------------------------------
;                    Data section
;-------------------------------------------------------------------------------------------------------------------

section     .data

    amsg        db    10,10,"ASSINMENT NO. 6 :- CONCATENATION AND SUBSTRING PROGRAM USING FAR CALL"
    amsg_len    equ    $-amsg  
;-------------------------------------------------------------------------------------------------------------------
;                    Input string msgs
;-------------------------------------------------------------------------------------------------------------------

          
    e1msg        db    10,10,"Enter a String1 "
    e1msg_len        equ    $-e1msg

    e2msg        db    10,10,"Enter a String2 "
    e2msg_len        equ    $-e2msg


   
;-------------------------------------------------------------------------------------------------------------------
;                    Menu realated msgs
;-------------------------------------------------------------------------------------------------------------------
   
   
    menu    db    10,"1.     STRINGS NAME AND LENGHT"
    db    10,"2.     STRING CONCATENATION"
    db    10,"3.    NO. OF OCCURANCE OF SUBSTRING IN GIVEN STRING"
    db    10,"4.    EXIT"
    db    10,"Enter your choice"    ,10
    menu_len    equ    $-menu

    emsg    db    10,10,"Invalid number"    ,10
    emsg_len    equ    $-emsg

;-------------------------------------------------------------------------------------------------------------------
;                    Bss section
;-------------------------------------------------------------------------------------------------------------------

section        .bss
   
    buf        resb    2
    str1        resb    20
    str1_len    equ    $-str1

    str2        resb    20
    str2_len    equ    $-str2

    str1_size    resw    1
    str2_size    resw    1
   
;-------------------------------------------------------------------------------------------------------------------
;                    Text section
;-------------------------------------------------------------------------------------------------------------------


section        .text
    global _start   

_start:
   
    print    amsg,amsg_len

    print    e1msg,e1msg_len

    read    str1,str1_len
    dec     rax
    mov    [str1_size],rax
   
   

    print    e2msg,e2msg_len

    read    str2,str2_len
    dec     rax
    mov    [str2_size],rax


MENU :
    print    menu,menu_len
    read    buf,2
    mov    al,[buf]

c1 :  
    cmp    al,'1'
    jne    c2
    call    str_name_len
    jmp    MENU

c2 :
    cmp    al,'2'
    jne    c3
    call    con_proc
    jmp    MENU

c3 :
    cmp    al,'3'
    jne    c4
    call    sub_proc
    jmp    MENU

c4 :
    cmp    al,'4'
    jne    invalid
    exit

invalid :
   
    print    emsg,emsg_len
    jmp    MENU
 ;----------------------------------------------------------------------------------------------------




     6B.asm
   ....................



global    con_proc,sub_proc,str_name_len
extern    str1,str1_size,str2,str2_size,str1_len,str2_len

%include    "macro.asm"

;-------------------------------------------------------------------------------------------------------------------
;                    Data section
;-------------------------------------------------------------------------------------------------------------------

section     .data

;-------------------------------------------------------------------------------------------------------------------
;                    Output string msgs
;-------------------------------------------------------------------------------------------------------------------


    cmsg        db    10,10,"Concantinated String is : "
    cmsg_len    equ    $-cmsg

    ymsg     db 10,10,    "The substring is present "
        db 10,10,    "NO. of occurrance of substring in main string is:"
    ymsg_len     equ $-ymsg
    nmsg    db 10,10,    "The substring is not present ",10
    nmsg_len    equ $-nmsg   


;-------------------------------------------------------------------------------------------------------------------
;                    Output string msgs
;-------------------------------------------------------------------------------------------------------------------


    s11msg        db    10,10,"String1 is : "
    s11msg_len    equ    $-s11msg


    s22msg        db    10,10,"String2 is : "
    s22msg_len    equ    $-s22msg

;-------------------------------------------------------------------------------------------------------------------
;                    Output string length msgs
;-------------------------------------------------------------------------------------------------------------------

    s1msg        db    10,"And String1 length is : "
    s1msg_len    equ    $-s1msg

    s2msg        db    10,"And String2 length is : "
    s2msg_len    equ    $-s2msg

    s3msg        db    10,10,"And Concantinated String length is : "
    s3msg_len    equ    $-s3msg


;-------------------------------------------------------------------------------------------------------------------
;                    Extra msgs
;-------------------------------------------------------------------------------------------------------------------

    line1        db    10,10
    line1_len    equ    $-line1
;-------------------------------------------------------------------------------------------------------------------
;                    Bss section
;-------------------------------------------------------------------------------------------------------------------

section        .bss
   
   
    str3        resb    40
    str3_len    equ    $-str3
    str3_size    resw    1   
   
    ss_count    resw    1
    cur_addr    resq    1
    end_addr    resq    1
   

    char_ans    resb    4         ;16bit=4,8bit=2


;-------------------------------------------------------------------------------------------------------------------
;                    Text section
;-------------------------------------------------------------------------------------------------------------------

section        .text
    global main   

main:
   
str_name_len:
    print    s11msg,s11msg_len
    print    str1,str1_len
    print    s1msg,s1msg_len
   
    mov    rax,[str1_size]
    call    display_16

    print    s22msg,s22msg_len
    print    str2,str2_len
    print    s2msg,s2msg_len
   
    mov    rax,[str2_size]
    call    display_16
ret
con_proc:
    xor    rcx,rcx
    cld
    mov    rdi,str3
   
    mov    rsi,str1
    mov    cx,[str1_size]
    mov    [str3_size],cx

    rep    movsb

    mov    rsi,str2
    mov    cx,[str2_size]
    add    [str3_size],cx

    rep    movsb

    print    cmsg,cmsg_len
    xor    rdx,rdx
    mov    dx,[str3_size]
    print    str3,rdx

    print    s3msg,s3msg_len
    xor     rax,rax
    mov    rax,[str3_size]
    call    display_16
   

ret

 sub_proc :
   
    mov    word[ss_count],0
    mov    rsi,str1
    mov    [cur_addr],rsi
   
    xor    rcx,rcx

    mov    cx,[str1_size]
    add    rsi,rcx
    dec    rsi
    mov    [end_addr],rsi
    CLD
    mov    rsi,str1

back :
   
    mov    rdi,str2
    mov    cx,[str2_size]
    REPE    CMPSB
    jnz    next
    inc    word[ss_count]

next :
   
    inc    qword[cur_addr]
    mov    rsi,[cur_addr]
    cmp    rsi,[end_addr]
    jbe    back
    mov    ax,[ss_count]
    cmp    ax,0
    je    NO

    print    ymsg,ymsg_len
    jmp    final   

NO :    print    nmsg,nmsg_len
final :   
    mov    ax,[ss_count]
    call    display_16

RET

display_16:
    mov     rsi,char_ans+3           ;16 bit=3,8bit=1,32bit=7
    mov    rcx,4                    ;16 bit=4,32bit=8
    mov    rbx,16

next_digit1:
    xor    rdx,rdx
    div    rbx
    cmp    dl,09H
    jbe    add30
    add    dl,07H

add30:
    add    dl,30H
    mov    [rsi],dl
    dec    rsi
    dec    rcx
    jnz    next_digit1
    print    char_ans,4              ;16 bit=4,8bit=2 ,32bit=8
    print    line1,line1_len   
ret   


;---------------------------------------------------------------------------------------------------------------------------------
 




   macro.asm
   ....................



%macro         print     2

    mov rax,1      ;System call for print
    mov rdi,1      ;file standard output
    mov rsi,%1     ;address of message
    mov rdx,%2     ;maximum number of bytes to write
    syscall   
%endmacro


%macro         read     2

    mov rax,0    ;System call for read
    mov rdi,0    ;file standard input
    mov rsi,%1    ;address of message
    mov edx,%2    ;maximum number of bytes to read
    syscall
%endmacro


%macro         exit     0

    mov rax,60    ;System call for exit
    mov rdi,0    ;clear the contents
    syscall
%endmacro

;--------------------------------------------------------------------------------------------------------------
                                          output:

student@OS18:~/179$ nasm -f elf64 Ass6a.asm -o Ass6a.o
student@OS18:~/179$ nasm -f elf64 Ass6b.asm -o Ass6b.o
student@OS18:~/179$ ld -o Ass6aAss6b Ass6a.o Ass6b.o
student@OS18:~/179$ ./Ass6aAss6b


ASSINMENT NO. 6 :- CONCATENATION AND SUBSTRING PROGRAM USING FAR CALL

Enter a String1 sunil


Enter a String2 nil

1.     STRINGS NAME AND LENGHT
2.     STRING CONCATENATION
3.    NO. OF OCCURANCE OF SUBSTRING IN GIVEN STRING
4.    EXIT
Enter your choice
1


String1 is : sunil

And String1 length is : 0005



String2 is : nil

And String2 length is : 0003


1.     STRINGS NAME AND LENGHT
2.     STRING CONCATENATION
3.    NO. OF OCCURANCE OF SUBSTRING IN GIVEN STRING
4.    EXIT
Enter your choice
2


Concantinated String is : sunilnil

And Concantinated String length is : 0008


1.     STRINGS NAME AND LENGHT
2.     STRING CONCATENATION
3.    NO. OF OCCURANCE OF SUBSTRING IN GIVEN STRING
4.    EXIT
Enter your choice
3


The substring is present

NO. of occurrance of substring in main string is:0001


1.     STRINGS NAME AND LENGHT
2.     STRING CONCATENATION
3.    NO. OF OCCURANCE OF SUBSTRING IN GIVEN STRING
4.    EXIT
Enter your choice
4
student@OS18:~/179$ 

;---------------------------------------------------------------------------------------------------------------

                                                 Assignment 7


     1 ; Name            :Jadhav Sunil
     2 ; Roll no.         :SECOA175.
     3 ; Assignment no.        :7(a)
     4 ; Assignment name    :Square Wave.
     5 ;-----------------------------------------------------------------

     6                                  section    .text
     7                                      global _start
     8                                  _start:
     9 00000000 B080                        MOV    AL,80H    ;I/O Mode
    10 00000002 E667                        OUT    67H,AL;Control Word Address
    11                                     
    12 00000004 B001                        MOV    AL,01H    ;Enable Latching
                                               Through Port B 
    13 00000006 E663                        OUT    63H,AL    ;Port B Address
    14                                  Again:
    15 00000008 B000                        MOV    AL,00H
    16 0000000A E661                        OUT    61H,AL    ;Port A Address
    17                                     
    18 0000000C BEFF00                      MOV    SI,00FFH
    19                                  Delay:
    20 0000000F 4E                          DEC    SI
    21 00000010 75FD                        JNZ    Delay
    22                                     
    23 00000012 B0FF                        MOV    AL,0FFH
    24 00000014 E661                        OUT    61H,AL
    25                                     
    26 00000016 BEFF00                      MOV    SI,00FFH
    27                                  Delay_2:
    28 00000019 4E                          DEC    SI
    29 0000001A 75FD                        JNZ    Delay_2
    30                                     
    31 0000001C EBEA                        JMP    Again
    32 0000001E CC                      INT3   
;-----------------------------------------------------------
OUTPUT:
student@212c14:~$ nasm -f elf64 7a.asm -l 7a.lst

;-----------------------------------------------------------------------------------------

     1 ; Name   :Jadhav Sunil
     2 ; Roll no.   :SECOA175.
     3 ; Assignment no.  :7(B)
     4 ; Assignment name :FORWARD RAMP.
     5 ;--------------------------------------------------------------------- 
     6  section .text
     7    global _start
     8  _start:
     9 00000000 B080                      MOV AL,80H 
    10 00000002 E667                      OUT  67H,AL
    11 00000004 B001                      MOV AL,01H  ;ENABLE LATCH 
    12 00000006 E603                      OUT 03H,AL  ;USING PB0
    13                                   
    14 00000008 B000                      MOV AL,00H
    15 0000000A E661                    BACK: OUT 61H,AL
    16                                   
    17 0000000C FEC0                      INC AL
    18 0000000E EBFA                      JMP BACK
    19 00000010 CC                        INT3
    20                                   
    21;-----------------------------------------------------
     OUTPUT:
    student@212c14:~$ nasm -f elf64 7b.asm -l 7b.lst
;----------------------------------------------------------------------
 
     1 ; Name   :Jadhav Sunil
     2 ; Roll no.   :SECOA175.
     3 ; Assignment no.  :7(c)
     4 ; Assignment name :REVERSE RAMP.
     5 ;--------------------------------------------------------------------- 
     6 section .text
     7     global _start
     8  _start:
     9 00000000 B080                      MOV AL,80H 
    10 00000002 E667                      OUT 67H,AL
    11 00000004 B001                      MOV AL,01H  ;ENABLE LATCH 
    12 00000006 E603                      OUT 03H,AL  ;USING PB0
    13                                   
    14 00000008 B0FF                      MOV AL,0FFH
    15 0000000A E661                    BACK: OUT 61H,AL
    16                                   
    17 0000000C FEC8                      DEC AL
    18 0000000E EBFA                      JMP BACK
    19 00000010 CC                        INT3
    20                                   
    21                                     
   ; ----------------------------------------------------------
    OUTPUT:
     student@212c14:~$ nasm -f elf64 7c.asm -l 7c.lst
;---------------------------------------------------------- --------------------
 
     1 ; Name   :Jadhav Sunil
     2 ; Roll no.   :SECOA175.
     3 ; Assignment no.  :7(D)
     4 ;Assignment Name       :TRIANGULAR WAVE
     5 ;------------------------------------------------------------
     6 section .text
     7   global _start
     8 _start:
     9 00000000 B080                      MOV AL,80H 
    10 00000002 E667                      OUT 67H,AL
    11 00000004 B001                      MOV AL,01H  ;ENABLE LATCH 
    12 00000006 E603                      OUT 03H,AL  ;USING PB0
    13                                   
    14 00000008 B000                      MOV AL,00H
    15                                  BACK: 
    16 0000000A E661                      OUT 61H,AL
    17 0000000C FEC0                           INC AL
    18 0000000E 3CFF                           CMP AL,0FFH
    19 00000010 72F8                           JB BACK 
    20                                  BACK1:    
    21 00000012 E661                           OUT 61H,AL
    22 00000014 FEC8                           DEC AL
    23 00000016 3C00                           CMP AL,00H
    24 00000018 77F8                           JA BACK1
    25                                       
    26 0000001A EBEE                      JMP BACK
    27 0000001C CC                        INT3
    28                                   
    29 
;-------------------------------------------------------------------  
OUTPUT:

student@212c14:~$ nasm -f elf64 -l 7D.lst 7D.asm 
;---------------------------------------------------------------------
     1 ; Name   :Jadhav Sunil
     2 ; Roll no.   :SECOA175.
     3 ; Assignment no.  :7E
     4 ;Assignment Name       :TRAPEZOIDAL WAVE
     5 ;------------------------------------------------------------
     6 section .text
     7   global _start
     8 _start:

     9 00000000 B080                      MOV AL,80H 
    10 00000002 E667                      OUT 67H,AL
    11 00000004 B001                      MOV AL,01H  ;ENABLE LATCH 
    12 00000006 E663                      OUT 63H,AL  ;USING PB0
    13                                   
    14 00000008 B000                      MOV AL,00H
    15                                  BACK: 
    16 0000000A E661                      OUT 61H,AL
    17 0000000C FEC0                           INC AL
    18 0000000E 3CFF                           CMP AL,0FFH
    19 00000010 72F8                           JB BACK 
    20                                      
    21 00000012 B0FF                           MOV AL,0FFH
    22 00000014 FEC8                    Delay:  DEC AL
    23 00000016 75FC                           JNZ Delay
    24                                      
    25                                  BACK1:    
    26 00000018 E661                           OUT 61H,AL
    27 0000001A FEC8                           DEC AL
    28 0000001C 3C00                           CMP AL,00H
    29 0000001E 77F8                           JA BACK1
    30                                   
    31 00000020 B0FF                            MOV AL,0FFH
    32 00000022 FEC8                    Delay_1:DEC AL
    33 00000024 75FC                        JNZ Delay_1  
    34                                        
    35 00000026 EBE2                      JMP BACK
    36 00000028 CC                        INT3
    37                                   
    38;--------------------------------------------------- 
OUTPUT:

student@212c14:~$ nasm -f elf64 -l 7E.lst 7E.asm 
;---------------------------------------------------------------------     
      ; Name   :Jadhav Sunil
      ; Roll no.   :SECOA175.
      ; Assignment no.  :7E
      ;Assignment Name       :Stair Case WAVE
      ;------------------------------------------------------------ 
     1                                       section    .text
     2                                                                            global _start
     3                                                                        _start:
     4 00000000 B080                                                   MOV    AL,80H    ;I/O Mode
     5 00000002 E667                                                   OUT    67H,AL;Control Word Address
     6                                                                           
     7 00000004 B001                                                   MOV    AL,01H    ;Enable Latching Through Port B 
     8 00000006 E663                                                   OUT    63H,AL    ;Port B Address
     9                                                               
    10 00000008 B000                                                   MOV    AL,00H
    11 0000000A E661                                              Back:  OUT    61H,AL    ;Port A Address
    12                                                                           
    13 0000000C 66B9FF00                                             MOV    CX,00FFH
    14 00000010 66FFC9                                             Delay: DEC    CX
    15 00000013 75FB                                                  JNZ    Delay
    16                                                                           
    17 00000015 0455                                                 ADD   AL,055H
    18 00000017 3CFF                          CMP   AL,00FFH
    19 00000019 72EF                           JB     Back 
    20 0000001B E661                                             Back1: OUT    61H,AL
    21                                                                           
    22 0000001D 66B9FF00                                             MOV    CX,00FFH
    23 00000021 66FFC9                                            Delay_2:DEC    CX
    24 00000024 75FB                                                 JNZ    Delay_2
    25                                                                            
    26 00000026 2C55                          SUB   AL,055H
    27 00000028 3C00                          CMP   AL,00H
    28 0000002A 77EF                           JA     Back1  
    29 0000002C EBDC                                                  JMP    Back
    30 0000002E CC                                            INT3   
    
 
    ;--------------------------------------------------- 
OUTPUT:

student@212c14:~$ nasm -f elf64 -l 7f.lst 7f.asm   
;---------------------------------------------------------------------------------------------------------------------------------------------

Assignment No. :8(A) 
Name   :Jadhav Sunil
Roll No.  :SECOA179
Assignment Name :8a.asm - for counter 0 mode 0
_________________________________________________________________________________                          
                                      
                                        section .text
                                          global _start
                                         _start :
                                       
     00000000 B071                     mov al,71h  ;select mode 0
     00000002 E633                     out 33h,al  ;out to CWR
                                      
     00000004 B005                     mov al,05h  ;counter for LSB
     00000006 E630                     out 30h,al  ;send to counter 0
                                      
     00000008 B000                     mov al,00h  ;counter for MSB
     0000000A E630                     out 30h,al  ;send to counter 0
                                      
     0000000C CC                       int3    
________________________________________________________________________________            
Output: 
student@OS17:~/Desktop/Assignment 8$ nasm 8a.asm -l 8a.lst
student@OS17:~/Desktop/Assignment 8$ 

;---------------------------------------------------------------------------------------------------------------------------------------------
Assignment No. :8(B) 
Name   :Sunil Jadhav
Roll No.  :SECOA179
Assignment Name :8b.asm - for counter 0 mode 1
_________________________________________________________________________________                          
                                section .text
                                         global _start
             _start :
                                       
     00000000 B033                     mov al,33h  ;select mode 1
     00000002 E633                     out 33h,al  ;out to CWR
                                      
     00000004 B005                     mov al,05h  ;counter for LSB
     00000006 E630                     out 30h,al  ;send to counter 0
                                      
     00000008 B000                     mov al,00h  ;counter for MSB
     0000000A E630                     out 30h,al  ;send to counter 0
                                      
     0000000C CC                       int3 
________________________________________________________________________________            
Output: 
student@OS17:~/Desktop/kaushalAssignment 8$ nasm 8b.asm -l 8b.lst
student@OS17:~/Desktop/kaushal/Assignment 8$ 

;----------------------------------------------------------------------------------------------------------------------------------------------
Assignment No. :8(C) 
Name   :Jadhav Sunil
Roll No.  :SECOA179
Assignment Name :8c.asm - for counter 0 mode 2
_________________________________________________________________________________                          
                                   section .text
                                       global _start
                                 _start :
                                      
     00000000 B035                     mov al,35h  ;select mode 2
     00000002 E633                     out 33h,al  ;out to CWR
                                      
     00000004 B005                     mov al,05h  ;counter for LSB
     00000006 E630                     out 30h,al  ;send to counter 0
                                      
     00000008 B000                     mov al,00h  ;counter for MSB
     0000000A E630                     out 30h,al  ;send to counter 0
                                      
     0000000C CC                       int3
________________________________________________________________________________            
Output: 
student@OS17:~/Desktop/Assignment 8$ nasm 8c.asm -l 8c.lst
student@OS17:~/Desktop/Assignment 8$ 


;-----------------------------------------------------------------------------------------------------------------------------------------------
Assignment No. :8(D) 
Name   :Jadhav Sunil
Roll No.  :SECOA179
Assignment Name :8d.asm - for counter 0 mode 3
_________________________________________________________________________________                               
                                   section .text
                                             global _start
                                        _start :
                                      
     00000000 B037                     mov al,37h  ;select mode 3
     00000002 E633                     out 33h,al  ;out to CWR
                                      
     00000004 B005                     mov al,05h  ;counter for LSB
     00000006 E630                     out 30h,al  ;send to counter 0
                                      
     00000008 B000                     mov al,00h  ;counter for MSB
     0000000A E630                     out 30h,al  ;send to counter 0
                                      
     0000000C CC                       int3
________________________________________________________________________________            
Output: 
student@OS17:~/Desktop/Assignment 8$ nasm 8d.asm -l 8d.lst
student@OS17:~/Desktop/Assignment 8$ 

;-----------------------------------------------------------------------------------------------------------------------------------------------
Assignment No. :8(e) 
Name   :Jadhav Sunil
Roll No.  :SECOA179
Assignment Name :8e.asm - for counter 0 mode 4
_________________________________________________________________________________                               
           section .text
                                                     global _start
                                            _start :
                                      
     00000000 B039                     mov al,39h  ;select mode 4
     00000002 E633                     out 33h,al  ;out to CWR
                                      
     00000004 B005                     mov al,05h  ;counter for LSB
     00000006 E630                     out 30h,al  ;send to counter 0
                                      
     00000008 B000                     mov al,00h  ;counter for MSB
     0000000A E630                     out 30h,al  ;send to counter 0
                                      
     0000000C CC                       int3
________________________________________________________________________________            
Output: 
student@OS17:~/Desktop/Assignment 8$ nasm 8e.asm -l 8e.lst
student@OS17:~/Desktop/Assignment 8$ 
;------------------------------------------------------------------------------------------------------------------------------------------
Assignment No. :8(F) 
Name   :Jadhav Sunil
Roll No.  :SECOA179
Assignment Name :8f.asm - for counter 0 mode 5_________________________________________________________________________________                               
           section .text
                                                     global _start
                                            _start :
                                      
     00000000 B03B                     mov al,3Bh ;select mode 5
     00000002 E633                     out 33h,al ;out to CWR
                                      
     00000004 B005                     mov al,05h ;counter for LSB
     00000006 E630                     out 30h,al ;send to counter 0
                                      
     00000008 B000                     mov al,00h ;counter for MSB
     0000000A E630                     out 30h,al ;send to counter 0
                                      
     0000000C CC                       int3
________________________________________________________________________________            
Output: 
student@OS17:~/Desktop/kaushalAssignment 8$ nasm 8f.asm -l 8f.lst
student@OS17:~/Desktop/kaushal/Assignment 8$ 
;------------------------------------------------------------------------------ ; Name   :Jadhav Sunil 
; Roll no.    :SECOA179
; Assignment no.  :9(a) 
; Assignment name :ALP to initialize 8279 & display  character in left and  right entry.
;--------------------------------------------------------------------------------------------------------------------                               
    section .text
                  global _start
                       _start:
   00000000 8CC8             MOV AX,CS          ;Init data segment
    00000002 8ED8             MOV DS,AX
                                     
    00000004 B001             MOV AL,01H  ;left entry
    00000006 E631             OUT 31H,AL  ;8-bit,initialize in 
        particular mode
                                     
    00000008 B090             MOV AL,90H  ;to write into 
        display ram
    0000000A E631             OUT 31H,AL
                                     
    0000000C B90400           MOV CX,04
    0000000F BB0020           MOV BX,2000H
                                     
                      NEXT_CHAR:
    00000012 8A07             MOV AL,[BX]  ;store it in 30H data 
        addr reg
    00000014 E630             OUT 30H,AL
                                       
    00000016 BEFFFF           MOV SI,0FFFFH ;DELAY CODE
    00000019 4E       DELAY:  DEC SI
    0000001A 75FD             JNZ DELAY
                                     
    0000001C 43               INC BX
                                      
    0000001D 49               DEC CX
    0000001E 75F2             JNZ NEXT_CHAR
                                      
    00000020 CC                INT3


;----------------------***OUTPUT***------------------------


student@ $ nasm -f elf64 9a.asm -l 9a.lst

;------------------------***END***------------------------- 
;--------------------------------------------------------------------------------- 
; Name   :Jadhav Sunil 
; Roll no.    :SECOA179
; Assignment no.  :9(b) 
; Assignment name  :ALP to initialize 8279 & display 
     character in left and  right entry. ;--------------------------------------------------------------------------------------------------------------------               
  section .text
               global _start
                    _start:
 0000000 8CC8            MOV AX,CS        ;Initialize DS
 00000002 8ED8            MOV DS,AX
                                  
 00000004 B011            MOV AL,11H  ;right entry
 00000006 E631            OUT 31H,AL  ;8-bit,initiaalize 
        in particular mode
                                  
 00000008 B090            MOV AL,90H  ;to write into 
        display ram
 0000000A E631            OUT 31H,AL
                                  
 0000000C B90400          MOV CX,04
 0000000F BB0020          MOV BX,2000H
                                  
                    NEXT_CHAR:
 00000012 8A07            MOV AL,[BX]  ;store it in 30H 
        data addr reg
 00000014 E630            OUT 30H,AL
    
 00000016 BEFFFF          MOV SI,0FFFFH 
 00000019 4E        DELAY: DEC SI
 0000001A 75FD            JNZ DELAY
                                  
 0000001C 43              INC BX
                                   
 0000001D 49              DEC CX
 0000001E 75F2            JNZ NEXT_CHAR
                                   
 00000020 CC              INT3


;----------------------***OUTPUT***------------------------


student@ $ nasm -f elf64 9b.asm -l 9b.lst


;------------------------***END***-------------------------

;--------------------------------------------------------------------------------- 

; Name :Jadhav Sunil
; Roll no. :SECOA179
; Assignment no. :9(c)
; Assignment name :ALP to initialize 8279 & display
character in left and right entry.
;-----------------------------------------------------------------------------------------------------------------
section .text
global _start
_start:
0000000 8CC8 MOV AX,CS ;Initialize DS
00000002 8ED8 MOV DS,AX
00000004 B001 MOV AL,01H ;left entry
00000006 E631 OUT 31H,AL ;8-bit,initialize in
paular mode
00000008 B090 MOV AL,90H ;to write into
display ram
0000000A E631 OUT 31H,AL
AGAIN:
0000000C B90600 MOV CX,06
0000000F BB0020 MOV BX,2000H
NEXT_CHAR:
00000012 8A07 MOV AL,[BX] ;store it in 30H
data addr reg
00000014 E630 OUT 30H,AL
00000016 BEFFFF MOV SI,0FFFFH ;DELAY CODE
00000019 4E DELAY:DEC SI
0000001A 75FD JNZ DELAY
0000001C 43 INC BX
0000001D 49 DEC CX
0000001E 75F2 JNZ NEXT_CHAR
00000020 EBEA JMP AGAIN
00000022 CC INT3




;----------------------***OUTPUT***------------------------
student@ $ nasm -f elf64 9c.asm -l 9c.lst
;------------------------***END***-------------------------
  
;--------------------------------------------------------------------------------- 
; Name :Jadhav Sunil
; Roll no. :SECOA179
; Assignment no. :9(d)
;Assignment name :ALP to initialize 8279 & display
character in left and right entry.
;-----------------------------------------------------------------------------------------------------------------
section .text
global _start
_start:
0000000 8CC8 MOV AX,CS ;Initialize DS
00000002 8ED8 MOV DS,AX
00000004 B011 MOV AL,11H ;right entry
00000006 E631 OUT 31H,AL ;8-bit,initialize in
particular mode
00000008 B090 MOV AL,90H ;to write into
di ram
0000000A E631 OUT 31H,AL
AGAIN:
0000000C B90600 MOV CX,06
0000000F BB0020 MOV BX,2000H
NEXT_CHAR:
00000012 8A07 MOV AL,[BX] ;store it in
30H data addr reg
00000014 E630 OUT 30H,AL
00000016 BEFFFF MOV SI,0FFFFH ;DELAY CODE


00000019 4E DELAY: DEC SI
0000001A 75FD JNZ DELAY
0000001C 43 INC BX
0000001D 49 DEC CX
0000001E 75F2 JNZ NEXT_CHAR
00000020 EBEA JMP AGAIN
00000022 CC INT3


;----------------------***OUTPUT***------------------------
student@ $ nasm -f elf64 9d.asm -l 9d.lst
;------------------------***END***-------------------------
 
;---------------------------------------------------------------------------------- 
; Name :Jadhav Sunil
;Roll no.    :SECOA179 
;Assignment name  :Analogto digital convertor 
;Assignment no.  :10 
;-----------------------------------------------------------------------------------------------------------------
                                
section .text
global _start
_start :
00000000 8CC8 mov ax,cs ;initialize cs with ds
00000002 8ED8 mov ds,ax ;initialize cs with ds
00000004 B099 mov al,99h ;set port A & C as input
00000006 E667 out 67h,al ;set port B as output
00000008 B005 mov al,05h ;enable oscillator
0000000A E663 out 63h,al ;using port B
0000000C B004 mov al,04h ;send SOC low
0000000E E663 out 63h,al ;to PB0
back :
00000010 E465 in al,65h ;load PC0 in al
00000012 A801 test al,01h ;check for EOC=1
00000014 74FA jz back
00000016 B006 mov al,06h ;if EOC=1
00000018 E461 in al,61h ;then read digital data in port A
0000001A BB0030 mov bx,3000h ;store at address 3000h
0000001D 8807 mov [bx],al ;load the al contents to3000h
0000001F CC int3 ;stop
_____________________________________________________________________________________
Output:
student@OS17:~/Desktop/Assignment 10$ nasm 10.asm -l 10.lst
student@OS17:~/Desktop/Assignment 10$
;------------------------------------------------------------------------------
 
Assignment No.         :12
Name   :Jadhav  Sunil.
Roll No.  :SECOA179
TITLE                   : Write a TSR program in 8086 ALP to implement Real Time Clock (RTC).
 Read the Real Time from CMOS chip by suitable INT and FUNCTION and display the RTC at the bottom right corner on the screen.
 Access the video RAM directly in your routine.

        
 ;--------------------------------------------------------------------------------------------
CODE SEGMENT
 ASSUME CS:CODE,DS:CODE

MAIN : JMP INIT
       OLD_ADD DD ?
       NO DB 0

OUR_ISR: PUSH AX
        PUSH BX
        PUSH CX
        PUSH DX
        PUSH DS
        PUSH SS
        PUSH ES
        PUSH DI
        PUSH SI

        MOV AX,CS
        MOV DS,AX

        MOV AH,02 
        INT 1AH

        MOV AX,0B800H
        MOV ES,AX
        MOV SI,400

        MOV NO,CH
        CALL DISPLAY
        CALL COLON
        MOV NO,CL
        CALL DISPLAY
        CALL COLON
        MOV NO,DH
        CALL DISPLAY

        POP SI
        POP DI
        POP ES
        POP SS
        POP DS
        POP DX
        POP CX
        POP BX
        POP AX
     JMP CS:OLD_ADD

DISPLAY PROC
    PUSH AX
    PUSH BX
    PUSH CX
    PUSH DX

    MOV CH,2
    MOV BL,NO

DISP:  MOV CL,4
       ROR BL,CL
       MOV AL,BL
       AND AL,0FH
       ADD AL,30H
       MOV  ES:[SI],AL
       INC SI
       MOV AL,10100001B
       MOV ES:[SI],AL
       INC SI
       DEC CH
       JNZ DISP
       POP DX
       POP CX
       POP BX
       POP AX
       RET
       DISPLAY ENDP

COLON PROC
        MOV AL,':'
        MOV ES:[SI],AL
        INC SI
        MOV AL,10010011B
        MOV ES:[SI],AL
        INC SI
        RET
        COLON ENDP

INIT: CLI
        MOV AX,CS
        MOV DS,AX

        MOV AH,35H
        MOV AL,8
        INT 21H

MOV WORD PTR OLD_ADD+2,ES
MOV WORD PTR OLD_ADD,BX

        MOV AH,25H
        MOV AL,8
        LEA DX,OUR_ISR
        INT 21H

        MOV AH,31H
        MOV AL,1
        LEA DX,INIT
        INT 21H
        STI
        CODE ENDS
        END MAIN

  
;----------------------------------------------------------------------------------------------------------------------------
Assignment No. :13
Name   :Jadhav  Sunil.
Roll No.  :SECOA179
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.----------------------------------------------------------------------------------------------------------------------------
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===================================
student@:~$ cd Desktop/
student@:~/Desktop$ nasm -f elf64 13.asm -o 13.o
student@:~/Desktop$ ld -o 13 13.o
student@:~/Desktop$ ./13

***WELCOME TO 64 BIT PROGRAMMING***
CALCULATED MEAN IS:-000000000000000130.30
CALCULATED STANDARD DEVIATION IS:-000000000000000072.32
CALCULATED VARIANCE IS:-000000000000005219.39

student@:~/Desktop/se55$