tnt400.com - AS/400 Tips And Techniques

Sponsored by news400.com

This page is a discussion on the mentioned topic.
Most of the answers are in their original posted form, including any technical/spelling/grammatical errors.
No guarantees are expressed or implied. :-)
Comments, corrections, concerns about this tip?

Got another AS/400 question? Ask it here


What's New?
See what's new at Tips-N-Tech.

AS/400 Tips-N-Tech
AS/400 tips, techniques, and FAQ. Updated frequently.
CODEPage/400
All the code samples you can eat! RPG, CL, DDS, etc. etc.
AS/400 FAQs
The official news400.com FAQs.






All AS/400 Tip Categories / AS/400 Programming / AS/400 'machine language' - MI Programming


Question:

Hi as i am often at AS/400 shops that only have an RPG compiler, i'd like to start learning MI to be able to do things i'd otherwise only could do in C/C++. Now i am not afraid of MI, but i need some information to get started. I (nor any of the shops i've ssen so far) dont have the "Machine Interface Functional Reference" which is referred to extensively in the API books. This book is NOT on the Online Reference Library CD's , nor is it on the IBM rochester FTP site (as far as i know). Can anyone tell me where i can obtain the book (in electronic or paper form, any version) or advice other reading? Or does anyone perhaps have a list of operation codes that can help me get started?? tnx very much in advance…


Answer(s):



> Can you tell us more about W-code? W-code is a platform independent intermediate language that is output by most of IBM's more recent compilers on multiple platforms. It is then processed by a platform specific back-end (the bit we refer to as the translator on the AS/400). There are back-ends for Win 95, OS/2, Win 3.1, etc. etc. It is much more of a 'nuts and bolts' assembler type language than the old MI. MI instructions are of the "Move Universe from A to B" type. W-code instructions are more itsy-bitsy. W-code is not a published interface, but it can be obtained by folks who want to write compilers etc. for the platform.




In the System API Programming guide chapter 5 contains a very brief introduction to MI programming. Here you also have all the information for a 'do it yourself' MI compiler. However for real programming you need the Functional Reference. The Functional Reference is NOT complete, in the sense that OPCODES reserved for use by IBM (system state programs) are not listed. However the opcodes that are listed are not likely to be changed in the curent millenium. I found that I can sometimes achieve an incredable performance gain by putting SELECTED parts of an application in MI. Especially manipulating Independent Indexes is much faster than using workfiles, of using Indexes with help of the appropriate API, which is incredibly slow. Also MI can be used to retrieve lots of information from a job, or from the system. For instance it can easily be seen how many pagefaults your jobs caused, or how many CPU milliseconds it used. I have used this for performance testing applications that themselves were written in RPG. A very simple MI program can even retrieve information from the system operator panel, like how your key is turned in your machine (if you still have one of those models).




QPROCT ("Program Operation Code Table" ??) in QSYS (type x'19DA') contains all valid MI op-codes. There's a lot of the op-codes from the S/38 days that can only be used by system domain programs, and the Create Program API won't recognize them. Database access, create program, etc. is probably considered too "dangerous" (or simply makes it too easy to violate system security or database integrity). Even IBM's compilers doesn't access the DB opcodes directly, but rather through programs QDB*. It's safer to use a HLL like RPG to access files, and use MI for the utlity/system related stuff.




> ...... all the compilers generate MI code if they changed MI > a lot, they would need to change all the compilers Just a couple of points. First only the _old_ compilers generate MI. All of current compilers (C, C++, CL, COBOL/400, RPG IV) generate W-code, not MI. Second, the compiler writers are protected from potential changes to MI (or more often to the control blocks etc.) by macros. Even when changes occur, by changing the macro we avoid changes in code. I agree though that MI is not likely to go away any time soon. Jon Paris - Toronto Lab




Do you know of any 3rd Party publications that might be useful aside from the IBM book I know of and looking at NEWS/400 articles? Like I said in my previous post, the IBM book (Machine Interface Functional Reference) really gets you nowhere.




Well, that struck me. :-) Not that I'm going to dive into MI after that, but it was a nice reading. As some say here : oooole tus huevos!




Right, but still, there are things you can do with MI at such a speed you can't do with anything else. We have been doing heavy MI development for years, and the difference is huge. However, we do system tools here, so the investment in manuals, training, and testing pays for itself. Outside the tool development, MI can help you to speed up certain critical functions of your applications... but try other languages first. There is more myth on the "release dependant" issue of MI than reality. Our software run untouched from V1R2 (yeah, I mean Version One Release Two) with the sole exception of two instructions (out of hundreds of thousands lines) that we use for speeding up system internal things, that you are not (definitely) going to use in a business application program (hey, not a surprise here: all the compilers generate MI code - if they changed MI a lot, they would need to change all the compilers - and the beauty of the AS/400 is MI - its machine independant interface). And we achieved subsecond response times in complex Client/Server transactions, for instance, thanks to the MI compiler. But MI *is* complex. You can buy the book (MI Functional Reference) from IBM, but it is not a tutorial. IBM will not help you either. There was a company (Monahon I think) that sold a MI compiler with a handbook, but I don't know if they still are on business (look for them on the NEWS/400 Sourcebook). Good MI examples appeared from time to time on AS/400 magazines as NEWS/400 and MC. You can learn a lot from inspecting the the RPG compiler output in MI. You are going to need a good interactive source debugger as well (the IBM provided debugger will not work). If you need a good one, send me a message, I know a great one. If you, in the end, start a MI programming career, welcome to the club!




He *doesn't* have a C compiler at his shops. ;D. That was his question. Anyway, I don't understand why someone wants to write legacy soft *on the AS* in C. Particulary on the AS, whose C compiler is really indecent and whose C++ environment requires aprox 50x (sum soft, CPU & workstations needed) investment as on any other machine. And if it isn´t legacy soft, well, why have you to recompile it for every customer? I don't know what you're doing, JimBob19, but I'm sure you have a better solution behind you as rewriting in MI code, which is machine & release dependent. Tell us some more.




If you can do it in C then do it in C. You can order the Machine Interface Functional Reference book from your local IBM literature service. I had this book at my previous work place and found it more than lacking. It only describes a few select system mmemonics such as MATMATR (materialize machine attributes) but certainly doesn't give you any information on how to change any settings on your /400 or even something "simple" as to create an object. (Even though they use the CRTS (create space) OP in their sample programs!) There is as certain *DTAARA in the QSYS library which contains the names of all MI mmemonics known to the system MI compiler (It starts with Q ;-) I don't remember the rest though). Just a fraction of these are documented in above mentioned publication. BTW I heard of a 3rd party MI compiler that has aside from the OPS I just mentioned lots of IBM undocumented MI OPS in it. You might want to check for that.




For kicks-n-giggles, I wrote an RPG that used most (all the standard) of the OPCODEs to get work done in RPG, then compiled the program with MI output it's on of the options on the compile. I then took a look at the code. And decided to skip it... Too much like JCL for me... 8-)




There are other problems too, for instance objects previously available via MI, can no longer be accessed as they're now in the 'System Domain' (I think it's called) and you get object violations if you go near them.




contact IBM, I think you can order this book. and as far as I know MI is release-dependent, opcodes may change without notice.!





Other tips in this category:

Click here to see all categories.

Socket Programming And Timeout Issues
Deleting Duplicate Records From A Table
What are data queues and how to use
Retrieving SMTP Name
RPGLE example for Dynamic Screen Manager API
Calling APIs from CL - with examples!
Compare two strings in RPG character by character
How to search all pgms in QCLSRC for a keyword
Retrieve Database File Description (QDBRTVFD) API
How to redirect the output to STDERR from RPG-IV
Using Multiformat Logical To Join 2 Identical File
D-Spec *LIKE DEFN
RPG: Converting Character to Decimal
Example of ILE RPG CGI Program
Handling ILE RPG Numeric Overflow
Help with Subfile Programming in RPG III
Zoned parameter in ILE RPG
What's the best way to do modulus in CL?
RPG Nesting Source Print Utility
More on changing the SIGNON screen
A silly ILE RPG question
Calling Validation List API From ILE RPG
Soft Coding Module Names
RPG Multidimensional Arrays in Action
Build a Page-Equals-Size Lookup Window
Procedures within an ILE RPG program
Break msg from RPG
Source Debugger for batch jobs
RPGLE debugging
Timing out display sessions in DDS
Building Dynamic Stored Procedures
Put Message in System Log
Dynamic RPGSQL
Randomize function for the AS/400
What's the fastest way to do a simple RPG lookup?
First time Data queue application in RPG
Print file overflow in ILE RPG
Mapping Fields To Arrays in ILE RPG
Named inidicators
STRQMQRY: comparision operator '=' isn't correct?!
DSPDTAARA to an outfile - possible?
PCL ESC codes in RPG
Sharing DB files between two AS/400s
Help: AS/400 subfiles
How do you change the signon screen?
Determining Even/Odd Values in queries
Get day of the week in RPG
Convert UPPERCASE to lowercase
RPG IV help using APIs
Help with data area API
Detecing IFS Files from RPG
SQL in a CL program
Calling AS/400 APIs from ILE RPG
CVTDAT command to convert an *MDY to a *LONGJUL
CPYSPLF Automation
Subfile Window background problem
Using IFS APIs w/ ILE RPG
Packed or unpacked fields?
QRYDFN to source and back
What does the "optimize" parm do?
Determining the calling program
Sockets in RPG?
Sorting a user space
OVRDBF and SECURE() keyword in an ILE environment
RPG record locking
RPG Differences: V2R3 to V3R2 upgrade
Getting the relative record number (RRN)
What is the longest parameter usable in RPG?
A C function that returns a string to an RPG pgm
Problems with ZADD *ZEROS
Can you highlight code in SEU?
Reusing deleted records - OK?
Is there an easy way to change edit codes?
Help - Windowed Subfiles
Logical Files and DDS
AS/400 'machine language' - MI Programming
Library lists and performance
How to use ERRSFL
Updating in CL
Record lock wait time
Message subfile problem
Physical File Joins
CL: Copying User Profiles
Commands and PARM
ILE RPG, RPG IV, vs. RPG/400
RPG and subfiles
Multiple subfiles
Field masking for passwords
SFLMODE keyword in an ILE program
Subfile size
Color coding records in a subfile
MSGLINE in windows
Controlling cursor movement on a display file
API returns error! Why?
Put an RPG Program on the Web
Variable length records in RPG
Differences Between RPG400, RPG IV, and ILE RPG


You are at a news400.com site.
Contact Us | Report Bugs | Submit Comments/Suggestions | Read Site Use Agreement | Read Privacy Policy
Copyright © 2000 Duke Communications International.
This site is best viewed with the latest versions of Netscape or Internet Explorer, 800 x 600 resolution (or higher), and at least 256 colors.
Duke Communications   NEWS/400 | 29th Street Press | Business Finance | DominoPro | Selling AS/400 Solutions | SQL Server Magazine | Windows NT Magazine