PROGRAM 1: section .data msg db "Enter a String:", 0ah msg_len equ $-msg %macro print 2 mov rax, 1 mov rdi, 1 mov rsi, %1 mov rdx, %2 syscall %endmacro %macro write 2 mov rax, 0 mov rdi, 0 mov rsi, %1 mov rdx, %2 syscall %endmacro %macro exit 0 mov rax, 60 mov rdi, 0 syscall %endmacro section .bss str1 resb 200 section .text global _start _start: print msg,msg_len write str1,200 print str1,200 exit OUTPUT: $ cd ~/Downloads $ nasm -f elf64 ass1.asm $ ld -o ass1 ass1.o $ ./ass1 Enter a String: Hello World Hello World PROGRAM 2: section .data msg1 db 10,13,"Enter 5 64 bit numbers" len1 equ $-msg1 msg2 db 10,13,"Entered 5 64 bit numbers" len2 equ $-msg2 section .bss array resd 200 counter resb 1 section .text global _start _start: ;display mov Rax,1 mov Rdi,1 mov Rsi,msg1 mov Rdx,len1 syscall ;accept mov byte[counter],05 mov rbx,00 loop1: mov rax,0 ; 0 for read mov rdi,0 ; 0 for keyboard mov rsi, array ;move pointer to start of array add rsi,rbx mov rdx,17 syscall add rbx,17 ;to move counter dec byte[counter] JNZ loop1 ;display mov Rax,1 mov Rdi,1 mov Rsi,msg2 mov Rdx,len2 syscall ;display mov byte[counter],05 mov rbx,00 loop2: mov rax,1 ;1 for write mov rdi, 1 ;1 for monitor mov rsi, array add rsi,rbx mov rdx,17 ;16 bit +1 for enter syscall add rbx,17 dec byte[counter] JNZ loop2 ;exit system call mov rax ,60 mov rdi,0 syscall OUTPUT: $ cd ~/Downloads $ nasm -f elf64 ass1.asm $ ld -o ass1 ass1.o $ ./ass1 Enter 5 64 bit numbers 42 18 59 36 53 Entered 5 64 bit numbers 42 18 59 36 53 PROGRAM 3: section .data msg1 db 10,13,"Enter a string:" len1 equ $-msg1 %macro dispmsg 2 mov Rax,1 mov Rdi,1 mov Rsi,%1 mov Rdx,%2 syscall %endmacro %macro write 2 mov rax,0 mov rdi,0 mov rsi,%1 mov rdx,%2 syscall %endmacro %macro exit 0 mov Rax ,60 mov Rdi,0 syscall %endmacro section .bss str1 resb 200 result resb 16 section .text global _start _start: ;display dispmsg msg1,len1 ;store string write str1,200 call display ;exit system call exit ;string declaration display: mov rbx,rax mov rdi,result mov cx,16 ; store no in rbx ;point rdi to result variable ;load count of rotation in cl up1: rol rbx,04 mov al,bl and al,0fh cmp al,09h jg add_37 add al,30h jmp skip ;rotate no of left by four bits ; move lower byte in al ;get only LSB ;compare with 39h ;if greater than 39h skip add 37 ;else add 30 add_37: add al,37h skip: mov [rdi],al ;store ascii code in result variable inc rdi ; point to next byte dec cx ; decrement counter jnz up1 ; if not zero jump to repeat dispmsg result,16 ;call to macro ret OUTPUT: $ cd ~/Downloads $ nasm -f elf64 ass2.asm $ ld -o ass2 ass2.o $ ./ass2 Enter a string: Hello World 11 PROGRAM 4: section .data menumsgdb 10,'****** Menu ******', db 10,'+: Addition' db 10,'-: Subtraction' db 10,'*: Multiplication' db 10,'/: Division' db 10,10,'Enter your choice:: ' menumsg_len: equ $-menumsg addmsgdb 10,'Welcome to additon',10 addmsg_lenequ $-addmsg submsgdb 10,'Welcome to subtraction',10 submsg_lenequ $-submsg mulmsgdb 10,'Welcome to Multiplication',10 mulmsg_lenequ $-mulmsg divmsgdb 10,'Welcome to Division',10 divmsg_lenequ $-divmsg wrchmsgdb 10,10,'Wrong CHoice Entered...!',10 wrchmsg_lenequ $-wrchmsg no1 dq 0ff05h no2 dq 0ffh resmsgdb 10,'Result is:' resmsg_lenequ $-resmsg qmsgdb 10,'Quotient::' qmsg_lenequ $-qmsg rmsgdb 10,'Remainder::' rmsg_lenequ $-rmsg nwmsgdb 10 reshdq 0 resldq 0 section .bss accbuffresb 2 dispbuffresb 16 %macro print 2 moveax, 4 movebx, 1 movecx, %1 movedx, %2 int 80h %endmacro section .text global _start start: print menumsg,menumsg_len mov eax,03 mov ebx,01 movecx,accbuff mov edx,02 int 80h cmp byte [accbuff],'+' jne case2 call add_proc jmp exit case2: cmp byte [accbuff],'-' jne case3 call sub_proc jmp exit case3: cmp byte [accbuff],'*' jne case4 call mul_proc jmp exit case4: cmp byte [accbuff],'/' jnecaseinv call div_proc jmp exit caseinv:printwrchmsg,wrchmsg_len exit: mov eax,01 mov ebx,0 int 80h add_proc: print addmsg,addmsg_len movrax,[no1] add rax,[no2] jnc addnxt1 inc qword [resh] addnxt1: mov [resl],rax print resmsg,resmsg_len movrbx,[resh] call disp64num movrbx,[resl] call disp64num print nwmsg,1 ret sub_proc: print submsg,submsg_len movrax,[no1] sub rax,[no2] jnc addnxt1 inc qword [resh] subnxt1: mov [resl],rax print resmsg,resmsg_len movrbx,[resh] call disp64num movrbx,[resl] call disp64num print nwmsg,1 ret mul_proc: print mulmsg,mulmsg_len movrax,[no1] movrbx,[no2] mulrbx mov [resh],rdx mov [resl],rax print resmsg,resmsg_len movrbx,[resh] call disp64num movrbx,[resl] call disp64num print nwmsg,1 ret div_proc: print divmsg,divmsg_len movrax,[no1] mov rdx,0 movrbx,[no2] div rbx mov [resh],rdx ;Remainder mov [resl],rax ;Quotient print rmsg,rmsg_len movrbx,[resh] call disp64num print qmsg,qmsg_len movrbx,[resl] call disp64num print nwmsg,1 ret disp64num: mov ecx,16 movedi,dispbuff dup1: rol rbx,4 moval,bl and al,0fh cmp al,09 jbedskip add al,07h dskip: add al,30h mov [edi],al incedi loop dup1 print dispbuff,16 ret OUTPUT: $ nasm -f elf64 msmalsw.asm $ ld -o msmalswmsmalsw.o $ ./msmalsw ****** Menu ****** +: Addition -: Subtraction *: Multiplication /: Division Enter your choice:: + Welcome to addition Result is:00000000000000000000000000010004 $ ./msmalsw ****** Menu ****** +: Addition -: Subtraction *: Multiplication /: Division Enter your choice:: - Welcome to subtraction Result is:0000000000000000000000000000FE06 $ ./msmalsw ****** Menu ****** +: Addition -: Subtraction *: Multiplication /: Division Enter your choice:: * Welcome to Multiplication Result is:00000000000000000000000000FE05FB $ ./msmalsw ****** Menu ****** +: Addition -: Subtraction *: Multiplication /: Division Enter your choice:: / Welcome to Division Remainder::0000000000000005 Quotient::0000000000000100 PROGRAM 5: section .data welmsg db 10,'Count positive and negative numbers in an array',10 welmsg_len equ $-welmsg arr64 dq -53H,36H,-15H,94H,25H n equ 5 pmsg db 10,"The no of Positive elements from 64-bit array :" pmsg_len equ $-pmsg nmsg db 10,"The no of Negative elements from 64-bit array :" nmsg_len equ $-nmsg section .bss p_count resq 1 n_count resq 1 char_ans resb 2 %macro print 2 mov rax, 1 mov rdi, 1 mov rsi, %1 mov rdx, %2 syscall %endmacro %macro read 2 mov rax, 0 mov rdi, 0 mov rsi, %1 mov rdx, %2 syscall %endmacro %macro exit 0 mov rax, 60 mov rdi, 0 syscall %endmacro section .text global _start _start: print welmsg,welmsg_len mov rsi,arr64 mov rcx,n mov rbx,0 mov rdx,0 next_num: mov rax,[rsi] shl rax,1 jc negative positive: inc rbx jmp next negative: inc rdx jmp next next: add rsi,8 dec rcx jnz next_num mov [p_count],rbx mov [n_count],rdx print pmsg,pmsg_len mov rax,[p_count] call disp64_proc print nmsg,nmsg_len mov rax,[n_count] call disp64_proc exit disp64_proc: mov rbx,16 mov rcx,2 mov rsi,char_ans+1 cnt: mov rdx,0 div rbx cmp dl,09h jbe add30 add dl,07h add30: add dl,30h mov [rsi],dl dec rsi dec rcx jnz cnt print char_ans,2 ret OUTPUT: $ cd ~/Downloads $ nasm -f elf64 ass5.asm $ ld -o ass5 ass5.o $ ./ass5 Count positive and negative numbers in an array The no of Positive elements from 64-bit array :03 The no of Negative elements from 64-bit array :02 PROGRAM 6: section .data array db 10h,20h,30h,40h,50h msg1: db 'Before overlapped :',0xa len1: equ $-msg1 msg2: db 'After overlapped :',0xa len2: equ $-msg2 msg3: db ' ',0xa len3: equ $-msg3 msg4: db ' : ' len4: equ $-msg4 count db 0 count1 db 0 count2 db 0 count3 db 0 count4 db 0 section .bss addr resb 16 num1 resb 2 section .text global _start _start: mov rax,1 mov rdi,1 mov rsi,msg1 mov rdx,len1 syscall xor rsi,rsi mov rsi,array mov byte[count],05 up: mov rbx,rsi push rsi mov rdi,addr call HtoA1 pop rsi mov dl,[rsi] push rsi mov rdi,num1 call HtoA2 pop rsi inc rsi dec byte[count] jnz up mov rsi,array mov rdi,array+5h mov byte[count3],05h loop10: mov dl,00h mov dl,byte[rsi] mov byte[rdi],dl inc rsi inc rdi dec byte[count3] jnz loop10 mov rax,1 mov rdi,1 mov rsi,msg2 mov rdx,len2 syscall mov rsi,array mov byte[count4],0Ah up10: mov rbx,rsi push rsi mov rdi,addr call HtoA1 pop rsi mov dl,[rsi] push rsi mov rdi,num1 call HtoA2 pop rsi inc rsi dec byte[count4] jnz up10 mov rax,60 mov rdi,0 syscall HtoA1: mov byte[count1],16 dup1: rol rbx,4 mov al,bl and al,0fh cmp al,09 jg p3 add al,30h jmp p4 p3: add al,37h p4:mov [rdi],al inc rdi dec byte[count1] jnz dup1 mov rax,1 mov rdi,1 mov rsi,addr mov rdx,16 syscall mov rax,1 mov rdi,1 mov rsi,msg4 mov rdx,len4 syscall ret HtoA2: mov byte[count2],02 dup2: rol dl,04 mov al,dl and al,0fh cmp al,09h jg p31 add al,30h jmp p41 p31: add al,37h p41:mov [rdi],al inc rdi dec byte[count2] jnz dup2 mov rax,1 mov rdi,1 mov rsi,num1 mov rdx,02 syscall mov rax,1 mov rdi,1 mov rsi,msg3 mov rdx,len3 syscall ret OUTPUT: $ nasm -f elf64 nonover_string.asm $ ld -o nonover_string nonover_string.o $ ./nonover_string Before overlapped : 0000000000600270 : 10 0000000000600271 : 20 0000000000600272 : 30 0000000000600273 : 40 0000000000600274 : 50 After overlapped : 0000000000600270 : 10 0000000000600271 : 20 0000000000600272 : 30 0000000000600273 : 40 0000000000600274 : 50 0000000000600275 : 10 0000000000600276 : 20 0000000000600277 : 30 0000000000600278 : 40 0000000000600279 : 50 PROGRAM 7: section .data array db 10h,20h,30h,40h,50h msg1: db 'Before overlapped :',0xa len1: equ $-msg1 msg2: db 'After overlapped :',0xa len2: equ $-msg2 msg3: db ' ',0xa len3: equ $-msg3 msg4: db ' : ' len4: equ $-msg4 count db 0 count1 db 0 count2 db 0 count3 db 0 count4 db 0 count5 db 0 section .bss addr resb 16 num1 resb 2 section .text global _start _start: mov rax,1 mov rdi,1 mov rsi,msg1 mov rdx,len1 syscall xor rsi,rsi mov rsi,array mov byte[count],05 up: mov rbx,rsi push rsi mov rdi,addr call HtoA1 pop rsi mov dl,[rsi] push rsi mov rdi,num1 call HtoA2 pop rsi inc rsi dec byte[count] jnz up mov rsi,array mov rdi,array+0Ah mov byte[count3],05h loop10: mov dl,00h movsb dec byte[count3] jnz loop10 xor rsi,rsi mov rsi,array+3h mov rdi,array+0Ah mov byte[count5],05h loop11: mov dl,byte[rdi] mov byte[rsi],dl inc rsi inc rdi dec byte[count5] jnz loop11 mov rax,1 mov rdi,1 mov rsi,msg2 mov rdx,len2 syscall xor rsi,rsi mov rsi,array mov byte[count4],08h up10: mov rbx,rsi push rsi mov rdi,addr call HtoA1 pop rsi mov dl,[rsi] push rsi mov rdi,num1 call HtoA2 pop rsi inc rsi dec byte[count4] jnz up10 mov rax,60 mov rdi,0 syscall HtoA1: mov byte[count1],16 dup1: rol rbx,4 mov al,bl and al,0fh cmp al,09 jg p3 add al,30h jmp p4 p3: add al,37h p4:mov [rdi],al inc rdi dec byte[count1] jnz dup1 mov rax,1 mov rdi,1 mov rsi,addr mov rdx,16 syscall mov rax,1 mov rdi,1 mov rsi,msg4 mov rdx,len4 syscall ret HtoA2: mov byte[count2],02 dup2: rol dl,04 mov al,dl and al,0fh cmp al,09h jg p31 add al,30h jmp p41 p31: add al,37h p41:mov [rdi],al inc rdi dec byte[count2] jnz dup2 mov rax,1 mov rdi,1 mov rsi,num1 mov rdx,02 syscall mov rax,1 mov rdi,1 mov rsi,msg3 mov rdx,len3 syscall ret OUTPUT: $ nasm -f elf64 wt_over.asm $ ld -o wt_over wt_over.o $ ./wt_over Before overlapped : 000000000060029C : 10 000000000060029D : 20 000000000060029E : 30 000000000060029F : 40 00000000006002A0 : 50 After overlapped : 000000000060029C : 10 000000000060029D : 20 000000000060029E : 30 000000000060029F : 10 00000000006002A0 : 20 00000000006002A1 : 30 00000000006002A2 : 40 00000000006002A3 : 50 PROGRAM 8: section .data msg db 'Enter two digit Number::',0xa msg_len equ $-msg res db 10,'Multiplication of elements is::' res_len equ $-res choice db 'Enter your Choice:',0xa db'1.Successive Addition',0xa db '2.Add and Shift method',0xa db '3.Exit',0xa choice_len equ $-choice section .bss num resb 03 num1 resb 01 result resb 04 cho resb 2 section .text global _start _start: xor rax,rax xor rbx,rbx xor rcx,rcx xor rdx,rdx mov byte[result],0 mov byte[num],0 mov byte[num1],0 mov rax,1 mov rdi,1 mov rsi,choice mov rdx,choice_len syscall mov rax,0 mov rdi,0 mov rsi,cho mov rdx,2 syscall cmp byte[cho],31h ;; comparing choice je a cmp byte[cho],32h je b jmp exit a: call Succe_addition jmp _start b: call Add_shift jmp _start exit: mov rax,60 mov rdi,0 syscall convert: xor rbx,rbx xor rcx,rcx xor rax,rax ;; ASCII to Hex conversion mov rcx,02 mov rsi,num up1: rol bl,04 mov al,[rsi] cmp al,39h jbe p1 sub al,07h jmp p2 p1: sub al,30h p2: add bl,al inc rsi loop up1 ret display: mov rcx,4 mov rdi,result dup1: rol bx,4 mov al,bl and al,0fh cmp al,09h jbe p3 add al,07h jmp p4 p3: add al,30h p4:mov [rdi],al ;; Hex to ASCII conversion inc rdi loop dup1 mov rax,1 mov rdi,1 mov rsi,result mov rdx,4 syscall ret Succe_addition: mov rax,1 mov rdi,1 mov rsi,msg mov rdx,msg_len syscall mov rax,0 mov rdi,0 mov rsi,num mov rdx,3 syscall call convert mov [num1],bl mov rax,1 mov rdi,1 mov rsi,msg mov rdx,msg_len syscall mov rax,0 mov rdi,0 mov rsi,num mov rdx,3 syscall call convert xor rcx,rcx xor rax,rax mov rax,[num1] repet: add rcx,rax dec bl jnz repet mov [result],rcx mov rax,1 mov rdi,1 mov rsi,res mov rdx,res_len syscall mov rbx,[result] call display ret Add_shift: mov rax,1 mov rdi,1 mov rsi,msg mov rdx,msg_len syscall mov rax,0 mov rdi,0 mov rsi,num mov rdx,3 syscall call convert mov [num1],bl mov rax,1 mov rdi,1 mov rsi,msg mov rdx,msg_len syscall mov rax,0 mov rdi,0 mov rsi,num mov rdx,3 syscall call convert mov [num],bl xor rbx,rbx xor rcx,rcx xor rdx,rdx xor rax,rax mov dl,08 mov al,[num1] mov bl,[num] p11: shr bx,01 jnc p add cx,ax p: shl ax,01 dec dl jnz p11 mov [result],rcx mov rax,1 mov rdi,1 mov rsi,res mov rdx,res_len syscall ;dispmsg res,res_len mov rbx,[result] call display ret OUTPUT: Enter your Choice: 1. Successive Addition 2.Add and Shift method 3.Exit 1 Enter two digit Number:: 02 Enter two digit Number:: 02 Multiplication of elements is::0004Enter your Choice: 1.Successive Addition 2. Add and Shift method 3.Exit 2 Enter two digit Number:: 03 Enter two digit Number:: 03 Multiplication of elements is::0009Enter your Choice: 1.Successive Addition 2.Add and Shift method 3.Exit 3 PROGRAM 9: section .data msg : db "File does not exist ",0AH len : equ $-msg msg1 : db "File successfully copied",0AH len1 : equ $-msg1 msg3 : db "Enter the data to be typed in the file",0AH len3 : equ $-msg3 buffer : times 1000 db ' ' filelen : dq 0 section .bss filedes_1 : resq 1 filedes_2 : resq 1 filename_1 : resb 16 filename_2 : resb 16 choice : resb 8 section .txt global _start %macro print 2 mov rax,1 mov rdi,1 mov rsi,%1 mov rdx,%2 syscall %endmacro %macro read 2 mov rax,0 mov rdi,1 mov rsi,%1 mov rdx,%2 syscall %endmacro _start: pop rbx pop rbx ; REMOVE THE NUMMBER OF ARGUMENS FROM THE STACK ;REMOVE EXECUTABLE PROGRAM NAME FROM THE STACK pop rbx ; GET THE FIRST ARGUMENT ;READ THE CHOICE i.e COPY OR TYPE mov [choice],rbx mov rsi,qword[choice] cmp byte[rsi],43H je copy cmp byte[rsi],44H je Delete jmp type ;---------------COPY FROM ONE FILE TO ANOTHER FILE ----------------------- > copy: pop rbx mov rsi,filename_1 up_1: mov al,byte[rbx] mov byte[rsi],al inc rsi inc rbx cmp byte[rbx],0H jne up_1 pop rbx mov rsi,filename_2 up_2: mov al,byte[rbx] mov byte[rsi],al inc rbx inc rsi cmp byte[rbx],0H jne up_2 ;OPENING FIRST FILE mov rax,2 mov rdi,filename_1 ;FIRST FILE NAME mov rsi,2 ; WR MODE mov rdx,0777 ; Permissions given to the file user,Owner,group is read and write and execute syscall ;CHECKING IF FILE EXIST bt rax,63 jc NoFile mov [filedes_1],rax ; if exists the saving hte file descriptor ;OPENING SECOND FILE mov rax,2 mov rdi,filename_2 ;SECOND FILE NAME mov rsi,2 ; WR MODE mov rdx,0777 ; Permissions given to the file user,Owner,group is read and write and execute syscall ;CHECKING IF FILE EXIST cmp rax,0 jle NoFile mov [filedes_2],rax ; if exists the saving the file descriptor ;READING FIRST FILE mov rax,0 mov rdi,qword[filedes_1] mov rsi,buffer mov rdx,100 syscall ;SAVING THE LENGHT OF FIRST FILE mov qword[filelen],rax ;WRITING TO SECOND FILE mov rax,1 mov rdi,qword[filedes_2] mov rsi,buffer mov rdx,qword[filelen] syscall ;CLOSING THE FILES mov rax,3 mov rdi,filedes_1 syscall mov rax,3 mov rdi,filedes_2 syscall ;PRINTING MESSAGE print msg1,len1 jmp exit ;< TYPE IN THE FILE type : ;SAVING FILE NAME pop rbx mov rsi,filename_1 up_4: mov al,byte[rbx] mov byte[rsi],al inc rsi inc rbx cmp byte[rbx],0H jne up_4 > ;OPENING THE FILE mov rax,2 mov rdi,filename_1 ;FIRST FILE NAME mov rsi,2 ; APPEND MODE mov rdx,0777 ; Permissions given to the file user,Owner,group is read and write and execute syscall ;CHECKING IF FILE EXIST cmp rax,1 je NoFile mov [filedes_1],rax ;READING THE INPUT FROM THE SCREEN print msg3,len3 read buffer,1000 ;WRITING TO THE FILE mov rax,1 mov rdi,qword[filedes_1] mov rsi,buffer mov rdx,1000 syscall ;CLOSING THE FILES mov rax,3 mov rdi,filedes_1 syscall jmp exit ;< PRINT FILE NoFile : print msg,len jmp exit > ;<--------------TERMINATING THE PROGRAM ------------- > exit: mov rax,60 mov rdi,0 syscall OUTPUT: $ nasm -f elf64 p.asm $ ld -o p p.o $ ./p COPY a.txt b.txt $ ./p TYPE a.txt PROGRAM10: section .data msgFact: db 'Factorial is:',0xa msgFactSize: equ $-msgFact newLine: db 10 section .bss fact: resb 8 num: resb 2 section .txt global _start _start: pop rbx ;Remove number of arguments pop rbx ;Remove the program name pop rbx ;Remove the actual number whoes factorial is to be calculated (Address of number) mov [num],rbx ;print number accepted from command line mov rax,1 mov rdi,1 mov rsi,[num] mov rdx,2 syscall mov rsi,[num] mov rcx,02 xor rbx,rbx call aToH mov rax,rbx call factP mov rcx,08 mov rdi,fact xor bx,bx mov ebx,eax call hToA mov rax,1 mov rdi,1 mov rsi,newLine mov rdx,1 syscall mov rax,1 mov rdi,1 mov rsi,fact mov rdx,8 syscall mov rax,1 mov rdi,1 mov rsi,newLine mov rdx,1 syscall mov rax,60 mov rdi,0 syscall factP: dec rbx cmp rbx,01 je comeOut cmp rbx,00 je comeOut mul rbx call factP comeOut: ret aToH: up1: rol bx,04 mov al,[rsi] cmp al,39H jbe A2 sub al,07H A2: sub al,30H add bl,al inc rsi loop up1 ret hToA: d: rol ebx,4 mov ax,bx and ax,0fH cmp ax,09H jbe ii add ax,07H ii: add ax,30H mov [rdi],ax inc rdi loop d ret OUTPUT: $ nasm -f elf64 ass9_rec.asm $ ld -o ass9_rec ass9_rec.o $ ./ass9_rec 02 02 00000002