I need to know the result of the following sequence of Mainframe Assembler instructions:
LA 0,1
LA 1,2
MR 0,0
Is it:
(a) R0=0, (b) R0=1, (c) R0=2, (d) S0C6
The answer will be (a) R0 = 0
According to the POP, the multiplicant is in bit positions 32-63 of R1 (the odd register of the even-odd register pair 0/1). As is the multiplier in case of the MR instruction.
The result interestingly is placed in R0 (the even register of the even-odd register pair 0/1) which contains 0.
Nice puzzle and not obvious.
The answer is "(a)". Register 0 will have a value of 0 after the multiply.
Explanation for "MR x,y" when "x" and "y" are the same register: It doesn't actually multiply the register by itself (although you'd naturally think it does) because the first operand (multiplicand) is actually in R₁+1 while the second (multiplier) is in R₂:
See Principles of Operation,7.5.52 MULTIPLY
...The multiplicand is taken from general register R₁+1.
So, when MR specifies the same register for both operands, the values for the multiplicand and multiplier can actually be totally different!
In IBM's Principles of Operation manuals, the convention for register naming uses a subscript equal to the position of the register in the instruction. So, "MR R₁,R₂" (sub1,sub2) just means the instruction specifies two registers, with "R₁" the first and "R₂" the second. Some instructions, like BXH and BXLE, even specify three registers, in which case the third is designated R₃.
But "R₁" isn't necessarily "Register 1". In fact, for MR, it must not be, since the first operand specifies an "even register of an even-odd pair", the "odd" part being "R₁+1". And quite surprisingly, the value in "R₁" itself plays no part in the calculation! It only serves to specify the 64-bit register pair into which the 64-bit result is is placed. Regardless of whether it contains a zero value, a non-zero value, or even a negative value, it will not change the outcome of the instruction!
So, while "MR 0,0" would appear to calculate the square of an identity, it actually calculates the product of two separate values: one in R₁+1 and the other in R₂, which may be totally different! Here's a direct link to the MR instruction specification in the ESA/390 Principles of Operation. ESA/390 was a 32-bit architecture which makes the descriptions easier to understand than those in the z/OS (64-bit) manuals: [PoP]http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR001/7.5.52
And thanks to IBM's stubborn insistence on upward compatibility, the effective result of every machine instruction defined here is exactly the same today as it was then, indeed for every machine instruction since System/360 (1964).
LA 0,1. First argument should be a register. - akg