Experiment No.1 Aim:: Perform Addition, Subtraction, Multiplication, Division and Store Result in Memory
Experiment No.1 Aim:: Perform Addition, Subtraction, Multiplication, Division and Store Result in Memory
1 AIM:
Perform addition, subtraction, multiplication, division and store result in memory.
CODE:
org 0000h op1 equ 0b4h op2 equ 40h mov r0,#50h ;--------------------Addition clr c mov a,#op1 mov b,#op2 add a,b mov @r0,a ;--------------------Subtraction inc r0 clr c mov a,#op1 subb a,b mov @r0,a ;--------------------Multiplication inc r0 mov a,#op1 mul ab mov @r0,a inc r0 mov @r0,b ;--------------------Division inc r0 mov a,#op1 mov b,#op2 div ab mov @r0,a r0 inc r0 mov @r0,b r0 end ;using directives
;addition (a+b) ;store result in RAM memory location pointed to by r0 ;increment pointer
;subtraction (a-b) ;store result in RAM memory location pointed to by r0 ;increment pointer ;multiplication (a*b) ;store result in RAM memory location pointed to by r0 ;store result in RAM memory location pointed to by r0 ;increment pointer
;division (a/b) ;store result (quotient) in RAM memory location pointed to by ;increment pointer ;store result (remainder) in RAM memory location pointed to by
OUTPUT:
CODE:
org 0000h op1 equ 50h op2 equ 65h clr c mov r0,#op1 mov r1,#op2 mov r2,#10 l1: mov a,@r0 rrc a byte inc r0 jnc l2 djnz r2,l1 sjmp next l2: rlc a mov @r1,a inc r1 djnz r2,l1 next: nop end ;using directives
;clear carry flag ;load pointer. R0=50h, RAM location ;load pointer. R1=65h, RAM location ;loading counter for scanning 10 bytes
;rotating value in regiater a with carry to right to identify even or odd ;increment pointer ;if carry bit is 0 jump to l2 ;loop until counter = 0 ;short jump to next ;rotate left with carry to retain byte in regiater a ;move the byte to new location in RAM ;increment pointer ;loop until counter = 0
OUTPUT:
CODE:
org 0000h ;--------------------All ON and All OFF m: mov r0,#04 ;load counter m1: mov P0,#00h ;all on call delay ;delay called to retain output for visible amount of time mov P0,#0ffh ;all off call delay ;delay called to retain output for visible amount of time djnz r0,m1 ;loop until counter = 0 ;--------------------Alternate ON mov r0,#04 ;load counter m2: mov a,#0aah ;alternate on and off mov P0,a call delay ;delay called to retain output for visible amount of time mov a,#55h ;alternate on and off mov P0,a call delay ;delay called to retain output for visible amount of time djnz r0,m2 ;loop until counter = 0 ;--------------------Sequential ON mov r0,#04 ;load counter m3: mov r1,#08 ;load counter mov dptr,#mydata ;load ROM pointer m4: clr a movc a,@a+dptr ;move data from code space mov P0,a call delay ;delay called to retain output for visible amount of time inc dptr djnz r1,m4 ;loop until counter = 0 djnz r0,m3 ;loop until counter = 0 sjmp m ;--------------------delay function defination delay: mov 31h,#0ffh l1: mov 31h,#99h djnz 30h,$ djnz 31h,$ ret ;--------------------On-chip code space used for store data mydata: db 0feh,0fdh,0fbh,0f7h,0efh,0dfh,0bfh,7fh end
OUTPUT:
CODE:
org 0000h main: mov P1,#0ffh mov a,P1 mov r0,#00h mov r1,#04h clr c check: rrc a jnc next inc r0 next: djnz r1,check rrc a cjne r0,#01h,error swap a mov P2,a sjmp main ;-------------------ERROR error: mov P2,#00h sjmp main end ;configure P1 as input port ;take key input ;set error check counter ;initialize counter
;check for multiple key press ;light the LED corresponding to key pressed ;repeat
OUTPUT: