what does insturction LD.SH means?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi,

just got so confused about the LD.SH instruction,
from the description of this instruction:

Quote:

LD.SH – Load Sign-extended Halfword
Architecture revision:
Architecture revision1 and higher.
Description
Reads the halfword memory location specified and sign-extends it.
Operation:
I. Rd ← SE( *(Rp) );
Rp ← Rp + 2;
II. Rp ← Rp - 2;
Rd ← SE( *(Rp) );
III. Rd ← SE( *(Rp + (ZE(disp3) << 1)) );
IV. Rd ← SE( *(Rp + (SE(disp16)));
V. Rd ← SE( *(Rb + (Ri << sa2));

Does it means read a halfword from a memory location and sign-extends it?

and what does this code means?

ld.sh	r0,r0[0x0]

Cheng

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, it means what you think it means. In the instruction set descriptions, SE() means Sign Extend and ZE() means Zero Extend.

"ld.sh r0, r0[0x0]" means "Load the halfword (16 bits) located at the address (r0 + 0), sign-extend it, and store the result in r0."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, then what's the initial value in r0 at the following code?

80000000 <_trampoline>:
80000000:	e0 8f 10 00 	bral	80002000 
	...

80002000 :
80002000:	48 1f       	lddpc	pc,80002004 
80002002:	00 00       	add	r0,r0
80002004:	80 00       	ld.sh	r0,r0[0x0]
80002006:	23 b4       	sub	r4,59

Is it 0? if it is, then this "add r0,r0" did nothing, right?
And this "ld.sh r0,r0[0x0]" read the memeory address 0x00000000 into r0, right? So what's is inital value in memeory location 0x00000000 then?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, I got the right answer from another post.
[url]
https://www.avrfreaks.net/index.p...
[/url]