From: "Tony Harminc" <[email protected]>
Sent: Thursday, 9 September 2010 7:14 AM
On 8 September 2010 15:09, Tom Marchant <[email protected]> wrote:
On Wed, 8 Sep 2010 08:35:42 -0600, Paul Gilmartin wrote:
On Sep 8, 2010, at 05:39, robin wrote:
Classic base-displacement atithmetic is always addition,
never subtraction.
Ahem.
LH R1,=H'-4096'
USING -4096,R1
LA R2,*
LA R3,-4(,R2)
What does R3 now address?
I'm surprised that this would assemble.
R:F 00000 20 USING TEST5,R15
21 *
0000 4810 F010 00010 22 LH R1,=H'-4096'
R:1 FFF000 23 USING -4096,R1
0004 4120 F004 00004 24 LA R2,*
0008 4130 2FFC FFFFFC 25 LA R3,-4(,R2)
26 *
0010 27 LTORG
0010 F000 28 =H'-4096'
I don't understand why the instruction at line 25 assembles
as 4130 2FFC. As far as I can see, it should generate an error.
I don't understand it either. Almost certainly what Paul meant to write was:
LA R3,-4(R2)
which would generate
41321FFC
Still, Robin is correct.
He's narrowly correct,
Let me assure you that he is absolutely correct.
The hardware ADDS only when the base and displacement are summed.
but in the twos complement world, addition of
unsigned values with the high bit on is equivalent to subtraction.
The base-displacement arithmetic is addition only.
Yes, it is.
The displacement is an unsigned value from 0 to 4095.
Yes, it is.
So, if the program is loaded into location 1000 and executed,
statement 24 would set register 2 to x'1004' and statement 25 would
set register 3 to x'2000'. That is, 1004+FFC.
Yes, but if the corrected code is executed, R3 will point to R2-4,
which is the start of the program, and in your example will be 1000.
If you don't believe me, try it.
The relevant part of the zArch POO puts it this way:
"In forming the intermediate sum, the base address and index are
treated as 64-bit binary integers. A 12-bit displacement is treated as
a 12-bit unsigned binary integer, and 52 zero bits are appended on the
left. A 20-bit displacement is treated as a 20-bit signed binary
integer, and 44 bits equal to the sign bit are appended on the left.
The three are added as 64-bit binary numbers, ignoring overflow."
If you prefer the earlier 32-bit version from the ESA/390 POO, it goes
like this:
"In forming the intermediate sum, the base address and index are
treated as 32-bit binary integers. The displacement is similarly
treated as a 12-bit unsigned binary integer, and 20 zero bits are
appended on the left. The three are added as 32-bit binary numbers,
ignoring overflow."
The result is the same, of course: subtraction.
The two values are SUMMED. For "summed", read "ADDITION".
It isn't subtraction.