The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: hfheatherfox07 on August 22, 2011, 01:58:36 AM

Title: irvine32 To MASM32
Post by: hfheatherfox07 on August 22, 2011, 01:58:36 AM

Hi there ...

I run into example from time to time that use "irvine32.inc".... and I downloaded the irvine32 package ..... I like MASM better

my question is this ; is there a formula of includes from MASM that make up "irvine32.inc" so I can use those .asm's ....

For example do this in MASM32 ( very short ASM) http://www.youtube.com/watch?v=KVd811eWs3I

thanks
Title: Re: irvine32 To MASM32
Post by: dedndave on August 22, 2011, 02:29:28 AM
i think all of Kip's functions have a masm32 counterpart
however, there are a number of differences in how he writes and calls functions
generally, Kip preserves all registers, unless one is used to return a value (usually EAX, but not always)
parameters are passed in register, rather than on the stack

so, you have to familiarize yourself with both libraries to make a translation
but, it can be done, and shouldn't be too difficult
Title: Re: irvine32 To MASM32
Post by: hfheatherfox07 on August 22, 2011, 02:32:46 AM
I noticed that there are a lot of proc's for stuff that can be called as a window function instead ....although in irvine32 they are written out! can't remember  a specific example off  the top of my head right now but I remember it had to do with consoles....
Title: Re: irvine32 To MASM32
Post by: MichaelW on August 22, 2011, 02:37:56 AM
Within limits it is possible to combine the two. For example, I was able to make this code work:

include Irvine32.inc
includelib irvine32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib
.data
    x REAL8 -250.0
    y REAL8 100.0
    z REAL8 ?
    fmt db "%f%c"
.code
start:
    fld x
    fld y
    fdiv
    fstp z
    invoke crt_printf, ADDR fmt, z, 10
    call DumpRegs
    call WaitMsg
    exit
end start


But I can't recall if I had to make changes to the Irvine32 library to make this work, and there will be major problems if you try to combine the MASM32 windows.inc with the Irvine32 SmallWin.inc. I think the easiest solution would be to create your own MASM32-compatible versions of the Irvine32 macros/procedures that you wish to use, and forget about Irvine32.



Title: Re: irvine32 To MASM32
Post by: dedndave on August 22, 2011, 02:53:34 AM
in the context of a learning tool, Kip's libraries make it easy for beginners to understand how the pieces fit together
the functions are written in a simple "building block" style
and, they make it fairly easy for those who were familiar with 16-bit DOS code

one approach that comes to mind, following what Michael mentioned, would be to make
"wrappers" for masm32 functions that make them behave like Kip's functions
Title: Re: irvine32 To MASM32
Post by: hutch-- on August 22, 2011, 03:16:44 AM
D yourself a favour here and don't follow an architecture that is so old. 32 bit Windows code is put together in a particular way that is dictated by (1) the Intel ABI (application binary interface) and (2) the Windows API that are ABI compliant.

If there is something in Kip's library that you want to emulate, rewrite it in modern ABI complaint format.
Title: Re: irvine32 To MASM32
Post by: baltoro on August 22, 2011, 08:33:40 PM
HFHEATHERFOX07,   
We've had a whole bunch of threads here in the Campus about using Kip Irvine's library and his procedures. It can be problematic for a number of reasons, the essentials of which, Dave described above. If you use the forum search feature, and provide 'irvine' for the subject to search for, and, just search the Campus, you will get a long list of threads discussing typical problems.
I have Kip Irvine's book myself, and have used his code examples in compiled MASM programs. They work, but tend to be as simple as possible to illustrate the concept from the book. And, the MASM32 library and the source code examples provided have similar procedures and macros, so there is definitely some overlap.
The single biggest problem for beginners is using include files from both Irvine and the MASM32 project in their programs. When you do that, without thinking about what those include files specify, you will multiply define numerous standard Windows symbols and Win32 API function names, producing a long list of confusing errors.
Title: Re: irvine32 To MASM32
Post by: hfheatherfox07 on August 22, 2011, 11:11:11 PM
Thank you all for the replies .....

I thought that there was a set of includes that would substitute irvine32 , just so I can assemble some of the examples that I find that use  irvine32... with masm32....
I was looking to completely substitute  irvine32 with masm32 , not combine them....

Just love hutch's masm32 package , I can't see my self using any thing else now.... :bg
Title: Re: irvine32 To MASM32
Post by: dedndave on August 22, 2011, 11:43:02 PM
in a way - it isn't all bad to learn both   :P
the reason i say that is - by playing with both, you learn how and why they are different
that, in itself, is a big lesson in assembly language

you will see the difference in how parameters are passed and returned
Title: Re: irvine32 To MASM32
Post by: baltoro on August 22, 2011, 11:43:58 PM
Typically, when writing a MASM32 program, the first line of the assembly file is:    
include \masm32\include\masm32rt.inc

If you read the masm32rt include file, you will find a number of standard MASM include files and corresponding libraries listed at the beginning. The best programming method is to use this pattern, and then, if you want to use some of Kip Irvine's procedures from his library, just copy the entire procedure and paste it into your program file (you may also have to write a Prototype). Frankly, you're better off just using the MASM32 libraries, procedures and macros,...they're better written and much more reliable than Kip Irvine's code. Also, Kip's code is designed to work only with Kip's other procedures in his library,...so, that if you mix some of Kip's code with MASM code, they often will conflict,...unless you rewrite the code to be compatible and work correctly in sequence.
Title: Re: irvine32 To MASM32
Post by: dedndave on August 22, 2011, 11:46:01 PM
well - i can see a need to pick up Kip's libraries
and, there is no reason you can't do both - i have used both, and it wasn't that big of a deal   :bg  (just not together)

the advantage of using Kip's libraries is you get to follow along with his book   :U
Title: Re: irvine32 To MASM32
Post by: baltoro on August 22, 2011, 11:51:31 PM
Well, actually Dave's code is better than Kip's. :eek
Just search the campus forum using Dave's "dedndave" handle and an asterisk for the subject, and you'll get all of Dave's greatest hits.
Title: Re: irvine32 To MASM32
Post by: dedndave on August 22, 2011, 11:52:23 PM
.....which aren't widely accepted
Title: Re: irvine32 To MASM32
Post by: baltoro on August 22, 2011, 11:54:59 PM
Here are some good examples illustrating the differences between Irvine code and MASM32 code:   
Flipping an Array Around (http://www.masm32.com/board/index.php?topic=16750.0)
How Do You Read a String Into an Array? (http://www.masm32.com/board/index.php?topic=16561.0)
Counting, Adding and eax Invalid Instruction (http://www.masm32.com/board/index.php?topic=16572.0)
Accessing and Array Issue (http://www.masm32.com/board/index.php?topic=16544.0)
Array Question (http://www.masm32.com/board/index.php?topic=16540.0)
Trying to Understand Randomize and Unsigned?? (http://www.masm32.com/board/index.php?topic=16528.0)
Irvine32 Nightmare (http://www.masm32.com/board/index.php?topic=16511.0)
Title: Re: irvine32 To MASM32
Post by: hfheatherfox07 on August 23, 2011, 12:09:52 AM
Quote from: baltoro on August 22, 2011, 11:43:58 PM
if you want to use some of Kip Irvine's procedures from his library, just copy the entire procedure and paste it into your program file (you may also have to write a Prototype).


I tried that a few times ...did not work for me at all ....

I ended up copying one thing which needed another sub proc ,which needed another, etc...

the assembly became ridiculously huge  :(

it would be nice if there was a set of masm32 includes like the masm32rt.inc... that will allow to assemble irvine's examples ...
Title: Re: irvine32 To MASM32
Post by: baltoro on August 23, 2011, 12:16:34 AM
INCLUDE Irvine32.inc
Title: Re: irvine32 To MASM32
Post by: dedndave on August 23, 2011, 12:22:58 AM
welllllll
you might give this a try
it may not work for all examples - hell, it may not work at all - lol

in the Irvine32.inc file, there is a line near the beginning
INCLUDE SmallWin.inc

you might be able to comment that line out
then, in your asm source file....
        INCLUDE    \masm32\include\masm32rt.inc
        INCLUDE    Irvine32.inc
        INCLUDELIB Irvine32.lib


from there, you are likely to get a few errors
take them one at a time and sort them out
the first error listed is usually the best one to fix first

it will be a good lesson in debugging   :bg

i'd be surprised if there weren't a few naming conflicts
Title: Re: irvine32 To MASM32
Post by: Tedd on August 23, 2011, 12:14:40 PM
Assuming I were crazy enough to write it (I am), would you want a drop-in replacement, or a lib that provides the same functions implemented in an Masm32 compatible way?
Title: Re: irvine32 To MASM32
Post by: dedndave on August 23, 2011, 01:25:54 PM
well - i think the idea is to have Kip's examples work
whether you write wrappers for masm32 functions to emulate Kip's functions
or convert Kip's library to work with masm32

of course, many of his examples are 16-bit - at least that reduces the number we have to make work   :bg
i found them, someplace - i can post them if you like
Title: Re: irvine32 To MASM32
Post by: hfheatherfox07 on August 24, 2011, 12:31:59 AM
In this case ... I just decided to write it masm
Title: Re: irvine32 To MASM32
Post by: dedndave on August 24, 2011, 01:46:15 AM
a good choice   :U

you won't regret it
and, you won't regret learning about Kip's libraries, either
Title: Re: irvine32 To MASM32
Post by: hfheatherfox07 on August 26, 2011, 12:33:30 AM
Quote from: dedndave on August 24, 2011, 01:46:15 AM
a good choice   :U

you won't regret it
and, you won't regret learning about Kip's libraries, either

:red I am a little embraced  :red that I was so concentrated with  trying to convert this that I did not read the code, and realize how easy it would be to write in MASM....

Title: Re: irvine32 To MASM32
Post by: hutch-- on August 26, 2011, 10:28:18 AM
Something to keep in mind, Win32 is a standard set in the portable executable standard and the Intel ABI, learn good habits and it will come back to you in terms of reliability and performance. Avoid sloppy code that pushed all registers with PUSHAD and POPAD and do it properly.


    push ebx
    push esi
    push edi

  ; write your code here

    pop edi
    pop esi
    pop ebx


If none of these 3 registers are used in the algo then you don't have to preserve and restore them. learn to use memory operands with LOCAL scope, if your algo needs to be faster you start with memory operands then shift to registers one you have it up and running properly. There are many more tricks but the base line is master the standard interface for procedures first so you have fast reliable code.