AVR Assembly Language Program: Reading Input, Multiplying Values, and Outputting Result, Assignments of Electronics

An avr assembly language code to read values from portc and portd pins, multiply them, store the result in memory locations 0x50 and 0x51, and display the lsb byte on portb pins. It also calculates the clock cycles and delay size of the given program code.

Typology: Assignments

2019/2020

Uploaded on 02/28/2022

hamton-1
hamton-1 🇵🇰

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Deliverables
Return the word file with answer(s) attached after every question.
Rename the submission file with your name and CMS ID i.e. Ali_Haider_182313.doc
Question 1:
Construct a program code using AVR Assembly language to read the value available on PortC
pins and PortD pins. Then multiply the two values and store the result (which is 2 bytes) in the
memory location: 0x50 for LSB byte and 0x51 for MSB byte. Then show the result from LSB
byte on PortB pins.
CODE:
.org 0x00
;Setting I/O register C and D for input
LDI R16,0X00
OUT DDRC,R16
LDI R16,0X00
OUT DDRD,R16
;Setting I/O register B for output
LDI R16,0xFF
OUT DDRB,R16
;getting input from I/O ports
IN R18, PINC
IN R19,PIND
;multiplying the numbers and then storing R0 and R1
MUL R18,R19
; Then copying the LSB and MSB from R0 and R1 to given adresses
STS 0x50,R0
STS 0x51,R1
;Output LSB to I/O register B
OUT PORTB,R0
Question 2:
Calculate the clock cycles of LOOP1, LOOP2 and the overall loop (total cycles) and the size of
delay of the program code below. (Assuming Crystal frequency is 8 MHz)
Instruction Cycles
DELAY: LDI R21, 200 ;1
LOOP2: LDI R20, 250 ;1
LOOP1: NOP ;1
NOP ;1
pf2

Partial preview of the text

Download AVR Assembly Language Program: Reading Input, Multiplying Values, and Outputting Result and more Assignments Electronics in PDF only on Docsity!

Deliverables

 Return the word file with answer(s) attached after every question.

 Rename the submission file with your name and CMS ID i.e. Ali_Haider_182313.doc

Question 1:

Construct a program code using AVR Assembly language to read the value available on PortC

pins and PortD pins. Then multiply the two values and store the result (which is 2 bytes) in the

memory location: 0x50 for LSB byte and 0x51 for MSB byte. Then show the result from LSB

byte on PortB pins.

CODE:

.org 0x ;Setting I/O register C and D for input LDI R16,0X OUT DDRC,R LDI R16,0X OUT DDRD,R ;Setting I/O register B for output LDI R16,0xFF OUT DDRB,R ;getting input from I/O ports IN R18, PINC IN R19,PIND ;multiplying the numbers and then storing R0 and R MUL R18,R ; Then copying the LSB and MSB from R0 and R1 to given adresses STS 0x50,R STS 0x51,R ;Output LSB to I/O register B OUT PORTB,R

Question 2:

Calculate the clock cycles of LOOP1, LOOP2 and the overall loop (total cycles) and the size of

delay of the program code below. (Assuming Crystal frequency is 8 MHz )

Instruction Cycles

DELAY: LDI R21, 200 ;

LOOP2: LDI R20, 250 ;

LOOP1: NOP ;

NOP ;

………………...LOOPS… ………………CLOCK .CYCLES

 - DEC R20 ; - BRNE LOOP1 ;2/ - DEC R21 ; - BRNE LOOP2 ;2/ - RET ; 
  • Calculate the clock cycles of LOOP1, LOOP
    • Loop1 (250x4)-1=
    • Loop2 ((((250x4)-1)+3)x200)= - ((((250x4)-1)+3)x200)-1+4=
  • So 1602 clock cycles and 1 clock cycle (125x10)power -