Page 1 of 5

Mainframe Assembler Macro

PostPosted: Fri Nov 18, 2011 2:25 am
by deathwish73
Hi,
I needed help in defining a macro called SWITCH that will interchange the contents of 2 fullwords in storage.

This is Mainframe Assembler IBM PC 370.

Thanks

Re: Mainframe Assembler Macro

PostPosted: Fri Nov 18, 2011 2:47 am
by enrico-sorichetti
and what has this to do with DFSORT/ICETOOL

using the basic good manners of posting in the proper forum will make helping You a pleasure rather than a pain in the ...

anyway Your request is not really a help request, rather a request for a complete solutions

edited quickly to add ...
what knowledge do You have about writing macros
what is You knowledge if logic operators
what is Your knowledge of register operations

there are three ways of doing it
1) 3 exclusive OR
2) 3 moves using an intermediate work variable
3) 1 load 1 move 1 store ( using a register instead of the work variable )

option 3 works on up to 64 bits operands , for longer operands only options 1 and 2 are available

Re: Mainframe Assembler Macro

PostPosted: Fri Nov 18, 2011 2:48 am
by dick scherrer
Hello and welcome to the forum,

How much experience using or creating macros do you have? If this is your first attempt, suggest you read about Macros for the assembler you are using before building one. Your topic has been moved to the Assembler part of the forum.

You might also look here:
http://www.les-smith.com/software/assembler/macros.htm

Simply said, you would define a work area and then move from the first fullword to the work area. Move the second fullword to the first fullword. Then move the work area to the second fullword. Expanded just a bit, you can switch data that is longer than a fullword.

I suspect SWITCH will work - we used SWAP (unconditional) once upon a time :) We also supported CSWAPHI and CSWAPLO (swap when a > b and when a < b. Actually, these were not macros, but instructions we incorporated into the application development language specification.

Good luck :)

Re: Mainframe Assembler Macro

PostPosted: Fri Nov 18, 2011 6:20 am
by steve-myers
We do not do homework.

Re: Mainframe Assembler Macro

PostPosted: Fri Nov 18, 2011 10:43 am
by dick scherrer
Hello,

Yup, we won't actually do the homework - but we will help when you get stuck or have problems.

To get this help, one needs to post what they have tried and what went wrong or where they are stuck.

Re: Mainframe Assembler Macro

PostPosted: Sat Nov 26, 2011 6:47 am
by deathwish73
The following below is not a homework assignment but just a book exercise for practice.

Can someone explain how to print out the prime numbers from 1 to 500 on the DOS Screen?

I can do this comfortably using C# as below, but need help in doing this using MAINFRAME ASSEMBLY.


using System;

class Program
{
static void Main()
{
//
// Write prime numbers between 0 and 100.
//
Console.WriteLine("--- Primes between 0 and 100 ---");
for (int i = 0; i < 100; i++)
{
bool prime = PrimeTool.IsPrime(i);
if (prime)
{
Console.Write("Prime: ");
Console.WriteLine(i);
}
}
//
// Write prime numbers between 10000 and 10100
//
Console.WriteLine("--- Primes between 10000 and 10100 ---");
for (int i = 10000; i < 10100; i++)
{
if (PrimeTool.IsPrime(i))
{
Console.Write("Prime: ");
Console.WriteLine(i);
}
}
}
}

Class that contains IsPrime [PrimeTool.cs, C#]

using System;

public static class PrimeTool
{
public static bool IsPrime(int candidate)
{
// Test whether the parameter is a prime number.
if ((candidate & 1) == 0)
{
if (candidate == 2)
{
return true;
}
else
{
return false;
}
}
// Note:
// ... This version was changed to test the square.
// ... Original version tested against the square root.
// ... Also we exclude 1 at the very end.
for (int i = 3; (i * i) <= candidate; i += 2)
{
if ((candidate % i) == 0)
{
return false;
}
}
return candidate != 1;
}
}

Re: Mainframe Assembler Macro

PostPosted: Sat Nov 26, 2011 6:49 am
by deathwish73
About the Macro

Can you please explain how to:

there are three ways of doing it
1) 3 exclusive OR
2) 3 moves using an intermediate work variable
3) 1 load 1 move 1 store ( using a register instead of the work variable )

Illustrate the move Macro with one of the following techniques?

Re: Mainframe Assembler Macro

PostPosted: Sat Nov 26, 2011 7:30 am
by steve-myers
deathwish73 wrote:The following below is not a homework assignment but just a book exercise for practice. ...
Most of us would regard this as homework.

Re: Mainframe Assembler Macro

PostPosted: Sat Nov 26, 2011 8:08 am
by deathwish73
It's not homework, I swear. And I would greatly appreciate your help on this, PLEASE

Re: Mainframe Assembler Macro

PostPosted: Sat Nov 26, 2011 8:31 am
by Robert Sample
there are three ways of doing it
1) 3 exclusive OR
2) 3 moves using an intermediate work variable
3) 1 load 1 move 1 store ( using a register instead of the work variable )
1. Google is your friend. Googling swap memory xor find 1,770,000 hits and the very first one explains it clearly.
2. You cannot figure out how to use a temporary variable to hold one of the values, move the other to that variable, then move the temporary variable to the second variable? Are you sure you should be in IT at all if such simple logic escapes you?
3. Hint: fullwords in memory are, conveniently, the same size as registers. Knowing that and finding a solution to #2 will allow you to easily find this method as well.

Doing the prime problem in Assembler is tedious but not difficult. Assembler requires a lot of other code around the actual algorithm for control mechanisms. How long it would take depends upon your level of expertise with Assembler -- based upon what you've posted so far, count on weeks or months of effort to write and debug the code.