On Wed, 21 Feb 2007 10:48:10 -0800, Charles Mills wrote:

>I'm trying to port an S/390 assembler routine to Visual Basic. VB has no
>shift operators. I'm trying to simulate SRL R6,8
>
>
>
>No need to know Visual Basic, just pretend the following is pseudo-code. 
R6
>is defined as a signed, 32-bit (31-bit in 390-speak) integer. The VB seems
>to work correctly; I'm not asking for VB help. I'd just like any of the
>mathematicians on the list to tell me if my logic, especially for negative
>values, is correct. I'm worried that I may have missed some boundary
>condition. (This code could be shortened to one line, but I did it this 
way
>to make the logic and the debugging clearer.)
>
>
>
>        ' Simulate a shift right logical 8
>
>        If R6 >= 0 Then
>
>            R6 = R6 \ 256     ' \ is integer division
>
>        Else
>
>            R6 = R6 \ 256   ' \ is integer division
>
>            R6 = R6 - 1
>
>            R6 = R6 And &HFFFFFF        ' Equivalent to S/390 X'FFFFFF'
>
>            End If
>

I  don't think you want the "R6 = R6 - 1". And if you drop it, you may as 
well rethink whether you want the if/else at all, and just do the "And" 
whether it's needed or not.

I'm not a mathematician, nor do I know Visual Basic, but the result 
produced by this VBS script may be relevant.

R6 = -512
R6 = R6 \ 256 And &Hffffff
Wscript.echo R6

I'm pretty sure this script uses signed 32-bit integers, because it won't 
run if i try to set R6 to a value > 2147483647. I picked -512 (hex 
fffffe00) as a test value, expecting a result of hex 00fffffe which is 
decimal 16777214, and 16777214 is indeed the result displayed by "cscript 
srl.vbs" from the command prompt.

Bill

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html

Reply via email to