Question
Please help by showing steps.
Question 4. (continued) (b) Consider a 16-bit binary number stored in AVR registers r15:r14 which the programmer considers to
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//i am asuming you are willing to find out how the 2 programs work
1.

    Ser r16
    Mov r15,r16
    Mov r14,r16

explaination:
    here first instruction is Ser ie set all bits
    setting all bits means 1111111111111111
    which is in 2's compliment form
    equivalent decima number of this is -1
    so we are loading -1 in r16

    2nd and 3rd instructions are Mov, here 1st register is destination and 2nd is source
    hence we are putting -1 in both registers r14 and r15


2.

    Mov r17,r15
    Mov r16,r14
    Lsl r14
    Rol r15
    Lsl r14
    Rol r15
    Add r14,r16
    Add r15,r17

explaination:
    1st and 2nd are Mov instructions as described above, here we are loading r17 with r15 and r16 with r14
  
    3rd instruction is Lsl, lets see what it does:
    Shifts all bits in R14 one place to the left. Bit 0 is cleared. Bit 7 is loaded into the C flag of the status register
    This operation effectively multiplies r14 by two.

    next instruction is Rol which is Rotate Left trough Carry, let's see what it does:
    Shifts all bits in r15 one place to the left. The C flag is shifted into bit 0 of Rd. Bit 7 is shifted into the C flag

    as this is mentioned that r15 is most significant byte so what we are doing with Rol is multipliying it by two with
    carry generated through Lsl

    so till now we have multiplied r14:r15 with two

    next 2 instructions are again Lsl and Rol which again multiplies r14:15 by two

    so till now we have multiplied r14:r15 with four

    next two instructions are Add instructions where we are adding r16 to r14 and r17 to r15

    equivalent high level code:
                                                r17=r15
                                                r16=r14
                                                r14=2*r14
                                                r15=2*r15
                                                r14=2*r14
                                                r15=2*r15
                                                r15=r15+r17
                                                r14=r14+r16

    so finally we have multiplied r14:r15 by 5

COMMENT DOWN FOR AN QUERY

PLEASE GIVE A THUMBS UP

Add a comment
Know the answer?
Add Answer to:
Please help by showing steps. Question 4. (continued) (b) Consider a 16-bit binary number stored in AVR registers r1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT