Tuesday, October 23, 2018

paaa

;PAI ASSIGNMENT -1
;Problem Statement-
;Write Assembly Language Program (ALP) to add array of N numbers stored in the memory

.model small
.data

array db 01h,02h,03h,04h,05h ;5 numbers in array
result db 00h
cnt db 05h ;initialize the count to 5

.stack 100h

.code
main proc
mov ax,@data ;initialization of data
mov ds,ax
lea si,array

add_up: ;label
mov al,[si] ;move first index of array to al
add result,al
inc si
dec cnt
jnz add_up
mov bl,result
and result,0F0h 
shr result,04h
cmp result,09h
ja add1
add result,30h ;to convert from ASCII to decimal value
jmp add2

add1:
add result,37h

add2:
mov ah,02h
mov dl,result
int 21h
and bl,0Fh
cmp bl,09h
ja add3
add bl,30h
jmp add4

add3:
add bl,37h

add4:
mov ah,02h
mov dl,bl

int 21h
mov ah,4ch
int 21h
main endp
end main

***********************************************************
;PAI Assignment 02
;Problem Statement-

;Write menu driven ALP to convert 4-digit Hex number into ;its equivalent BCD number and 5-digit
;BCD number into its equivalent HEX number. Make your ;program user friendly to accept the choice
;from user for
;i. HEX to BCD
;;ii. BCD to HEX iii. EXIT.
;Display proper strings to prompt the user while accepting ;the input and displaying the result. Write
;near procedures to complete the task.
;Program -

disp macro msg ;macro to display message
mov dx, offset msg
mov ah,09h
int 21h
endm


.model small
.data

msg1 db 10,13,"Enter 5 Digit Bcd Number$" ;messages to display
msg2 db 10,13,"Equivalent Hexadecimal Number$"
msg3 db 10,13,"Enter Your Choice$"
msg4 db 10,13,"Equivalent Bcd Number is$"
msg5 db 10,13,"Enter Hex Number$"
msg6 db 10,13,"Menu$"
msg7 db 10,13,"1.Bcd To Hex$"
msg8 db 10,13,"2.Hex To Bcd$"
msg9 db 10,13,"3.Exit$"
msg10 db 10,13,"------------------------------$"
msg11 db 10,13,"Invalid Entry$"

arr dw 2710h,03e8h,0064H,000ah,0001h ;hexadecimal values for units to ten thousand

cnt db 05h ;count

;ORG 0200h

res dw 0000h
op1 dw ?
count db 00h

.code

bh1 proc near ; for bcd to hex

disp msg1
lea si,arr

back:
mov ah,01h
int 21h
cmp al,30h ;to check number is between 0 to 9
jb invalid1
cmp al,39h
jg invalid1
cmp al,39h
jbe next1 ;if below or equal to
sub al,07h

next1:
sub al,30h
mov ah,00h
mov cx,[si]
mul cx ;multiply contents of accumulator with cx
add res,ax
inc si
inc si ;increment twice because of 16 bit data
dec cnt
jnz back
disp msg2
jmp dis
ret1:
ret

invalid1:
disp msg11
ret

bh1 endp




bh2 proc near ;for hex to bcd

disp msg5
mov cx,0404h
mov dx,0000h

back6:
mov ah,01h
int 21h
cmp al,30h
jb invalid
cmp al,39h
jg next6
sub al,30h
jmp below

next6:
cmp al,41h ;check if between a tof
jb invalid
cmp al,46h
ja next7
sub al,37h
jmp below

next7:
cmp al,61h ;check if between A to F
jb invalid
cmp al,66h
ja invalid
sub al,57h

below:
rol dx,cl
mov ah,00h
add dx,ax
dec ch
jnz back6
mov op1,dx
disp msg4
mov ax,op1

up:
mov dx,0000h
mov bx,000ah
div bx
push dx
inc count
cmp ax,0000h
jnz up

back5:
pop dx
add dl,30h
mov ah,02h
int 21h
dec count
jnz back5
ret

invalid:
disp msg11
ret
bh2 endp


start:
mov ax,@data
mov ds,ax
menu:
disp msg6
disp msg7
disp msg8
disp msg9
disp msg10
disp msg3

mov ah,01h
int 21h
mov bl,al
cmp bl,31h ;compare with 1
jne next
call bh1
jmp menu

next:
cmp bl,32h ;compare with 2
jne last
call bh2
jmp menu

dis:
mov cx,0404h
mov bx,res

back1:
rol bx,cl
mov dl,bl
and dl,0fh
cmp dl,09h
jbe next3
add dl,07h


next3:
add dl,30h
mov ah,02h
int 21h
dec ch
jnz back1
jmp ret1


last:
mov ah,4ch
int 21h

end start
end

****************************************************************
;PAI-Assignemnt-03
;Write ALP to perform following operation on string:
;i. Find and display length
; ii. Display reverse
; iii. Check whether string is palindrome or not.
; Display proper strings to prompt the user while accepting the input and displaying the result. Write
; near procedures to complete the task.
;
;Program -

disp macro msg ;macro for display
mov ah,09h
lea dx,msg
int 21h
endm


.model small
.stack 100h
.data

str1 db 25 dup("$")
str2 db 25 dup("$")
msg1 db 10,13, "Menu$" ;display menu
msg2 db 10,13, "1.Enter String $"
msg3 db 10,13, "2.length of String$"
msg4 db 10,13, "3.Reverse of String $"
msg5 db 10,13, "4.palindrome of String$"
msg6 db 10,13, "5.Exit$"
msg7 db 10,13, "Enter Choice  $"
msg8 db 10,13,  "Wrong Choice   $"
msg9 db 10,13,  "Enter The String   $"
msg10 db 10,13, "String is :$"
msg11 db 10,13, "length is :$"
msg12 db 10,13, "String is palindrome$"
msg13 db 10,13, "String is not palindrome$"

.code 


accept proc near
disp msg9
lea dx,str1 ;0Ah to accept string
mov ah,0Ah ;and store in str1
int 21h
ret ;return the controll
accept endp


leng proc near

disp msg11
mov dl,str1+1 ;store length in dl
add dl,30h  ;to convert in ascii value
mov ah,02h ;02h to display length 
int 21h
ret
leng endp



reverse proc near

disp msg10
xor ch,ch
mov cl,str1+1 ;move length in cl
sub cl,01h ;subtract 1bcoz 1st index stores length
lea si,str1+2
lea di,str1+2
rep movsb ;to reach to last index copy in same index
mov cl,str1+1
lea di,str2+2

loop1:
mov dx,[si] ;move rightmost char in dx
mov [di],dx ;copy char to destination
mov ah,02h
int 21h ;print the value in di
dec si
inc di
dec cl
cmp cl,00h ;compare if no more elements
jne loop1 ;if more elements are there
ret
reverse endp


pall proc near

lea dx,str1+2
call reverse ;reverse the string
lea di,str2+2 ;start from 2nd index
lea si,str1+2
mov cl,str1+1 ;move length in cl as count

loop2:
mov al,byte ptr[si]
mov bl,byte ptr[di]
dec cl ;decrement count
cmp cl,00h ;compare if no more elements
je loopx
cmp al,bl ;compare characters
je loop3
loopx:
cmp cl,00h
je loop4
disp msg13
jmp loop5

loop4:disp msg12

loop5:ret

loop3:  inc si
inc di
jmp loop2 ;check next character
pall endp



start:

mov ax,@data ;initialize data and extra segment
mov ds,ax

menu:
disp msg1
disp msg2
disp msg3
disp msg4
disp msg5
disp msg6
disp msg7

mov ah,01h ;accept the choice
int 21h
mov bl,al

cmp bl,31h ;if choice is 1
je acc

cmp bl,32h ;if choice 2
je len

cmp bl,33h ;if choice 3
je rev

cmp bl,34h ;if choice 4
je pallindrom

cmp bl,35h ;if choice 5
je ter
disp msg8 ;wrong choice



acc: call accept
jmp menu

len: call leng
jmp menu
rev:
call reverse
jmp menu
pallindrom: call pall
jmp menu
ter: mov ah,4ch 
int 21h

end start

end





*******************************************************************************


4.1
;PAI ASSIGNMENT -4

;Problem Statement-

;Write menu driven ALP to perform string manipulations. ;The strings to be accepted from the user is
;to be stored in code segment Module_1 and write FAR ;PROCEDURES in code segment Module_2 to
; perform the following string operations:
;i. Concatenation of two strings.
;ii. Comparison of two strings.

;Program -

disp macro msg
mov ah,09h
lea dx,msg
int 21h
endm

.model small
.stack 100h
.data

public str1,str2

msg1 db 10,13, 'Enter string 1  $'
msg2 db 10,13, 'Enter string 2  $'
msg3 db 10,13, '1.Concatenation$'
msg4 db 10,13, '2.Compare$'
msg5 db 10,13, '3.Exit$'
msg6 db 10,13, 'Enter your choice$'
msg7 db 10,13, 'Enter correct choice$'

str1 db 25 dup('$')
str2 db 25 dup('$')

.code
extrn   concatenation: far
extrn comparison: far

start:
mov ax,@data
mov ds,ax
mov es,ax

disp msg1
lea dx,str1
mov ah,0ah
int 21h

disp msg2
lea dx,str2
mov ah,0ah
int 21h

menu:

disp msg3
disp msg4
disp msg5
disp msg6


mov ah,01h
int 21h
mov bl,al

cmp bl,31h
je concat

cmp bl,32h
je comp

cmp bl,33h
je ter

disp msg7
jmp menu


concat: call concatenation
jmp menu 
 
comp: call comparison
jmp menu 
 
ter: 
mov ah,4ch
int 21h
end start
end

4.2
;Program 4-2


;MOD 2

disp macro msg
mov ah,09h
lea dx,msg
int 21h
endm


.model small
.stack 100h
.data
extrn str1:byte,str2:byte
msg1 db 10,13,'concatenation string$'
msg2 db 10,13,'strings are equal$'
msg3 db 10,13,'strings are not equal$'
str3 db 25 dup('$')
.code
main proc
public concatenation,comparison
mov ax,@data
mov ds,ax
mov es,ax
concatenation proc far
mov ch,00h
mov cl,str1+1
lea si,str1+2
lea di,str3+2
repz movsb
mov ch,00h
mov cl,str2+1
lea si,str2+2
cld
repz movsb
disp msg1
lea si,str3
mov ah,09h
lea dx,str3+2
int 21h
ret
concatenation endp
comparison proc far
mov cl,str1+1
mov ch,str2+1
cmp ch,cl
jnz down
mov ch,00h
mov cl,str1+1
lea si,str1
lea di,str2
cld
repe cmpsb
jnz down
disp msg2
ret
down:disp msg3
ret
comparison endp
ter:mov ah,4ch
int 21h
main endp
end main
*************************************************************
#include<stdio.h> //header files
#include<conio.h>
#include<dos.h>

void create_directory(char []); //function to create directory
void delete_directory(char []); //function to delete directory
void delete_file(char []); //function to delete file
void create_file(char []); //function to create file

int main() //main function
{

char directory[10],directory_name[40],file[10],file_name[40]; //initialization of variables
int ch;
//clrscr();

do
{
printf("\t\t\n\nDIRECTORY PROGRAM\n"); //menu
printf("1)Create A Directory\n");
printf("2)Create A File\n");
printf("3)Delete A Directory\n");
printf("4)Delete A File\n");
printf("ENTER YOUR CHOICE :");
scanf("%d",&ch);

switch(ch)
{
case 1:
       printf("ENTER THE NAME OF DIRECTORY:");
       scanf("%s",directory);
       create_directory(directory); //function call: create directory
break;

case 2:
       printf("ENTER THE NAME OF FILE: ");
       scanf("%s",file);
       create_file(file); //function call: create file
break;

case 3:
       printf("ENTER THE PATH OF DIRECTORY:");
       scanf("%s",directory_name);
       delete_directory(directory_name); //function call: delete directory
break;

case 4:
       printf("ENTER THE PATH OF FILE: ");
       scanf("%s",file_name);
       delete_file(file_name); //function call: delete file
break;
}
}while(ch<5);
return 0;
}

void create_directory(char directory[10]) //function definition: directory create function
{
     union REGS regs;
struct SREGS sregs;
int ret,err;

regs.h.ah=0x39;
regs.x.dx=FP_OFF(directory);
sregs.ds=FP_SEG(directory);

ret=intdosx(&regs,&regs,&sregs);
err=(regs.x.cflag?ret:0);

if(!err)
{
printf("DIRECTORY CREATED SUCCESSFULLY\n");
}
else if(err==5)
{
printf("DIRECTORY ALREADY EXISTS");
}
else
{
printf("DIRECTORY DOES NOT EXIXTS");
}
}

void create_file(char file[10]) //function definition: file creation
{
union REGS regs;
struct SREGS sregs;
int ret,err;

regs.h.ah=0x3C;
regs.x.dx=FP_OFF(file);
sregs.ds=FP_SEG(file);

ret=int86x(0x21,&regs,&regs,&sregs);
err=(regs.x.cflag?ret:0);

if(!err)
{
printf("FILE CREATED SUCCESSFULLY\n");
}
else if(err==5)
{
printf("FILE ALREADY EXISTS");
}
else
{
printf("FILE DOES NOT EXIXTS");
}
}

void delete_file(char file_name[40]) //function definition: file deletion
{
union REGS regs;
struct SREGS sregs;
int ret,err;

regs.h.ah=0x41;
regs.x.dx=FP_OFF(file_name);
sregs.ds=FP_SEG(file_name);

ret=intdosx(&regs,&regs,&sregs);
err=(regs.x.cflag?ret:0);

if(!err)
{
printf("FILE DELETED SUCCESSFULLY\n");
}
else
{
printf("FILE DOES NOT EXIXTS");
}
}

void delete_directory(char directory_name[40]) //function definition: directory deletion
{
union REGS regs;
struct SREGS sregs;
int ret,err;

regs.h.ah=0x3a;
regs.x.dx=FP_OFF(directory_name);
sregs.ds=FP_SEG(directory_name);

ret=intdosx(&regs,&regs,&sregs);
err=(regs.x.cflag?ret:0);

if(!err)
{
printf("DIRECTORY DELETED SUCCESSFULLY\n");
}
else
{
printf("DIRECTORY SUCCESSFULLY DELETED");
}
}

**********************************************************************
6
ORG 0000H ;The ORG directive is used to indicate the beginning of the address
  mov 40h,#01h ;10 values for addition are moved to respective loactions
  mov 41h,#02h
  mov 42h,#03h
mov 43h,#04h
mov 44h,#05h
  mov 45h,#06h
mov 46h,#07h
mov 47h,#08h
mov 48h,#09h
mov 49h,#0ah
add A,40h ;value at lcation 40 is added in register A
add A,41h ;value at lcation 41 is added in register A
add A,42h ;value at lcation 42 is added in register A
add A,43h ;value at lcation 43 is added in register A
add A,44h ;value at lcation 44 is added in register A
add A,45h ;value at lcation 45 is added in register A
add A,46h ;value at lcation 46 is added in register A
add A,47h ;value at lcation 47 is added in register A
add A,48h ;value at lcation 48 is added in register A
add A,49h ;value at lcation 49 is added in register A
mov R6,A ;result in A is moved in R6 register
mov R7,A ;result in A is moved in R7 register
end ;end of program
*******************************************************************************
7
;Write 8051 ALP to multiply 16 bit number by 8 bit number and store 
;the result in internal memory location.

ORG 0000H
MOV A,#0EEH   ;immediate adressing: value 238 which is EE in hex moved in register A
MOV B,#0FFH ;immediate adressing: value 255 which is ff in hex moved in register B
MUL AB     ;mul is used to multiply values stored in A and B register and store it in A
MOV R0,A       ;value A is moved in register R0
MOV R1,B ;value in register B is moved in R1
MOV A,#0BBH ;immediate adressing: value 187 is moved in register A
MOV B,#0FFH ;immediate adressing: value 255 is moved in register B
MUL AB ;mul is used to multiply values stored in A and B register and store it in A
ADD A,R1 ;addtion is performed and result stored in register A
MOV R2,A ;addtion is performed and result stored in register A
MOV A,B ;value in B is moved in A
ADDC A,#00H ;0 is added in A
MOV R4,A ;value in A moved in R4 register
END ;end of program
******************************************************************
8.10kz
;Generation Of Square Wave:
ORG 0000H
MOV TMOD,#01H
BACK: MOV TL0,#075H ;B875H
  MOV TH0,#0B8H
  MOV P0,#00H   ;PORT 0 OFF TIME
  ACALL DELAY

  MOV TL0,#08H ;EA08H
  MOV TH0,#0EAH  
  MOV P0,#0FFH   ;PORT 0 ONN TIME
  ACALL DELAY
  SJMP BACK
  
  ORG 300H
  DELAY:SETB TR0 ;TO START THE TIMER 0
  AGAIN: JNB TF0 ,AGAIN ;JUMP TO THE TIMER OVERFLOW FLAG
  CLR TR0    ;STOP TIMER TR0
  CLR TF0
  RET ;RETURN TO MAIN LOOP


END
******************************************************************
9.1 Square Wave Generation using DAC
ORG 0000h ; reset entry point
mov P1,#00H ; Low value at Port1
repeat: Acall squarwave
sjmp repeat
squarwave:mov P1,#FFH ; High value at Port1
Acall delay
mov P1,#00H ; Low value at Port1
Acall delay
ret
 ; Delay Subroutine (2^8 =256) Largest Delay
delay:mov r0,#20
up2:mov r1,#250
up1:mov r2,#250
Here:djnz r2,Here
djnz r1,up1
djnz r0,up2
ret
END
***********
9.2 Tringular Wave Generation using DAC
ORG 0000h ; reset entry Point
mov P1,#00H ; starting value of port1 is 0 & It will increamenting. After reaching at
;maximum it ; will be decrementing
repeat:Acall triwave ; generate triangular wave
sjmp repeat
triwave:mov A,#00H
INCR:mov P1,A ; initialization of port P1 to 00
INC A ; increment P1 value after Increament A
CJNE A,#0FFH,INCR ; Compare first two operand if not eqaul move to offset & else
execute ;next instruction
DECR:mov P1,A ; initialization of port P1 to FF
DEC A ;Decrement P1 value after Decreament A
CJNE A,#00H,DECR
ret
END
*****************************
;9.3 Trapezodal Wave Generation using DAC
ORG 0000h ;reset entry point
mov P1,#00H ; Starting Value of P1 is 00
repeat:Acall triwave; generate Trapezoadal wave
sjmp repeat
triwave:mov A,#00H
INCR:mov P1,A
INC A ; increment P1
CJNE A,#0FFH,INCR
Acall delay ; Delay for Trapezoidal

DECR:mov P1,A
DEC A
CJNE A,#00H,DECR ; Compare first two operand if not eqaul move to offset & else
;execute next instruction
Acall delay
ret
delay:mov r0,#200 ; Delay Subroutine for 10 ms
;up2:mov r1,#10
;up1:mov r2,#10
Here:djnz r0,Here
;djnz r1,up1
;djnz r0,up2
ret
END   
*********************************
10
  ;program for stepper motor thr.port 1 of 89c51RD2V4,
;lines used p1.0 to p1.3
;motor rotates in forward direction
;to change the direction use "Reverse" look up table

ORG     0000h
SJMP    0030H

ORG     0030H


MOV  P1,#80H      ;initialise port 1                
ACALL   DELAY        ;delay 

START1:
MOV     DPTR,#REVERSE  ;load forward direction table
MOV     R7,#08H       ; steps 
NEXT:   CLR     A

MOVC    A,@A+DPTR     ; ini. A for signal.
INC     DPTR
MOV     P1,A          ; out stepper signal  to P1
ACALL   DELAY
DEC     R7
CJNE    R7,#00,NEXT         ; keep in step loop
SJMP    START1              ; keep in continous loop

DELAY:
MOV     R1,#0FFH            ; delay as per user
MOV     R2,#0FFH         ; motor speed is depend on this delay
MOV     R3,#03H         ; if you want slow speed increase delay

D1:
DJNZ    R1,D1
MOV     R1,#0A0H
DJNZ    R2,D1
MOV     R2,#0A0H
DJNZ    R3,D1
RET

FORWARD: DB 11H,13H,12H,16H,14H,1CH,18H,19H  ; forward direction  table                                                                           
REVERSE: DB 09H,08H,0CH,04H,06H,02H,03H,01H  ;revese direction table
END
************************************************




No comments:

Post a Comment