Scripter9700
Scripter9700

Reputation: 81

AVR Assembly: What will be the address in the jmp and rjmp instructions?

I've been given a code that goes like this:

140 Back: jmp Forward

142 add

143 add

.

. There are a total of 80 add instructions that go on like this

.

222 lds

224 lds

226 lds

.

. There are a total of 300 lds instructions that go on like this

.

822 Forward: rjmp Back

Which memory location's address will be stored in the jmp instruction in the 140th line and the rjmp instruction in the 822nd line? Will rjmp store address of 822-140 = 682 or 823-140 = 683 (given that PC+1).

Upvotes: 0

Views: 1467

Answers (1)

David Grayson
David Grayson

Reputation: 87486

I think those numbers at the beginning of each line of this homework problem are not line numbers, but program counter values (i.e. addresses of words in flash, where each word is two bytes).

The jmp instruction stores absolute addresses, so the jmp Forward instruction will simply store the number 822.

The rjmp instruction stores a number k, and causes the program counter (PC) to change to PC + k + 1. So we have to solve for k, knowing that the PC is 822 initially and it must change to 140. So we know 140 = 822 + k + 1, and therefore k = 140 - 822 - 1 = -683.

Upvotes: 1

Related Questions