Re: Address computation



[Superseding prior response, typo in example.]

Tim Frink <plfriko@xxxxxxxx> writes:
Hi,

the ISA of my processor can handle immediate operands of max.
16bits. So, to store a 32bit base pointer into a 32bit address
register, the manual suggest the usage of a combination of two
instructions:

MOVH AREG, ((absolute address+0x8000)>>16) & 0xFFFF and
LEA AREG, AREG (off16) # off16 = (absolute address & 0xFFFF)

where
* the absolute address is 32bit,
* MOVH moves the 16bit value of the second operand to the
most-significant half-word of AREG and set the least-significant
16 bits to zero.
* LEA computes the effective address with
effective address = second AREG + sign_ext(off16);
^^^^^^^^

first AREG = EA[31:0];

The thing I don't understand here is the addition of 0x8000 in
the MOVH instruction before shifting. Why is this done? If the
16th bit is already 1 in the value of absolute address, then
the addition would also modify the most-significant 16 bits.

If bit 15 (value 8000) is 1, then sign extension would add
ffff0000, which is subtracting 10000. So you need to add
1 to the value loaded into the top 16 bits to ensure it's
10000 higher.

Just try it with the example 00008000 to see why it works.

Phil
--
Dear aunt, let's set so double the killer delete select all.
-- Microsoft voice recognition live demonstration
.



Relevant Pages

  • Re: Address computation
    ... the ISA of my processor can handle immediate operands of max. ... most-significant half-word of AREG and set the least-significant ... the MOVH instruction before shifting. ... 16th bit is already 1 in the value of absolute address, ...
    (alt.lang.asm)
  • Address computation
    ... the ISA of my processor can handle immediate operands of max. ... most-significant half-word of AREG and set the least-significant ... the MOVH instruction before shifting. ... 16th bit is already 1 in the value of absolute address, ...
    (alt.lang.asm)