Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

avr - What are the addresses of r10 and r20 in this assembly code?

When I look at this AVR assembly code with its equivalent (partially completed) address and binaries on I cannot figure out which registers are supposed to be r10 and r20. What I can figure out is, at least I believe, that registers X and Y are $004A and $004B respectively

Assembly code

question from:https://stackoverflow.com/questions/65950241/what-are-the-addresses-of-r10-and-r20-in-this-assembly-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In AVR architecture the registers are located at the first 32 address in data memory space as appears in the following picture.

enter image description here

the address of the register could be representable in 5 bits in the instruction opcode to know exactly where is the 5 bit in the opcode, you have to look at AVR instruction set Manual and see every instruction binary

for example if you look at the page 115 in the manual you will see the translation in binary for LDi instruction which is limit you to only access the upper 16 register (from r16 to r31) the 16 is represented only in the 4 bit, so it appears in the third Nibble as litter d (d abbreviation for "destination register") Note: if dddd bits take one value from 0000 to 1111 this will map from r16 to r31


I cannot figure out which registers are supposed to be r10 and r20

let us manually translation this code ClR R10 to opcode to figure out the answer

in the manual (page 71) you will find that the ClR is Just EOR (Exclusive OR) which mean

clr R10
; is same opcode as 
EOR R10,R10

now try to found EOR translation instead of ClR, in manual (Page 91) you will found the following

EOR Rd,Rr
;will translat to 
;0010 01rd dddd rrrr

now replace RdandRr with r10 (r10 in binary will be 01010) so the output will be

;be carful in bits location
;the bits are mixed
0010 01rd dddd rrrr  
0010 0100 1010 1010

this is the translate of CLR R10

now try to translate ROR r20 by yourself (hint : ROR in page 145)


What I can figure out is, at least I believe, that registers X and Y are $004A and $004B respectively

this is not correct, X Y and Z registers are actually pairs of r27:r26, r29:r28 and r31:r30 registers

indirect store instruction ST will be translated for different opcode depend on which pairs are selected (x, y, z work as alias for these pairs) and you could see them in pages 173-177 in the manual

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...