On 2017-03-02, at 13:04, Ngan, Robert wrote:
> However, I can use your code to strip the low order half off the value before
> dividing by 65536, which resolves my issue of the value being potentially
> "off by one" when a negative value is divided.
> ...
> The example "expression" I was messing with was actually SAVF4SAID_VALUE
> (i.e. C'F4SA') which when divided by 65536 gives C'F5' instead of C'F4'.
> However &M3 above generates the expected value.
>
I embellished your code to obviate the warning suppression:
MACRO
&L MVFI &TO,&IMM
.* Simulate Move Fullword Immediate with two MVHHI.
.* (Add PRINT option to taste. )
LCLC &M1,&M2,&M3
.* 16-bit signed remainder.
&M1 SETC '((&IMM)-(&IMM)/65536*65536)'
.* 16-big unsigned modulus.
&M2 SETC '(&M1+65536-(&M1+65536)/65536*65536)'
.* Top half shifted right arithmetic.
&M3 SETC '((&IMM)-&M2)/65536'
&L MVHHI &TO+0,&M3
.* Bottom half sign-extended.
MVHHI &TO+2,(&M2)-(&M2)/32768*65536
MEND
START
USING A,2
.* Test cases:
L0 MVFI A,C'F4SA'
L1 MVFI A,X'80007FFF'
L2 MVFI A,X'C0004000'
L3 MVFI A,X'4000C000'
L4 MVFI A,X'7FFF8000'
A DSECT
END
-- gil