Page 2 of 5

Re: Mainframe Assembler Macro

PostPosted: Sat Nov 26, 2011 9:01 am
by steve-myers
There is an example of using Exclusive OR to swap memory in the Opcode: BXLE topic, though I suspect you never bothered to read it.

Re: Mainframe Assembler Macro

PostPosted: Sun Nov 27, 2011 5:50 am
by deathwish73
I needed help in writing a program that can iterate from 1 to 500 and display the prime numbers on the DOS Screen, in Mainframe Assembler.

Here's what I tried out so far, I need help in organizing it, it does not run:

This loop runs COUNT through all values 1 to 100

ZAP COUNT,=P'1'
TOPLOOP EQU *
...LOOP BODY HERE
AP COUNT,=P'1'
CP COUNT,=P'100'
BNH TOPLOOP

COUNT DS PL3 PUT THIS IN THE VARIABLE SECTION

This code checks to see if the COUNT field is divisible by 2,3...,COUNT - 1

ZAP I,2 START WITH 2 AS THE DIVISOR I
PRIMECHK EQU * LOOP THROUGH 2,3,...,COUNTM
ZAP WORK,COUNT PREPARE TO DIVIDE
DP WORK,I DIVIDE BY I
CP REM,=P'0' IS REMAINDER ZERO?
BE NOTPRIME IF SO... NOT PRIME
AP I,=P'1' IF NOT... TRY NEXT NUMBER
CP I,COUNT REACHED THE COUNT?
BE PRIME YES ... ITS PRIME
B PRIMECHK NO...TRY NEXT NUMBER

NOTPRIME EQU *


WORK DS 0PL6 MORE VARIABLES...
QUOT DS PL3
REM DS PL3
I DS PL3

Re: Mainframe Assembler Macro

PostPosted: Sun Nov 27, 2011 6:18 am
by BillyBoyo
deathwish73 wrote:I needed help in writing a program that can iterate from 1 to 500 and display the prime numbers on the DOS Screen, in Mainframe Assembler.

Here's what I tried out so far, I need help in organizing it, it does not run:

This loop runs COUNT through all values 1 to 100

          ZAP  COUNT,=P'1'
TOPLOOP   EQU   *         
          ...LOOP BODY HERE
          AP   COUNT,=P'1'
          CP   COUNT,=P'100'
          BNH  TOPLOOP
         
COUNT     DS   PL3         PUT THIS IN THE VARIABLE SECTION                   

This code checks to see if the COUNT field is divisible by 2,3...,COUNT - 1

          ZAP  I,2              START WITH 2 AS THE DIVISOR I
PRIMECHK  EQU  *                LOOP THROUGH 2,3,...,COUNTM
          ZAP  WORK,COUNT       PREPARE TO DIVIDE
          DP   WORK,I           DIVIDE BY I
          CP   REM,=P'0'        IS REMAINDER ZERO?
          BE   NOTPRIME         IF SO... NOT PRIME
          AP   I,=P'1'          IF NOT... TRY NEXT NUMBER
          CP   I,COUNT          REACHED THE COUNT?
          BE   PRIME            YES ... ITS PRIME
          B    PRIMECHK         NO...TRY NEXT NUMBER
         
NOTPRIME  EQU  *

         
WORK      DS  0PL6        MORE VARIABLES...
QUOT      DS   PL3
REM       DS   PL3         
I         DS   PL3


Firstly, notice the power of the Code button.

Secondly, how does it not run?

Thirdly, why is your algorithm different from the C# example that you wrote?

Re: Mainframe Assembler Macro

PostPosted: Sun Nov 27, 2011 6:29 am
by deathwish73
It does not run because how can we fix it to take care of primes from 1 to 500?

Also, where is the output going to be displayed, there is no WTO Statements.

Re: Mainframe Assembler Macro

PostPosted: Sun Nov 27, 2011 6:46 am
by BillyBoyo
There is not much point in practicing WTO, in the real world you'll get your legs chopped off for using it. Why not just write the results to an output file, you can always TYPE that to your DOS screen, or whatever.

In your code snippets you are using 100 as your value. Change that to 500.

There is even another topic which, copying judiciously, would give you code for the output file.

You can stick with your packed loop-control for now, but it is an uncommon way to do it. Get the logic working, then change the loop-control(s) to binary.

Why is the algorithm not like the C#?

Put your primecheck in the body of the loop, do it 500 times, get yourself an output file, write the primes to it, you should basically have something running then. Then you'd go back and do it again with a bit more thought about some of the details about how things can be done in Assembler, and about how to implement algorithms.

Re: Mainframe Assembler Macro

PostPosted: Sun Nov 27, 2011 1:30 pm
by deathwish73
So, the code will work for 500, if I change the 100 above to 500?

Also, my algorithm is not like the C# since it was hard to do using Assembly. Don't know how to do it.

Can you show how to do the program more efficiently? I did it, above and you said it wasn't efficient.

Re: Mainframe Assembler Macro

PostPosted: Sun Nov 27, 2011 3:43 pm
by BillyBoyo
deathwish73 wrote:So, the code will work for 500, if I change the 100 above to 500?

Also, my algorithm is not like the C# since it was hard to do using Assembly. Don't know how to do it.

Can you show how to do the program more efficiently? I did it, above and you said it wasn't efficient.


I'm saying you can change the test for 100 to 500 and you should be able to get the code working, following the other suggestions.

The algorithm you used already is not difficult if you hunt around for some examples (like the same place with the printer output).

I didn't say if wasn't efficient, I said it is not usual to use decimals for loop-control. I also suggested you get it working "as is" and then look to change it.

Try to put it all together - plan it out, think about how it should go (why did you think it wouldn't be able to work for 500? or any other value?). You should be able to get something from it. Once you do, then you can think about how to do it in other ways, but if you try that now, you'll likely get confused.

Re: Mainframe Assembler Macro

PostPosted: Mon Nov 28, 2011 4:09 am
by deathwish73
I need help in writing a program that can convert km/hr to mi/hr.

I have the following snippet below:
 MP    EARNINGS,TAXRATE
         MVC   OEARN(16),=XL16'40202020202020206B2020204B202020'
         ED    OEARN(16),EARNINGS
   
  WTO   ' '         
EOFRTN   WTO   OEARN
         WTO   'End of Program Execution'   
       
         L     13,SAVEAREA+4
         LM    14,12,12(13)
         BR    14

EARNINGS DC    PL7'172245'
TAXRATE  DC    PL3'125'
OEARN    DS    CL16

SAVEAREA DS    18F
         END   


and NEED Help in Formating it to do what I want. Is this a forum to help me do the assignment or argue ?

Re: Mainframe Assembler Macro

PostPosted: Mon Nov 28, 2011 5:36 am
by Robert Sample
Why are you posting code snippets dealing with earnings and taxes if you want to convert km/hr to mi/hr? How are you getting your input? Will you just have one input or will there be multiple km/hr to convert in one run of the program? What kind of output do you want? The actual conversion is trivial but since it involves floating point numbers, what have you done already (if anything) with floating point numbers in Assembler? How accurate do the results need to be?

In other words, you are complaining about not getting any help -- yet there is a tremendous amount of information you have not yet provided, and it is not at all clear at this point if you are looking for a km - mi conversion program or a program to compute taxes on earnings. Perhaps if YOU took the time to fully and clearly explain what you are attempting to achieve, you could get more assistance? But be aware that you will not get complete code here -- we provide assistance and replies that just give you the code don't help you learn, and tend to get deleted anyway.

Re: Mainframe Assembler Macro

PostPosted: Mon Nov 28, 2011 6:21 am
by deathwish73
I need help in modifying the program that I did with earnings and taxes to something that can handle a conversion from km/hr to mi/hr.

I am struggling with how to define an arbitrary input constant, call it K, that we just need to multiple K by 0.624 to get into mi/hr and WTO on the screen.

The results don't need to be too acurate. Can you please demonstrate? Learning to me comes when I can remove the stress of the due date of this assignment than I can fully concentrate, which I can do when I look at a solution.