Mainframe Assembler Macro



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

Re: Mainframe Assembler Macro

Postby steve-myers » Mon Nov 28, 2011 7:33 am

We do not do homework.

Your conversion factor is close, but not 100% accurate, though it's more accurate than what I use for a rough estimate: multiply km/hr by 5/8. Since you say you do not have to be accurate I guess it's close enough. Any time you have fractions and want to do fractional arithmetic with fixed point arithmetic you have problems. How do you handle this issue in C? You follow the same procedure in Assembler.

After you do the multiply you most likely divide the result by 1000, though, of course, you can handle this issue in the output format. There are two ways to do this: the Divide Decimal (DP) instruction, or the Shift and Round (SRP) instruction to shift the number 3 digits to the right since you are dividing by 1000. Both instructions present problems: DP because you have to allow for a remainder, and SRP because the method to specify a right shift isn't very clear in Principles of Operation.

Unfortunately Principles of Operation isn't very helpful in telling you how to specify a right shift in SRP, so I will tell you a simple way: specify 64-n in the shift amount field in the instruction, where n is the number of digits to shift.

For what it's worth, WTO xxx, where xxx is the name of a storage area will not work, for two reasons. First, while you can specify a storage area, you specify it differently. Second, the storage area must be formatted very precisely. Look at how the storage area in something like WTO 'message text' is formatted, and you'll have the idea.
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Re: Mainframe Assembler Macro

 

Re: Mainframe Assembler Macro

Postby steve-myers » Mon Nov 28, 2011 11:35 am

Basic WTO macro with included text. Lines that start with a + are the macro expansion.
          WTO   'MESSAGE TEXT'
+         CNOP  0,4
+         BAL   1,IHB0001A
+         DC    AL2(16)
+         DC    B'0000000000000000'
+         DC    C'MESSAGE TEXT'
+IHB0001A DS    0H
+         SVC   35
The BAL instruction stores the address of the message buffer into register 1.

WTO macro specifying remote text.
          WTO   MF=(E,WTOBUF)
+         LA    1,WTOBUF
+         SVC   35
          ...
 WTOBUF   WTO   'MESSAGE',MF=L
+WTOBUF   DS    0F
+         DC    AL2(11)
+         DC    B'0000000000000000'
+         DC    C'MESSAGE'
The first DC defines the length of the message buffer, and includes the length of this prefix. The second DC defines 2 bytes of binary 0s. The third DC defines the message text.

Formatting output is one of the more difficult tasks of an Assembler programmer. Sadly, there are no IBM provided general purpose tools for this task. It's probably too complex!
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Mainframe Assembler Macro

Postby dick scherrer » Mon Nov 28, 2011 11:45 am

Hello,

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.
Unfortunately, that is not learning, but rather coasting. . . Deadlines are a basic part of our profession.

As mentioned, wo don't do homework, but will work with you to make progress.

As this was started more than 10 days, more effort on your part would possibably (probably) have reduced the stress level. Ift is somewhat a guarantee that if you are not persistent in trying things, no one here is going to push you.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Mainframe Assembler Macro

Postby NicC » Tue Nov 29, 2011 1:19 am

New problem should be a new topic.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: Mainframe Assembler Macro

Postby steve-myers » Tue Nov 29, 2011 10:29 am

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.
I've been there myself when I started, but, as Mr. scherrer says, you learn more by doing something, and doing it wrong and starting over. I learned some 7040 Assembler by reviewing the "Assembler" code the 7040 Fortran compiler wrote, but I really learned it by writing programs or Assembler subroutines. Sometimes you learn by reading over your programs and deciding how to do it better.
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Mainframe Assembler Macro

Postby deathwish73 » Thu Dec 01, 2011 2:32 pm

          PRINT NOGEN
****************************************************************
*        FILENAME:  PRIME Number                              *
****************************************************************
          START 0


*Information is needed to restore control to OS when
*Program ends!         
          STM   14,12,12(13)
          BALR  12,0
          USING *,12
          ST    13,SAVEAREA+4
          LA    13,SAVEAREA

*This loop runs COUNT through all values 1 to 500


           ZAP  COUNT,=P'1'
TOPLOOP   EQU  *         
  AP   COUNT,=P'1'
         
           ZAP  I,1              *START WITH 2 AS THE DIVISOR I
PRIMECHK   EQU  *                *LOOP THROUGH 2,3,...,COUNT
  AP   I,=P'1'          *IF NOT... TRY NEXT NUMBER
  CP   I,COUNT
  BNL  PRIME
 
PRIME  EQU  *

           ZAP  WORK,COUNT       *PREPARE TO DIVIDE
           DP   WORK,I           *DIVIDE BY I
           CP   REM,=P'0'        *IS REMAINDER ZERO?
  BE   NOTPRIME
 
               B    PRIMECHK         *NO...TRY NEXT NUMBER

NOTPRIME   EQU  *

           CP   COUNT,=P'500'
  MVC  VAR1,=C'402020202020'
  ED   VAR1,COUNT

  WTO  VAR1
           BL   TOPLOOP


  L    13,SAVEAREA+4
  LM   14,12,12(13)
  BR   14
SAVEAREA DS   18F
 

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

COUNT      DS   PL3
VAR1  DS   CL6


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



This is what I have so far on the Prime number program. It prints out 444444 and abends.

And the logical error I need help in fixing comes from:

PRIMECHK   EQU  *                *LOOP THROUGH 2,3,...,COUNT
                       AP   I,=P'1'          *IF NOT... TRY NEXT NUMBER
                      CP   I,COUNT
                      BNL  PRIME
 
PRIME  EQU  *


So, BNL branches to PRIME if the condition code is not low. If it is low, we fall through the branch and end up at PRIME. In other words, no matter what happens we're always going to go to PRIME.

I need help in fixing this logical error. I thought of of replacing BNL Prime with BNH Prime, BL Prime, etc.
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

Re: Mainframe Assembler Macro

Postby enrico-sorichetti » Thu Dec 01, 2011 2:36 pm

                      BNL  PRIME
 
PRIME  EQU  *


does it occur to You that after the branch and before the PRIME label there should be the instructions to process the <other> case ?

it looks like You are doing some patchwork and not programming.
for a beginners before starting writing code it would be wiser to write the pseudo code ( express in plain words the program logic flow )
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Mainframe Assembler Macro

Postby deathwish73 » Thu Dec 01, 2011 2:40 pm

I have a program where we need to convert (have not learned user input) miles/hr to km/hr in assembly.

THe program runs, but it looks wrong. Can someone explain to me how to fix it and what is wrong? Thanks


         PRINT NOGEN                                                   
****************************************************************
*        FILENAME: Convert MI/HR to KM/HR                      *
*        AUTHOR  :                        *
*        SYSTEM  :  pc/370                                     *
*        REMARKS :  Conversion Program                         *
****************************************************************
         START 0                                                       
         REGS
         STM   14,12,12(13)
         BALR  12,0
         USING *,12
         ST    13,SAVEAREA+4
         LA    13,SAVEAREA   
***************************************************************
* Convert Miles/Hour to Km/Hr
***************************************************************
    DP    EARNINGS,CONST   
         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    PL10'172245'
TAXRATE  DC    PL3'624'
CONST    DC    PL4'1000'
OEARN    DS    CL16

SAVEAREA DS    18F
         END   
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

Re: Mainframe Assembler Macro

Postby deathwish73 » Thu Dec 01, 2011 2:42 pm

enrico-sorichetti wrote:
                      BNL  PRIME
 
PRIME  EQU  *


does it occur to You that after the branch and before the PRIME label there should be the instructions to process the <other> case ?

it looks like You are doing some patchwork and not programming.
for a beginners before starting writing code it would be wiser to write the pseudo code ( express in plain words the program logic flow )



OK, so then, I would add a statement just below BNL PRIME that says: BL PRIMECHECK

That would be it?
deathwish73
 
Posts: 17
Joined: Fri Nov 18, 2011 2:20 am
Has thanked: 0 time
Been thanked: 0 time

Re: Mainframe Assembler Macro

Postby enrico-sorichetti » Thu Dec 01, 2011 2:56 pm

/repeat on
before starting writing code write the pseudo code ( express in plain words the program logic flow )

if the BNL will get You out of the <loop>

why not use a BL to branch to the beginning of the loop
and fall thru in the other case ( BNL )
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2643
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

PreviousNext

Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post