diff --git a/mp-lab/8086/01_add.asm b/mp-lab/8086/01_add.asm new file mode 100644 index 0000000..e101430 --- /dev/null +++ b/mp-lab/8086/01_add.asm @@ -0,0 +1,126 @@ +; @nlkguy +; addition +; NANDULAL KRISHNA +; 20221097 +; S5 CSB + +.model small +.data + msg1 db 13, 10, "num1 : $" + msg2 db 13, 10, "num2 : $" + sum db 13, 10, "sum : $" + +.code +.stack + +start: + + mov ax, @data + mov ds, ax + + lea dx, msg1 + mov ah, 09h + int 21h + + call input + mov bh, dl + + + lea dx, msg2 + mov ah, 09h + int 21h + + call input + mov bl, dl + + + ; add + mov ax, 0000h + mov al, bl + mov cx, 0000h + mov cl, bh + add ax, cx + mov bx, ax + + + mov ah, 09h + lea dx, sum + int 21h + + + call output + mov bh, bl + call output + + + mov ah, 4ch + int 21h + +;----------------------------- +input proc + + call inputnum ; get 1st digit + mov cl, 04h ; cl = 4 + rol dl, cl ; rotate DL 4 times left(shift first digit to left nibble) + and dl, 00f0h ; clear lower nibble + mov ch, dl ; move to CH + + + call inputnum ; get 2nd digit to DL + and dl, 000fh ; AND - + add dl, ch ; add to DL + + ret +input endp +;----------------------------- +inputnum proc + mov ah, 01h + int 21h + + cmp al, 'A' ; compare with character A + jc inputnum_is_dec ; if lessthan A , it is decimal + jmp inputnum_is_hex ; or hex +inputnum_is_hex: + sub al, 'A' + add al, 0ah + mov dl, al + ret +inputnum_is_dec: + sub al, '0' + mov dl, al + ret +inputnum endp +;----------------------------- +output proc + mov al, bh + and al, 00f0h + mov cl, 04h + ror al, cl + mov dl, al + call outputnum + + mov dl, bh + and dl, 000fh + call outputnum + + ret +output endp +;----------------------------- +outputnum proc + mov ah, 02h + + cmp dl, 0ah + jc outputnum_is_dec + jmp outputnum_is_hex +outputnum_is_hex: + add dl, 'A' + sub dl, 0ah + int 21h + ret +outputnum_is_dec: + add dl, '0' + int 21h + ret +outputnum endp +;----------------------------- +end start diff --git a/mp-lab/8086/02_mul.asm b/mp-lab/8086/02_mul.asm new file mode 100644 index 0000000..39e0a37 --- /dev/null +++ b/mp-lab/8086/02_mul.asm @@ -0,0 +1,125 @@ +; @nlkguy +; multiplication +; NANDULAL KRISHNA +; 20221097 +; S5 CSB + +.model small +.data + ms1 db 13, 10, "num1 : $" + ms2 db 13, 10, "num2 : $" + prod db 13, 10, "product : $" + +.code +.stack + +start: + + mov ax, @data + mov ds, ax + + lea dx, ms1 + mov ah, 09h + int 21h + + call input + mov bh, dl + + + lea dx, ms2 + mov ah, 09h + int 21h + + call input + mov bl, dl + + + mov al, bl + mul bh + mov bx, ax + + + mov ah, 09h + lea dx, prod + int 21h + + + call output + mov bh, bl + call output + + + mov ah, 4ch + int 21h + +;--------------------------------- + +input proc + + call inputnum + mov cl, 04h + rol dl, cl + and dl, 00f0h + mov ch, dl + + + call inputnum + and dl, 000fh + add dl, ch + + ret +input endp +;--------------------------------- +inputnum proc + mov ah, 01h + int 21h + + cmp al, 'A' + jc inputnum_is_dec + jmp inputnum_is_hex +inputnum_is_hex: + sub al, 'A' + add al, 0ah + mov dl, al + ret +inputnum_is_dec: + sub al, '0' + mov dl, al + ret +inputnum endp + +;--------------------------------- +output proc + mov al, bh + and al, 00f0h + mov cl, 04h + ror al, cl + mov dl, al + call outputnum + + mov dl, bh + and dl, 000fh + call outputnum + + ret +output endp +;--------------------------------- +outputnum proc + mov ah, 02h + + cmp dl, 0ah + jc outputnum_is_dec + jmp outputnum_is_hex +outputnum_is_hex: + add dl, 'A' + sub dl, 0ah + int 21h + ret +outputnum_is_dec: + add dl, '0' + int 21h + ret +outputnum endp +;--------------------------------- + +end start diff --git a/mp-lab/8086/03_concat.asm b/mp-lab/8086/03_concat.asm new file mode 100644 index 0000000..de2f366 --- /dev/null +++ b/mp-lab/8086/03_concat.asm @@ -0,0 +1,92 @@ + +; @nlkguy +; string concat +; NANDULAL KRISHNA +; 20221097 +; S5 CSB + + +data segment + str1 db 30 dup(" $") + str2 db 30 dup("$") + m1 db 13,10,"str 1 : $" + m2 db 13,10,"str 1 : $" + outp db 13,10,"str 1 : $" + wel db 13,10,"string concat ---- $" +data ends + +code segment +assume cs:code , ds:data +start: + mov ax,data + mov ds,ax + mov cl,04 + + lea dx,wel + mov ah,09h + int 21h + + lea dx,m1 + mov ah,09h + int 21h + + loop0:mov ah,01h + int 21h + cmp al,13 + je skip + mov [si],al + inc si + jmp loop0 + + skip:mov ah,09h + lea dx,m2 + int 21h + + lea si,str2 + loop1:mov ah,01h + int 21h + cmp al,13 + je skip1 + mov [si],al + inc si + jmp loop1 + + skip1:call concat + + mov ah,4ch + int 21h + +concat proc + lea si,str1 + lea di,str2 + mov al,"$" + + loop2: cmp al,[si] + jz loop3 + inc si + jmp loop2 + + loop3: + cmp al,[di] + jz exit + mov bl,[di] + mov [si],bl + inc si + inc di + jmp loop3 + + exit: mov [di],al + lea dx,outp + mov ah,09h + int 21h + lea dx,str1 + mov ah,09h + int 21h + ret +concat endp +code ends +end start + + + + diff --git a/mp-lab/8086/04_replace.asm b/mp-lab/8086/04_replace.asm new file mode 100644 index 0000000..d357bbc --- /dev/null +++ b/mp-lab/8086/04_replace.asm @@ -0,0 +1,126 @@ + +; @nlkguy +; string replace +; NANDULAL KRISHNA +; 20221097 +; S5 CSB + + +data segment + str1 db 20 dup("$") + str2 db 20 dup("$") + newstr db 20 dup("$") + + wel db 13,10,"string replace ---- $" + mainstr db 13,10,"str 1 : $" + replstr db 13,10,"str rep : $" + newstring db 13,10,"str new : $" + outstring db 13,10,"str 1 : $" + foundstring db 13,10,"found $" + notstring db 13,10,"no found $" + +data ends + + +code segment + assume cs:code , ds:data +start: + mov ax,data + mov ds,ax + + lea dx,wel + mov ah,09h + int 21h + + lea dx,mainstr + mov ah,09h + int 21h + + loop0:mov ah,01h + int 21h + cmp al,13 + je skip + mov [si],al + inc si + jmp loop0 + + skip:mov ah,09h + lea dx,replstr + int 21h + + lea si,str2 + loop1:mov ah,01h + int 21h + cmp al,13 + je skip1 + mov [si],al + inc si + jmp loop1 + + skip1:mov ah,09h + lea dx,newstring + int 21h + + lea si,newstr + loop2:mov ah,01h + int 21h + cmp al,13 + je skip2 + mov [si],al + inc si + jmp loop2 + + + skip2: call replace + + + mov ah,4ch + int 21h + +replace proc + lea si,str1 + lea di,str2 + mov al,"$" + + + compare:cmp al,[si] + je nosub + mov bl,[si] + cmp bl,[di] + je copy + inc si + jmp compare + + copy: mov cx,si + lea di,newstr + jmp loop3 + + nosub:lea dx,notstring + mov ah,09h + int 21h + mov ah,4ch + int 21h + + + + loop3: + cmp al,[di] + jz exit + mov bl,[di] + mov [si],bl + inc si + inc di + jmp loop3 + + exit: mov [di],al + lea dx,outstring + mov ah,09h + int 21h + lea dx,str1 + mov ah,09h + int 21h + ret +replace endp +code ends +end start + diff --git a/mp-lab/8086/temp.asm b/mp-lab/8086/temp.asm new file mode 100644 index 0000000..4bbdf84 --- /dev/null +++ b/mp-lab/8086/temp.asm @@ -0,0 +1,49 @@ +.model small +.data + stringarray1 db 30 dup("$") + message1 db 13,10, "this is a god$" + message2 db 13,10, "you have done wrong$" +.code +.stack +start: + mov ax,@data + mov ds,ax + + lea dx,message1 + mov ah,09h + int 21h + + lea dx,message2 + mov ah,09h + int 21h + + call input_string + call output_string + + call exit + + + +exit proc + mov ah,4ch + int 21h +exit endp + +input_string proc + loopin: lea ah,01h + int 21h + cmp al,13 + je skip + mov [si],al + inc si + jmp loopin + skip: call output_string + +input_string endp + +output_string proc + +output_string endp + + +end start \ No newline at end of file diff --git a/mp-lab/8086/temp2.asm b/mp-lab/8086/temp2.asm new file mode 100644 index 0000000..bb6518a --- /dev/null +++ b/mp-lab/8086/temp2.asm @@ -0,0 +1,91 @@ +.model small +.stack 100h + +print macro msg + mov dx,offset msg + mov ah,9h + int 21h +endm + +print_num macro num + mov dl,num + add dl,"0" + mov ah,2 + int 21h +endm + + +input_str macro string,len + local loop1,skip + mov si,0 + loop1: + call input + cmp al,13 + je skip + mov string[si],al + inc si + jmp loop1 + skip: + mov string[si],"$" + mov len,si +endm + +data segment + msg1 db 10,13,"Enter the string 1",10,13,"$" + msg2 db 10,13,"Enter the string 2","$" + no_equal db 10,13,"strings are not equal","$" + equal db 10,13,"strings are equal","$" + + str1 db 10,?,10 dup("$") + str2 db 10,?,10 dup("$") + len1 db 0 + len2 db 0 +data ends + +code segment + assume ds:data,cs:code + start: + mov ax,data + mov ds,ax + + print msg1 + + input_str str1,len1 + + print_num len1 + + print msg2 + + input_str str2,len2 + + mov al,len1 + cmp al,len2 + jne not_equal + mov si,0 + loop1: + mov al,str1[si] + cmp al,"$" + je print_equal + cmp al,str2[si] + jne not_equal + inc si + jmp loop1 + + print_equal: + print equal + jmp exit + not_equal: + print no_equal + + + exit: + mov ah,4ch + int 21h + + input: + mov ah,01h + int 21h + ret + +code ends +end start \ No newline at end of file