├── 8bit_multiplication.asm ├── README.md ├── add_two_16_bit_numbers.asm ├── add_two_4_bit_numbers.asm ├── add_two_8_bit_numbers.asm ├── asending_sort.asm ├── desending_sort.asm ├── linear_search.asm ├── pallindrome.asm ├── pattern.asm ├── prime.asm ├── print_hello_world.asm └── string_reversal.asm /8bit_multiplication.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | 3 | msg1 db 0ah,0dh, "Enter first number : $" 4 | msg2 db 0ah,0dh, "Enter second number : $" 5 | msg3 db 0ah,0dh, "Result is : $" 6 | 7 | data ends 8 | 9 | code segment 10 | assume cs:code,ds:data 11 | 12 | start:mov ax,data 13 | mov ds,ax 14 | 15 | ;Printing "Enter first Number" 16 | lea dx,msg1 17 | mov ah,09h 18 | int 21h 19 | 20 | mov ah,01h 21 | int 21h 22 | sub al,30h 23 | mov bl,al 24 | 25 | mov ah,01h 26 | int 21h 27 | sub al,30h 28 | mov bh,al 29 | 30 | ;Packing the entered number and storing in bl 31 | mov ax,bx 32 | aad 33 | mov bl,al 34 | 35 | ;Printing "Enter second Number" 36 | lea dx,msg2 37 | mov al,09h 38 | int 21h 39 | 40 | mov ah,01h 41 | int 21h 42 | sub ah,30h 43 | mov ch,al 44 | 45 | mov ah,01h 46 | int 21h 47 | sub al,30h 48 | mov cl,al 49 | 50 | ;Packing the entered number 51 | mov ax,cx 52 | aad 53 | 54 | ;Multiplying 55 | mul bl 56 | 57 | ;Getting number at 1000s place 58 | mov cx,03e8h 59 | mov dx,0000h 60 | 61 | div cx 62 | 63 | ;Making reminder the new divident 64 | mov bx,dx 65 | 66 | ;Printing 67 | mov dl,al 68 | add dl,30h 69 | mov ah,02h 70 | int 21h 71 | 72 | ;Getting number at 100s place 73 | mov cl,64h 74 | mov ax,bx 75 | 76 | div cl 77 | 78 | ;Making reminder the new divident 79 | mov bl,ah 80 | 81 | ;Printing 82 | mov dl,al 83 | add dl,30h 84 | mov ah,02h 85 | int 21h 86 | 87 | ;Getting number at 10s place 88 | mov cl,0Ah 89 | mov bh,00h 90 | mov ax,bx 91 | 92 | div cl 93 | 94 | ;Saving Reminder 95 | mov bl,ah 96 | 97 | ;Printing 98 | mov dl,al 99 | add dl,30h 100 | mov ah,02h 101 | int 21h 102 | 103 | ;Printing Reminder 104 | mov dl,bl 105 | add dl,30h 106 | mov ah,02h 107 | int 21h 108 | 109 | mov ah,4ch 110 | int 21h 111 | 112 | 113 | code ends 114 | end start 115 | 116 | 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Microprocessor Lab | KTU

4 |
5 |

This repository contains a collection of assembly programs written as part of Microprocessor Lab KTU

6 |
7 |

8 | 9 | ## 🚧 Requirements 10 | 11 | * [DOSBox](https://www.dosbox.com/download.php?main=1) 12 | * [MASM](http://www.mediafire.com/download/x13v7gqqmw1pom7/8086_Assembler(TechzClub_joyjophin).zip) 13 | 14 |

15 | 16 | ## 🛠 Setup DOSBox and MASM 17 | 18 | 1. Download and Install [DOSBox](https://www.dosbox.com/download.php?main=1) 19 | 2. Download and extract [MASM](http://www.mediafire.com/download/x13v7gqqmw1pom7/8086_Assembler(TechzClub_joyjophin).zip) 20 | 3. Open DOSBox and Run following commands 21 | 22 |
23 | 24 | ```bash 25 | mount c 26 | c: 27 | ``` 28 |
29 | 30 | ### Example 31 | 32 | ```bash 33 | mount c c:/users/aromal/downloads/masm 34 | c: 35 | ``` 36 |

37 | 38 | ## 💻 Run 39 | 40 | To run any of these programs in your computer. 41 | 42 | 1. Download and Copy the program you want to run to the MASM folder 43 | 2. Open DOSBox and Run following commands 44 | 45 |
46 | 47 | ```bash 48 | mount c 49 | c: 50 | 51 | masm 52 | link 53 | 54 | ``` 55 |
56 | 57 | ### Example 58 | 59 | ```bash 60 | mount c c:/users/aromal/downloads/masm 61 | c: 62 | 63 | masm pattern.asm 64 | link pattern.obj 65 | pattern.exe 66 | ``` 67 |

68 | 69 | ## ✍ Author 70 | 71 | [Aromal Anil](https://aromalanil.in) 72 | 73 | -------------------------------------------------------------------------------- /add_two_16_bit_numbers.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | msg1 db 0ah,0dh, "Enter first number : $" 3 | msg2 db 0ah,0dh, "Enter second number : $" 4 | msg3 db 0ah,0dh, "Result is : $" 5 | n1 db 07h dup(?) 6 | n2 db 07h dup(?) 7 | data ends 8 | 9 | code segment 10 | assume cs:code,ds:data 11 | start: mov ax,data 12 | mov ds,ax 13 | 14 | ;Getting offset of arrays 15 | mov si,offset n1 16 | mov di,offset n2 17 | 18 | ;Printing "Enter first number" 19 | lea dx,msg1 20 | mov ah,09h 21 | int 21h 22 | 23 | ;Setting Count to 4 24 | mov cl,04h 25 | 26 | ;Getting First Number 27 | first:mov ah,01h 28 | int 21h 29 | sub al,30h 30 | mov [si],al 31 | inc si 32 | dec cl 33 | jnz first 34 | 35 | ;Printing "Enter second number" 36 | lea dx,msg2 37 | mov ah,09h 38 | int 21h 39 | 40 | ;Setting count to 4 41 | mov cl,04h 42 | 43 | ;Getting second Number 44 | second:mov ah,01h 45 | int 21h 46 | sub al,30h 47 | mov [di],al 48 | inc di 49 | dec cl 50 | jnz second 51 | 52 | ;Clearing carry 53 | clc 54 | 55 | ;Setting count to 4 56 | mov cl,04h 57 | 58 | ;Performing Addition 59 | addition:dec di 60 | dec si 61 | mov al,[si] 62 | mov bl,[di] 63 | 64 | adc al,bl 65 | mov ah,00h 66 | aaa 67 | 68 | ;Storing result to di array 69 | mov [di],al 70 | 71 | dec cl 72 | jnz addition 73 | 74 | ;Printing "Result is" 75 | lea dx,msg3 76 | mov ah,09h 77 | int 21h 78 | 79 | ;Printing Result 80 | mov bh,00h 81 | mov dl,30h 82 | adc dl,bh 83 | cmp dl,30h 84 | je skip 85 | 86 | ;Printing Carry 87 | mov ah,02h 88 | int 21h 89 | 90 | skip: 91 | ;Setting Count to 4 92 | mov cl,04h 93 | 94 | ;Printing array content 95 | print:mov dl,[di] 96 | add dl,30h 97 | 98 | mov ah,02h 99 | int 21h 100 | 101 | inc di 102 | dec cl 103 | jnz print 104 | 105 | mov ah,4ch 106 | int 21h 107 | code ends 108 | end start 109 | -------------------------------------------------------------------------------- /add_two_4_bit_numbers.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | num1 DB ? 3 | num2 DB ? 4 | msg1 DB 0ah,0bh,"Enter first Number : $" 5 | msg2 DB 0ah,0bh,"Enter second Number : $" 6 | msg3 DB 0ah,0bh,"result is $" 7 | DATA ENDS 8 | 9 | CODE SEGMENT 10 | ASSUME DS:DATA,CS:CODE 11 | 12 | START : MOV AX,DATA 13 | MOV DS,AX 14 | LEA DX,msg1 15 | MOV AH,09H 16 | INT 21H 17 | MOV AH,01H 18 | INT 21H 19 | SUB AL,30H 20 | MOV num1,AL 21 | 22 | LEA DX,msg2 23 | MOV AH,09H 24 | INT 21H 25 | MOV AH,01H 26 | INT 21H 27 | SUB AL,30H 28 | MOV num2,AL 29 | 30 | 31 | LEA DX,msg3 32 | MOV AH,09H 33 | INT 21H 34 | 35 | ADD AL,num1 36 | 37 | MOV AH,00H 38 | AAA 39 | MOV BX,AX 40 | ADD BX,3030H 41 | MOV DL,BH 42 | MOV AH,02H 43 | INT 21H 44 | MOV DL,BL 45 | MOV AH,02H 46 | INT 21H 47 | MOV AH,4CH 48 | INT 21H 49 | 50 | 51 | CODE ENDS 52 | END START 53 | -------------------------------------------------------------------------------- /add_two_8_bit_numbers.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | 3 | MSG1 DB "Enter first number : $" 4 | MSG2 DB "Enter second number : $" 5 | MSG3 DB "Result is : $" 6 | 7 | DATA ENDS 8 | 9 | 10 | CODE SEGMENT 11 | 12 | ASSUME DS:DATA, CS:CODE 13 | 14 | START: MOV AX,DATA 15 | MOV DS,AX 16 | 17 | ;Print first message 18 | LEA DX,MSG1 19 | MOV AH,09H 20 | INT 21H 21 | 22 | ;Read first digit of number 1 23 | MOV AH,01H 24 | INT 21H 25 | SUB AL,30H 26 | MOV BH,AL 27 | 28 | ;Read second digit of number 1 29 | MOV AH,01H 30 | INT 21H 31 | SUB AL,30H 32 | MOV BL,AL 33 | 34 | ;Print second Message 35 | LEA DX,MSG2 36 | MOV AH,09H 37 | INT 21H 38 | 39 | ;Read first digit of number 2 40 | MOV AH,01H 41 | INT 21H 42 | SUB AL,30H 43 | MOV CH,AL 44 | 45 | ;Read second digit of number 2 46 | MOV AH,01H 47 | INT 21H 48 | SUB AL,30H 49 | MOV CL,AL 50 | 51 | ;Performing AL=BL+CL 52 | ADD BL,CL 53 | MOV AL,BL 54 | 55 | ;Splitting AL into AH & AL 56 | MOV AH,00H 57 | AAA 58 | 59 | ;Saving result of first addition to BL(temperory) 60 | MOV BL,AL 61 | 62 | ;Performing AL=BH+CH+AH 63 | MOV AL,AH 64 | ADD AL,BH 65 | ADD AL,CH 66 | 67 | ;Splitting result into AH & AL 68 | MOV AH,00H 69 | AAA 70 | 71 | ;CH=AH,CL=AL 72 | MOV CH,AH 73 | MOV CL,AL 74 | 75 | ;Print last message 76 | LEA DX,MSG3 77 | MOV AH,09H 78 | INT 21H 79 | 80 | ;Converting result to ascii 81 | ADD CH,30H 82 | ADD CL,30H 83 | ADD BL,30H 84 | 85 | 86 | ;Printing Result 87 | 88 | ;If first digit is zero skip it 89 | CMP CH,30H 90 | JE LB 91 | 92 | MOV DL,CH 93 | MOV AH,02H 94 | INT 21H 95 | 96 | LB: 97 | MOV DL,CL 98 | MOV AH,02H 99 | INT 21H 100 | 101 | MOV DL,BL 102 | MOV AH,02H 103 | INT 21H 104 | 105 | ;Closing 106 | MOV AH,4CH 107 | INT 21H 108 | 109 | 110 | CODE ENDS 111 | END START 112 | -------------------------------------------------------------------------------- /asending_sort.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | 3 | msg1 db 0ah,0dh,"Enter the no of elements : $" 4 | msg2 db 0ah,0dh,"Enter the numers : $" 5 | msg3 db 0ah,0dh,"Sorted array is : $" 6 | n db ? 7 | n1 db 09h dup(?) 8 | 9 | data ends 10 | code segment 11 | assume cs:code,ds:data 12 | start: mov ax,data 13 | mov ds,ax 14 | 15 | ;Printing "Enter the limit" 16 | lea dx,msg1 17 | mov ah,09h 18 | int 21h 19 | 20 | mov ah,01h 21 | int 21h 22 | sub al,30h 23 | mov n,al 24 | 25 | mov cl,n 26 | 27 | ;Printing "Enter the numbers" 28 | lea dx,msg2 29 | mov ah,09h 30 | int 21h 31 | 32 | mov si,offset n1 33 | 34 | read:mov ah,01h 35 | int 21h 36 | sub al,30h 37 | mov [si],al 38 | inc si 39 | dec cl 40 | jnz read 41 | 42 | mov cl,n 43 | loop1: 44 | mov ch,n 45 | mov si,offset n1 46 | loop2: 47 | mov dl,[si] 48 | cmp dl,[si+1] 49 | jnc swap 50 | jmp swapped 51 | 52 | swap:mov dl,[si] 53 | xchg dl,[si+1] 54 | mov [si],dl 55 | 56 | swapped:inc si 57 | dec ch 58 | jnz loop2 59 | 60 | dec cl 61 | jnz loop1 62 | 63 | ;Printing "Sorted Array is" 64 | lea dx,msg3 65 | mov ah,09h 66 | int 21h 67 | 68 | 69 | ;printing Array 70 | mov si,offset n1 71 | mov cl,n 72 | inc si 73 | 74 | print: 75 | mov dl,[si] 76 | add dl,30h 77 | mov ah,02h 78 | int 21h 79 | 80 | inc si 81 | dec cl 82 | jnz print 83 | 84 | mov ah,4ch 85 | int 21h 86 | 87 | code ends 88 | end start 89 | 90 | 91 | -------------------------------------------------------------------------------- /desending_sort.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | 3 | msg1 db 0ah,0dh,"Enter the no of elements : $" 4 | msg2 db 0ah,0dh,"Enter the numers : $" 5 | msg3 db 0ah,0dh,"Sorted array is : $" 6 | n db ? 7 | n1 db 09h dup(?) 8 | 9 | data ends 10 | code segment 11 | assume cs:code,ds:data 12 | start: mov ax,data 13 | mov ds,ax 14 | 15 | ;Printing "Enter the limit" 16 | lea dx,msg1 17 | mov ah,09h 18 | int 21h 19 | 20 | mov ah,01h 21 | int 21h 22 | sub al,30h 23 | mov n,al 24 | 25 | mov cl,n 26 | 27 | ;Printing "Enter the numbers" 28 | lea dx,msg2 29 | mov ah,09h 30 | int 21h 31 | 32 | mov si,offset n1 33 | 34 | read:mov ah,01h 35 | int 21h 36 | sub al,30h 37 | mov [si],al 38 | inc si 39 | dec cl 40 | jnz read 41 | 42 | mov cl,n 43 | loop1: 44 | mov ch,n 45 | mov si,offset n1 46 | loop2: 47 | mov dl,[si] 48 | cmp dl,[si+1] 49 | jc swap 50 | jmp swapped 51 | 52 | swap:mov dl,[si] 53 | xchg dl,[si+1] 54 | mov [si],dl 55 | 56 | swapped:inc si 57 | dec ch 58 | jnz loop2 59 | 60 | dec cl 61 | jnz loop1 62 | 63 | ;Printing "Sorted Array is" 64 | lea dx,msg3 65 | mov ah,09h 66 | int 21h 67 | 68 | 69 | ;printing Array 70 | mov si,offset n1 71 | mov cl,n 72 | print: 73 | mov dl,[si] 74 | add dl,30h 75 | mov ah,02h 76 | int 21h 77 | 78 | inc si 79 | dec cl 80 | jnz print 81 | 82 | mov ah,4ch 83 | int 21h 84 | 85 | code ends 86 | end start 87 | 88 | 89 | -------------------------------------------------------------------------------- /linear_search.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | msg1 db 0ah,0dh,"Enter the string : $" 3 | msg2 db 0ah,0dh,"Enter the key : $" 4 | msg3 db 0ah,0dh,"Key found$" 5 | msg4 db 0ah,0dh,"Key not found$" 6 | n db 09h dup(?) 7 | data ends 8 | 9 | code segment 10 | assume cs:code,ds:data 11 | start: mov ax,data 12 | mov ds,ax 13 | 14 | ;Getting offset of array 15 | mov si,offset n 16 | 17 | ;Printing message1 18 | lea dx,msg1 19 | mov ah,09h 20 | int 21h 21 | 22 | mov cl,00h 23 | 24 | ;Reading string 25 | scan:mov ah,01h 26 | int 21h 27 | 28 | cmp al,0dh 29 | jz ended 30 | mov [si],al 31 | inc cl 32 | inc si 33 | jmp scan 34 | 35 | ended: 36 | ;printing msg2 37 | lea dx,msg2 38 | mov ah,09h 39 | int 21h 40 | 41 | 42 | ;Reading key 43 | mov ah,01h 44 | int 21h 45 | mov bl,al 46 | 47 | mov ch,00h 48 | check:dec si 49 | 50 | cmp bl,[si] 51 | jz found 52 | dec cl 53 | jnz check 54 | 55 | jmp notfound 56 | 57 | found: 58 | ;Printing message1 59 | lea dx,msg3 60 | mov ah,09h 61 | int 21h 62 | jmp finish 63 | 64 | notfound: 65 | ;Printing message1 66 | lea dx,msg4 67 | mov ah,09h 68 | int 21h 69 | 70 | 71 | finish: 72 | mov ah,4ch 73 | int 21h 74 | 75 | code ends 76 | end start 77 | -------------------------------------------------------------------------------- /pallindrome.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | msg1 db 0ah,0dh,"Enter the string : $" 3 | msg2 db 0ah,0dh,"Is a pallindrome $" 4 | msg3 db 0ah,0dh,"Is not a pallindrome $" 5 | n db 09h dup(?) 6 | data ends 7 | code segment 8 | assume cs:code,ds:data 9 | start: mov ax,data 10 | mov ds,ax 11 | 12 | ;Getting offset of array 13 | mov si,offset n 14 | mov di,offset n 15 | 16 | ;Printing message1 17 | lea dx,msg1 18 | mov ah,09h 19 | int 21h 20 | 21 | mov cl,00h 22 | ;Reading string 23 | scan:mov ah,01h 24 | int 21h 25 | 26 | cmp al,0dh 27 | jz ended 28 | mov [si],al 29 | inc cl 30 | inc si 31 | jmp scan 32 | 33 | ended: 34 | dec si 35 | mov bl,[si] 36 | cmp [di],bl 37 | jnz notpal 38 | inc di 39 | dec cl 40 | jnz ended 41 | 42 | 43 | pal: 44 | ;Printing pallindrom 45 | lea dx,msg2 46 | mov ah,09h 47 | int 21h 48 | jmp stoped 49 | 50 | notpal: ;Printing not pallindrom 51 | lea dx,msg3 52 | mov ah,09h 53 | int 21h 54 | 55 | stoped: 56 | mov ah,4ch 57 | int 21h 58 | 59 | 60 | code ends 61 | end start 62 | -------------------------------------------------------------------------------- /pattern.asm: -------------------------------------------------------------------------------- 1 | ; An assembly program which prints the pattern 2 | ; 1 3 | ; 1 2 4 | ; 1 2 3 5 | ; 1 2 3 4 6 | 7 | data segment 8 | 9 | nxtline db 0ah,0dh,"$" 10 | space db " $" 11 | n db 00h 12 | m db 00h 13 | 14 | data ends 15 | code segment 16 | assume cs:code,ds:data 17 | start: mov ax,data 18 | mov ds,ax 19 | 20 | loop1: 21 | inc n 22 | mov m,00h 23 | 24 | loop2: 25 | inc m 26 | 27 | ;Printing m 28 | mov dl,m 29 | add dl,30h 30 | mov ah,02h 31 | int 21h 32 | 33 | ;Print space 34 | lea dx,space 35 | mov ah,09h 36 | int 21h 37 | 38 | ;If m!=n go to loop2 39 | mov bl,m 40 | cmp n,bl 41 | jne loop2 42 | 43 | ;If n=4 go to loopend 44 | cmp n,04h 45 | je loopend 46 | 47 | ;Print nextline 48 | lea dx,nxtline 49 | mov ah,09h 50 | int 21h 51 | 52 | ;Goto loop1 53 | jmp loop1 54 | 55 | loopend: mov ah,4ch 56 | int 21h 57 | 58 | code ends 59 | end start -------------------------------------------------------------------------------- /prime.asm: -------------------------------------------------------------------------------- 1 | ;Assembly program to find whether an 8-bit number is prime or not 2 | 3 | data segment 4 | A db 1,2,3,5,7 5 | msg1 db 0ah,0dh,"Enter the number : $" 6 | isprime db 0ah,0dh,"The number is Prime$" 7 | notprime db 0ah,0dh,"The number is not Prime$" 8 | data ends 9 | 10 | code segment 11 | assume cs:code,ds:data 12 | start: mov ax,data 13 | mov ds,ax 14 | 15 | ;Print "Enter the number : " 16 | lea dx,msg1 17 | mov ah,09h 18 | int 21h 19 | 20 | ;Getting the number at bx 21 | mov ah,01h 22 | int 21h 23 | mov bh,al 24 | mov ah,01h 25 | int 21h 26 | mov bl,al 27 | sub bx,3030h 28 | 29 | mov dl,05h 30 | mov si,offset A 31 | mov ch,[si] 32 | mov cl,00h 33 | 34 | loop1:mov ax,bx 35 | aad 36 | div ch 37 | cmp ah,00h 38 | jne loop2 39 | inc cl 40 | 41 | loop2:inc si 42 | mov ch,[si] 43 | dec dl 44 | jne loop1 45 | cmp cl,01h 46 | je jmpprime 47 | 48 | ;Printing "The number is not Prime" 49 | lea dx,notprime 50 | mov ah,09h 51 | int 21h 52 | 53 | jmp finish 54 | 55 | ;Printing "The number is Prime" 56 | jmpprime:lea dx,isprime 57 | mov ah,09h 58 | int 21h 59 | 60 | finish:mov ah,4ch 61 | int 21h 62 | code ends 63 | end start 64 | 65 | -------------------------------------------------------------------------------- /print_hello_world.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | msg DB "Hello World$" 3 | DATA ENDS 4 | CODE SEGMENT 5 | ASSUME CS:CODE,DS:DATA 6 | START: MOV AX,DATA 7 | MOV DS,AX 8 | LEA DX,msg 9 | MOV AH,09H 10 | INT 21H 11 | MOV AH,4CH 12 | INT 21H 13 | CODE ENDS 14 | END START 15 | -------------------------------------------------------------------------------- /string_reversal.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | msg1 db 0ah,0dh,"Enter the string : $" 3 | msg2 db 0ah,0dh,"Reverse is : $" 4 | n db 09h dup(?) 5 | data ends 6 | 7 | code segment 8 | assume cs:code,ds:data 9 | start: mov ax,data 10 | mov ds,ax 11 | 12 | ;Getting offset of array 13 | mov si,offset n 14 | 15 | ;Printing message1 16 | lea dx,msg1 17 | mov ah,09h 18 | int 21h 19 | 20 | mov cl,00h 21 | ;Reading string 22 | scan:mov ah,01h 23 | int 21h 24 | 25 | cmp al,0dh 26 | jz ended 27 | mov [si],al 28 | inc cl 29 | inc si 30 | jmp scan 31 | 32 | ended: 33 | ;printing msg2 34 | lea dx,msg2 35 | mov ah,09h 36 | int 21h 37 | 38 | print:dec si 39 | 40 | mov dl,[si] 41 | mov ah,02h 42 | int 21h 43 | dec cl 44 | jnz print 45 | 46 | mov ah,4ch 47 | int 21h 48 | 49 | code ends 50 | end start 51 | --------------------------------------------------------------------------------