Port-vax archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Help decoding a vax instruction




> On Sep 28, 2019, at 3:03 PM, Maciej W. Rozycki <macro%linux-mips.org@localhost> wrote:
> 
> On Wed, 21 Aug 2019, coypu%sdf.org@localhost wrote:
> 
>>> I'm a vax newbie. What does this one do?
>>> 
>>>   c:	98 40 a0 02 	cvtbl 0x2(r0)[r0],15 <e+0x15>
>> 
>> Managed to find
>> https://www.cs.auckland.ac.nz/references/macvax/indexed-address-mode.html
>> which seems to say
>> convert byte to long
>> src = 0x2 + r0 + [r0 * operand size]
>> dest = 0x15
>> 
>> The 0x15 amount makes more sense if I consider it's gcc -c output, so
>> it's going to be a real address after linking probably (?).
> 
> There's probably a relocation attached to the operand; use `objdump -dr' 
> to see the relocation.  The dump above has the bytes of the second operand 
> removed, however the whole instruction could possibly look like:
> 
>   c:	98 40 a0 02 	cvtbl 0x2(r0)[r0],15 <e+0x15>
>  10:	ef 00 00 00
>  14:	00
> 			11: R_VAX_PC32	foo+0x15
> 
> where `15' (hexadecimal) is merely an addend to the symbol `foo', which as 
> you correctly expect will be resolved and the final value of the operand 
> calculated and pasted into the operand by the linker.
> 
> HTH,
> 
>  Maciej

In this particular case, it's an efficient way to use r0 as the index of an array with two-byte entries.  The (r0) adds the contents of r0 to the base address (2) and [r0] then adds to that r0 times the operand size.  In this case, the operand is a byte so its size is one.  Net result is that the address is 2 * r0 + 2.  And that fits the source code shown, where a "short" array is indexed by a+1.

Somewhere in the VAX documentation is a discussion of this sort of trickery.  It can be used with the load-address instructions to do multiply by various small integers, possibly with another integer added in.  For example:

	moval  42(r0)[r0], r1

which means:

	r1 = r0 * 5 + 42;

    paul



Home | Main Index | Thread Index | Old Index