Mainframe Assembler Macro



High Level Assembler(HLASM) for MVS & VM & VSE

Re: Mainframe Assembler Macro

Postby steve-myers » Sat Nov 26, 2011 9:01 am

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.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Mainframe Assembler Macro

Postby deathwish73 » Sun Nov 27, 2011 5:50 am

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
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

Re: Mainframe Assembler Macro

Postby BillyBoyo » Sun Nov 27, 2011 6:18 am

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?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Mainframe Assembler Macro

Postby deathwish73 » Sun Nov 27, 2011 6:29 am

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.
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

Re: Mainframe Assembler Macro

Postby BillyBoyo » Sun Nov 27, 2011 6:46 am

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Mainframe Assembler Macro

Postby deathwish73 » Sun Nov 27, 2011 1:30 pm

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.
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

Re: Mainframe Assembler Macro

Postby BillyBoyo » Sun Nov 27, 2011 3:43 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Mainframe Assembler Macro

Postby deathwish73 » Mon Nov 28, 2011 4:09 am

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 ?
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

Re: Mainframe Assembler Macro

Postby Robert Sample » Mon Nov 28, 2011 5:36 am

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Mainframe Assembler Macro

Postby deathwish73 » Mon Nov 28, 2011 6:21 am

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.
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

PreviousNext

Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post