0
votes

I am stuck on the following code and don't have a basic understand of how it works?

Determine the decimal value of r22 after the following line of code is executed:

clr r22  

dec r22

push r22

dec r22

pop r5

value of r22 = ?

2
Why not run it to find out? - Michael
The AVR Instruction Set starting page 11 should give a listing of exactly what the instructions do. - Vlad

2 Answers

1
votes

Well, just work through each instruction one at a time and figure out what each one does.

  1. clr r22: This sets the register to 0.
  2. dec r22: This decrements it, so it underflows from 0 to 255.
  3. push r22: This pushes 255 (r22) onto the stack.
  4. dec r22: This decrements r22, so r22 is now 254.
  5. pop r5: This pops a value (255) off the stack and stores it in r5, not affecting r22.

So, unless I got something wrong, the answer is r22 = 254.

0
votes

The register(in 8bit) goes from 0 to FF(dec r22) to FE(dec r22)

If r22 is 4 bit then E = 14

If r22 is 8 bit then FE = 254

if r22 is 16 bit then FFFE = 65534

and so on

A processor register is like a car mileometer When it reaches 99,999 miles it goes forwards to 00000

A register reaches F-F-F-F, 15-15-15-15 (not 9-9-9-9 because it's hex not decimal) and when we +1 it returns to 0-0-0-0