0% found this document useful (0 votes)
67 views

Arithematic and Logical Instruction 1.write A Program To Add 25 To The Day of Your Birthday and Save The Result in R20

The document contains several code snippets related to arithmetic, logical, and bitwise operations in AVR microcontrollers. It includes programs to: 1) Add numbers and save results 2) Toggle pins on and off 3) Monitor bits and send output based on bit values 4) Check bytes in memory and save/reject based on bit values

Uploaded by

Uzef Sheikh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Arithematic and Logical Instruction 1.write A Program To Add 25 To The Day of Your Birthday and Save The Result in R20

The document contains several code snippets related to arithmetic, logical, and bitwise operations in AVR microcontrollers. It includes programs to: 1) Add numbers and save results 2) Toggle pins on and off 3) Monitor bits and send output based on bit values 4) Check bytes in memory and save/reject based on bit values

Uploaded by

Uzef Sheikh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

ARITHEMATIC AND LOGICAL INSTRUCTION

1.Write a program to add 25 to the day of your birthday and save the result in R20

Output:

2.Write a program to add following number and save result in R20


Output:

3.

5.show how 64/4 in the AVR

2.BIT AND BIT SET INSTRUCTION

1.write a program to toggle PB3 and PB5 continously without disturbing the rest of
the pins

Output:
2.write a program to toggle PD3,PD7 and PC5 continously without disturbing the
rest of the pins

Output:
.
3.Write a program to monitor bit PC3. When it is HIGH send 0X55 to port D
CBI DDRC,3 ; set pc 3 as input
LDI R17,0XFF ; R17 =FFH
OUT DDRD ,R17 ; set PORT D as output
CHECk:
SBIS PINC ,3 ;Skip next instruction if PC3 is 1
RJMP CHECK ; Relative jump to CHECK
LDI R18,$55;R18=55H
MAIN:
OUT PORT D,R18 ; set PORTD to 55H
RJMP MAIN ; jump to main

4. ;write a program to monitor bit PB5 and PB6 ,when both of


them is high send 0xAA AND otherwise $AA to portC
write a program that find number of one in given byte

Output:
;A set of eight data bytes is stored in the memory locations
starting at 2100H. Check
;each data byte for bits D7 and D0. If D7 or D0 is 1, reject
the data byte; otherwise, store
;the data bytes at memory locations starting at 2150H

; Created: 9/25/2020 9:31:48 AM


; Author : uzef sheikh
;

; Replace with your application code


ldi R16,$80 ;R16 =80H
ldi R17,$52 ;R17 =52H
ldi R18,$E8 ;R18 =E8H
ldi R19,$78 ;R19 =78H
ldi R20,$F2 ;R20 =F2H
ldi R21,$67 ;R21 =67H
ldi R22,$35 ;R22 =35H
ldi R23,$62 ;R23 =62H
ldi yh,21
ldi yl,$00
st y+,R16 ;store indirect and post increment of R16
st y+,R17 ;store indirect and post increment of R16
st y+,R18 ;store indirect and post increment of R16
st y+,R19 ;store indirect and post increment of R16
st y+,R20 ;store indirect and post increment of R16
st y+,R21 ;store indirect and post increment of R16
st y+,R22 ;store indirect and post increment of R16
st y,R23 ;store indirect and post increment of R16
ldi Xh,21
ldi Xl,$50

CHECK:
SBRS YL,7 ;skip in bit if YL=7
SBRC YL,0 ;skip in bit if YL=0
RJMP NEXT ; relative jump to NEXT
RJMP STORE ; relative jump to STORE

NEXT:
INC YL ;increment Yl
RJMP CHECK ; relative jump to CHECK

STORE:
st XL,YL
INC XL ;increment Xl
RJMP NEXT ; relative jump to NEXT
;A string of readings is stored in memory location, starting at
2100H. The end of
;string is indicated by byte ODH. Write a program to check each
byte in the string,
;and save the bytes between the range of 30H to 35H (both
inclusive) in memory
;locations starting form 2150H.

; Created: 9/25/2020 9:31:48 AM


; Author : uzef sheikh
;
ldi R16,$24 ;R16 =24H
ldi R17,$27 ;R17=27H
ldi R18,$30 ;R18 =30H
ldi R19,$31 ;R19 =31H
ldi R20,$32 ;R20 =32H
ldi R21,$35 ;R21 =35H
ldi R22,$39 ;R22 =39H
ldi R23,$42 ;R23 =42H
ldi R24,$43 ;R24 =43H
ldi R25,$0D ;R25 =0D
ldi yh,21
ldi yl,$00
st y+,R16 ;store indirect and post increment of R16
st y+,R17 ;store indirect and post increment of R17
st y+,R18 ;store indirect and post increment of R18
st y+,R19 ;store indirect and post increment of R19
st y+,R20 ;store indirect and post increment of R20
st y+,R21 ;store indirect and post increment of R21
st y+,R22 ;store indirect and post increment of R22
st y+,R23 ;store indirect and post increment of R23

st y+,R24

st y,R25
ldi Xh,21
ldi Xl,$50

CHECK:
SBRC YL,5 ;skip in bit if YL=5
SBRS YL,4 ;skip in bit if YL=4
RJMP NEXT ; relative jump to NEXT
RJMP STORE ; relative jump to STORE

NEXT:
INC YL
RJMP CHECK ; relative jump to CHECK
STORE:
st XL,YL
INC XL
RJMP NEXT ; relative jump to NEXT
;Write a program to add the following data bytes stored in memory
locations starting
;from 2100H, and store the sum at 2150H. If carry is generated store
00H at 2150H.

;Data(H); 32, 47, 39, 22, f3, D7

ldi R16,$80
ldi
R17,$32
ldi R18,$47
ldi R19,$39
ldi R20,$22
ldi R21,$F3
ldi R22,$D7
ldi R23,$00
ldi yh,21
ldi yl,$00
st y+,R16
st y+,R17
st y+,R18
st y+,R19
st y+,R20
st y+,R21
st y,R22

ldi Xh,21
ldi Xl,$50
st y+,R23

CHECK:

ADC XL,YL
INC YL
SBRS SREG,C
RJMP CHECK
RJMP SR
SR: LDI
XL,00H INC XL
RJMP NEXT
;A set of eight readings is stored in the memory location
starting at 2150H. Write a
;program to check whether a byte 40H exists in the set. If it does,
stop checking and
;store it at 2160H, otherwise store 00H
ldi Xh,21
ldi Xl,$50
ldi Yh,21
ldi Yl,$60
CHECK:

SBRS XL,8
SBRS XL,7
RJMP CHECK2
RJMP STORE
CHECK2:
SBRS XL,6
SBRS XL,5
SBRS XL,4
SBRS XL,3
SBRS XL,2
SBRS XL,1
SBRS XL,0
RJMP STORE
RJMP NEXT
NEXT:
INC XL
RJMP CHECK
STORE:
MOV YL,XL

You might also like