Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you read a 16 bit number into a port and then add? I\'m so confused. Plea

ID: 2085933 • Letter: H

Question

How do you read a 16 bit number into a port and then add? I'm so confused. Please help tent/group/ELEN2006 2017Lecture not ect-p1-28.pdf C Search 16 of 28 +Automatic Zoom Exercise 1 Read a 16-bit number from port C and D into register pair R25:R24. Delay 3 clock cycles. Read a 16-bit number from port C and D into register pair R27:R26. . Add the two 16-bit numbers together and put into register Y Output result to port C and D . Carry bit should be low bit of port B Can you use ADIW? Note that this is a technical exercise to show you how managing 16-bit arithmetic works. So I am forcing you to read into one set of registers, move between registers and then do addition or the other way round. Exercise 2 Read two 8-bit numbers from port B and C into suitable registers. Do integer long division . Quotient to port C . Remainder to port D Exercise 3 Read an 16-bit numbers from port C and D, wait 4 clock cycles. Read an 8-bit number from port C. Do integer long division . Quotient to port B . Remainder to port C

Explanation / Answer

1)

In this problem, we need to read two 16bit numbers through PORT C and PORT D serially.

We will use Port C to read the 8bit msb and Port D for the 8bit lsb. Firstly, we will read the first 16bit number and store it in the registers R25(msb) and R24(lsb). After a 3 cycle delay, we will read the second 16-bit number in the same manner and store them in R27(msb) and R26(lsb).

===== ASSEMBLY CODE ========

.ORG 00

MAIN:

LDI R16, 0xFF ; Load 0b11111111 in R16

OUT DDRB, R16 ; Configure PORT B as an OUTPUT port

LDI R16, 0x00 ; Load 0b00000000 in R16

OUT DDRC, R16 ; Configure PORT C as an INPUT port

LDI R16, 0x00 ; Load 0b00000000 in R16

OUT DDRD, R16 ; Configure PORT D as an INPUT port

IN R25, PINC; Loading the first 16 bit number in r25 and r24

IN R24, PIND

NOP ; 3 Cycle delay

NOP

NOP

IN R27, PINC; Loading the second 16 bit number in r27 and r26

IN R26, PIND

ADD R26,R24 ; adding the lsb 8bits

ADC R27,R25 ; adding the msb 8bits with carry

LDI R16, 0xFF ; Load 0b11111111 in R16

OUT DDRC, R16 ; Configure PORT C as an OUTPUT port

LDI R16, 0xFF ; Load 0b11111111 in R16

OUT DDRD, R16 ; Configure PORT D as an OUTPUT port

OUT PORTC, R27 ; output result 8bit msb to PORT C

OUT PORTD, R26 ; output result 8bit lsb to PORT D

BRCC nocarry

LDI R16, 0x01

OUT PORTB, R16 ; output carry bit as 1bit lsb of PORT B

nocarry:

======================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote