News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Irvine32 nightmare

Started by bcddd214, April 20, 2011, 11:55:20 PM

Previous topic - Next topic

bcddd214

For the first time, I understand the procedure calls.

dedndave

yah - most of Kip's library functions are passed parameters in register
that is the old way of doing things - DOS INT 21h, as well as most other INT dispatchers work the same way

for newer code, win32 API especially, functions are passed parameters on the stack - that is what INVOKE is all about
        INVOKE  SomeProc,Parm1,Parm2
actually generates code that looks like this
        push    Parm2
        push    Parm1
        call    SomeProc

the API functions balance the stack for you upon exit
for C functions, the caller has to balance the stack, although there are wrappers that can do it for us

baltoro

bcddd214,
Kip's library does actually work, but, he designs it to be as simple as possible. He also designs the routines within to work specifically with other routines in his library,...so, (as you noticed) they often don't work with other routines written by other programmers (for instance, the MASM32 package).
I got the impression when I read the book that he first started teaching assembly programming in 16-bit real mode, and then added 32-bit routines to his repertoire in order to present a more complete coverage of the current Intel !A-32 instruction set. After Windows 98, the newer versions of the Windows operating system were designed to be exclusively 32-bit platforms. And, in Windows XP and later, the system will not even execute an application coded in 16-bit real mode (a DOS emulator is used instead).
And, Irvine doesn't cover any of the more advanced instruction sets. The best source for these is: Intel 64 and IA-32 Architecture Software Developer's Manuals, which are a free download (but, considerably more cpmplex than Irvine).
If you want to be able to integrate Irvine's library routines and routines from the MASM32 libraries, the solution is simple. Just copy and paste the individual Irvine routine code (starting from the PROC directive and continuing to the ENDP directive, so that you have the complete block) into the .code section of your program, and supply a PROC function prototype at the beginning of your file,...and then, merely comment out the line: "include Irvine32.inc" at the start of your file. This is pretty easy, if you only are calling a few routines from the Irvine library. All the code will be in one continuous file,...it will be more straightforward to edit and update, and you won't have to link explicitly to Irvine's LIB and DLL files from the command line or in a makefile.
By compiling all of his routines into one DLL, Irvine is just trying to demonstrate the correct usage of the INVOKE technique,...which you will use quite frequently in assembly programs because it is convenient and because many useful routines already exist for common assembly language problems. Read through the code supplied with the various MASM 32 libraries and macros, and you will learn alot about efficient coding techniques that is not explained in Irvine's book.
Baltoro

dedndave

yah - i think you're right
also - he wanted to adapt the already written 16-bit book for 32-bit without a total re-write
the "pass parms in regsiter" and "preserve all registers" approach is not really a win32 thing   :P
but, it made it easier to get a 32-bit book out of a 16-bit one

most forum members use the masm32 libraries
what that means is, you will get a wider range of support from members by using it

that by no indicates that masm32 is without flaws, either
certain aspects of the include files are not really ideal
on the other hand, many of the routines are super-fast and well-written
still, a lot of programmers use the masm32 libraries, macros, and include files
that means that people viewing your code are likely to be familiar with it

baltoro

Yup. When you read Irvine's book,..about a third of the entire content demonstrates DOS 16-bit real mode techniques and the usage of invoking 16-bit Interrupts, which are completely obsolete in Windows XP and newer systems. I'm not quite sure why he has kept these 'historical documents' in a modern beginners text about assembly programming. :eek
Baltoro

MichaelW

Quote from: baltoro on April 23, 2011, 07:19:57 PM
When you read Irvine's book,..about a third of the entire content demonstrates DOS 16-bit real mode techniques and the usage of invoking 16-bit Interrupts, which are completely obsolete in Windows XP and newer systems.

Most of the 16-bit stuff works fine under Windows XP. There are a few things that you can't do, but AFAIK Irvine's code does not do any of these things. There is still a possibility of an assembly programmer needing some of the techniques that you see in 16-bit DOS code, so I think it's reasonable to at least cover some of it, but dedicating a third of the book to it does seem excessive.
eschew obfuscation