Taking a class that uses the Irvine32 libraries.
I am so lost. There is not support that I can find and the book is useless.
Anyone know where there are good and working code samples like procedures for dummies?
Some of the guys in here do know their way around Kip Irvine's package so if you can let us know what you are trying to get the swing of, maybe one of our members can help you.
With MASM in general, a procedure needs 2 things, a PROTOTYPE that matches the arguments in the procedure.
myproc PROTO arg1:DWORD,arg2:DWORD ; the PROTOTYPE
........
myproc PROC arg1:DWORD,arg2:DWORD
; write your code here
ret ; you need this to exit from the proc back to its caller
myproc ENDP
I get the concept (kind of) that asm is a real time operation and less wiggle room to just slap something up in memory and grab it as you need it.
Perfect example of my very serious limitation and hoping to get some clarity.
I am trying to turn the following working code to run the 3 input read as a procedure.
Here is the working code (no errors)
************************************
INCLUDE Irvine32.inc
.data
i dword ?
xstart dword ?
xhold dword ?
xend dword ? ;
xdelta dword ?
y dword ?
lines dword ?
oops byte "oops",0
buffer BYTE 21 DUP(0) ; input buffer
xahold dword ?
promptia byte "What is the start of the x loop?",0
promptib byte "What is the end of the x loop?",0
promptjla byte "What is the y value?",0
promptlines byte "How many lines ?",0
promptname byte "What is is your name?",0
star byte "*",0
.code
main PROC
mov eax,0
;*****************reads xstart **************
mov edx, offset promptia
call writestring
CALL READINT
mov xstart, eax
mov xhold,eax
;**********************************************
;*****************reads xend **************
mov edx, offset promptib
call writestring
call readINT ; to eax
mov xend, eax
;**********************************************
;*****************reads y **************
mov edx, offset promptjla
call writestring
call readINT ; to eax
mov y , eax
;**********************************************
;*****************readslines **************
mov edx, offset promptlines
call writestring
CALL READINT
mov lines, eax
;**********************************************
call clrscr
mov eax,yellow + (black* 16)
call SetTextColor
call drawbox
mov eax,white + (black* 16)
call settextcolor
exit
main ENDP
DrawBox Proc
mov eax, xend
sub eax, xstart
inc eax
mov xdelta,eax
mov ecx,lines
outer:
push ecx
Call Drawline
call crlf
inc y
pop ecx
loop outer
ret
drawbox endp
Drawline Proc
mov ecx , xdelta
mov eax, xhold
mov xstart,eax
iloop:
mov eax,xstart
mov dl,al
mov eax,y
mov dh,al
call gotoxy
mov edx,offset star
call writestring
;**********************delay of 2 seconds *********
mov eax,50
call delay
;*******************************************
inc xstart
loop iloop
ret
drawline endp
END main
**********************************************
My common sense says that this should work, but it is not.
The following errors with a nested loop error.
*************************************************
INCLUDE Irvine32.inc
.data
i dword ?
xstart dword ?
xhold dword ?
xend dword ? ;
xdelta dword ?
y dword ?
lines dword ?
delta dword ?
oops byte "oops",0
buffer BYTE 21 DUP(0) ; input buffer
xahold dword ?
promptia byte "What is the start of the x loop?",0
promptib byte "What is the end of the x loop?",0
promptjla byte "What is the y value?",0
promptlines byte "How many lines ?",0
promptname byte "What is is your name?",0
star byte "*",0
.code
main PROC
mov eax,0
;*****************reads xstart **************
mov edx, offset promptia
call writestring
CALL READINT
mov xstart, eax
mov xhold,eax
;**********************************************
call clrscr
mov eax,yellow + (black* 16)
call SetTextColor
call drawbox
mov eax,white + (black* 16)
call settextcolor
exit
main ENDP
DrawBox Proc
mov eax, xend
sub eax, xstart
inc eax
mov xdelta,eax
mov ecx,lines
outer:
push ecx
Call Drawline
call crlf
inc y
pop ecx
loop outer
DeltaProc Proc
mov eax, xend
sub eax, xstart
add eax, 1
ret
drawbox endp
Drawline Proc
mov ecx , xdelta
mov eax, xhold
mov xstart,eax
iloop:
mov eax,xstart
mov dl,al
mov eax,y
mov dh,al
call gotoxy
mov edx,offset star
call writestring
;**********************delay of 2 seconds *********
mov eax,50
call delay
;*******************************************
inc xstart
loop iloop
ret
drawline endp
;*****************reads xend **************
ReadB Proc
mov edx, offset promptib
call writestring
call readINT ; to eax
mov xend, eax
ReadB endp
;**********************************************
;*******************************
ReadA Proc
mov edx, offset promptjla
call writestring
call readINT ; to eax
mov y , eax
ReadA endp
;**********************************************
;*****************readslines **************
ReadY Proc
mov edx, offset promptlines
call writestring
CALL READINT
mov lines, eax
ReadY endp
;**********************************************
END main
************************************
Pointing me in the right direction will really help me ask the next set of questions.
Thank you!
Added code tags
i am a little surprised that it works :P
we usually use a directive that makes everything case sensitive, and Kip's routine is named "ReadInt"
;################################################
InpProc PROC
mov eax,0
;*****************reads xstart **************
mov edx, offset promptia
call writestring
CALL READINT
mov xstart, eax
mov xhold,eax
;**********************************************
;*****************reads xend **************
mov edx, offset promptib
call writestring
call readINT ; to eax
mov xend, eax
;**********************************************
;*****************reads y **************
mov edx, offset promptjla
call writestring
call readINT ; to eax
mov y , eax
;**********************************************
;*****************readslines **************
mov edx, offset promptlines
call writestring
CALL READINT
mov lines, eax
;**********************************************
call clrscr
ret
InpProc ENDP
;################################################
then, in main....
.code
main PROC
call InpProc
mov eax,yellow + (black* 16)
call SetTextColor
i don't think the MOV EAX,0 is necessary at the beginning
maybe you meant that you want to put the write/read into a proc, then call it four times
INCLUDE Irvine32.inc
;################################################
;place PROTOtypes near the beginning of the program
;they allow you to use the PROC in an INVOKE
;in this case, it tells the assembler that the PROC has a single DWORD parameter
PromptI PROTO :DWORD
;################################################
.data
i dword ?
xstart dword ?
xhold dword ?
xend dword ? ;
xdelta dword ?
y dword ?
lines dword ?
oops byte "oops",0
buffer BYTE 21 DUP(0) ; input buffer
xahold dword ?
promptia byte "What is the start of the x loop?",0
promptib byte "What is the end of the x loop?",0
promptjla byte "What is the y value?",0
promptlines byte "How many lines ?",0
promptname byte "What is is your name?",0
star byte "*",0
;################################################
.CODE
main PROC
;*****************reads xstart **************
INVOKE PromptI,offset promptia
mov xstart,eax
mov xhold,eax
;*****************reads xend **************
INVOKE PromptI,offset promptib
mov xend,eax
;*****************reads y **************
INVOKE PromptI,offset promptjla
mov y,eax
;*****************readslines **************
INVOKE PromptI,offset promptlines
mov lines,eax
;**********************************************
call clrscr
mov eax,yellow + (black* 16)
call SetTextColor
;the rest of main proc
;
;
main ENDP
;################################################
PromptI PROC lpPromptStr:DWORD
mov edx,lpPromptStr
call WriteString
call ReadInt
ret
PromptI ENDP
;################################################
Well, just like all assembly thus far, you left me with a ton of questions sir.
The goal is 3 separate procedures. I see you encompassed all 3 routines into one procedure.
I was actually expecting you to call me an idiot for my gross logical error.
I am not seeing/feeling the separation from memory to function registers.
It's that 'trip to the other side' I am just not catching.
in the code that you posted that gives you the nest error,
you are missing these two lines...
ret
DrawBox ENDP
if you are having trouble understanding memory, registers, etc,
maybe what you want is the first few chapters, here...
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html
INCLUDE Irvine32.inc
.data
i dword ?
xstart dword ?
xhold dword ?
xend dword ? ;
xdelta dword ?
y dword ?
lines dword ?
delta dword ?
oops byte "oops",0
buffer1 BYTE 21 DUP(0) ; input buffer
xahold dword ?
promptia byte "What is the start of the x loop?",0
promptib byte "What is the end of the x loop?",0
promptjla byte "What is the y value?",0
promptlines byte "How many lines ?",0
promptname byte "What is is your name?",0
star byte "*",0
hello byte "hello ",0
.code
main PROC
xor eax,eax ;mov eax,0
mov edx, offset promptia
call writestring ;writes a string on the screen
CALL READINT ;read a key user input, return in eax
mov xstart, eax ;we save the returned input of user
mov xhold,eax
CALL ReadB
call ReadA
call ReadY
call clrscr ;clear the screen
;EAX = Bits 0-3 = foreground color
;Bits 4-7 = background color
;each color have 4 bits, so this means 1 nibble, a half of byte
mov al, yellow ;AL = ???? XXXX
shl eax,4 ;we rotate the yellow to the upper of the byte, XXXX ????
;you can use here a "rol" mnemonic
or al,blue ;now, we complete that byte, XXXX YYYY
;you can use here a "xor" mnemonic
call SetTextColor
call drawbox
mov eax,white + (black* 16)
call settextcolor
mov edx, offset promptname
call writestring
mov edx,offset buffer1
mov ecx,18
call ReadString
mov edx,offset hello
call writestring
mov edx, offset buffer1
call writestring
CALL READINT ;read a key user input, return in eax, but here we make a pause, waiting the user press something
exit
main ENDP
DrawBox Proc
mov eax, xend
sub eax, xstart
inc eax
mov xdelta,eax
mov ecx,lines
outer:
push ecx
Call Drawline
call crlf
inc y
pop ecx
loop outer
ret
drawbox endp
;DeltaProc Proc
;mov eax, xend
;sub eax, xstart
;add eax, 1
;ret
;DeltaProc endp
Drawline Proc
mov ecx , xdelta
mov eax, xhold
mov xstart,eax
iloop:
mov eax,xstart
mov dl,al
mov eax,y
mov dh,al
call gotoxy
mov edx,offset star
call writestring
;**********************delay of 2 seconds *********
mov eax,50
call delay
;*******************************************
inc xstart
loop iloop
ret
drawline endp
;*****************reads xend **************
ReadB Proc
mov edx, offset promptib
call writestring
call readINT ; to eax
mov xend, eax
RET
ReadB endp
;**********************************************
;*******************************
ReadA Proc
mov edx, offset promptjla
call writestring
call readINT ; to eax
mov y , eax
RET
ReadA endp
;**********************************************
;*****************readslines **************
ReadY Proc
mov edx, offset promptlines
call writestring
CALL READINT
mov lines, eax
RET
ReadY endp
;**********************************************
END main
bcddd214,
We get alot of posts in here about problems using the Irvine library. I have the book myself, so I understand what you are going through,...but, most of the assembly programmers here are not familiar with the code contained in Kip Irvine's book and library. Specifically, the code routines contained in the library are not used by more experienced programmers because the Irvine library routines are largely obsolete. If you include the code for those routines which your initial program invokes (using CALL) in one of your posts here in the forum, the guys (like, Dave) won't be forced to guess what your application is actually attempting to do as they trace the sequence of instructuions. As I recall, the original code for each and every Irvine routine is contained in one of the include files that Irvine supplies with the library (that you link to when compiling).
Also, a big problem with Irvine's methods is the way he does his loops (he relies on the loop instruction). The group here has remarked numerous times that Irvine's way of coding loops is not really reliable, and they recommend better and more reliable techniques. Here is a reference to: Chapter Ten, Control Structures, The Art of Assembly Programming (http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_10/CH10-1.html#top),...lots of useful information on loops.
If you use the Forum search facility, advanced search,...and, supply the word 'Irvine' in the search for text box, and search just the Campus Forum (you have to uncheck all the others), and, supply a reasonable number in the 'Message Age' box, you will get a huge number of threads from beginner programmers that have problems similar to yours. :eek
For example, here's one in which the beginner gets numerous compiler erros becuase he starts his asm file off with, "include Irvine32.inc", and then adds includes from the MASM32 package, which generate a number of redefinition errors: Setting up irvine libs with default masm install (http://www.masm32.com/board/index.php?topic=15539.0). You might find it informative.
Thank you baltoro!
That is my EXACT issue. As soon as I looked at the book and saw Kip using the proprietary call which have nothing to do with how assembly works, I know I was up a creek!
It's an understanding of how it works that is blocking me and Kip does little to nothing to help that and the BIGGEST issues I have is that if I use sample code from other masm websites to experiment, it crashes and Kip's stuff works nowhere else but make32.
I am in pretty deep now and just need to dredge through it I guess.
I got it to assemble and the format seems ok. I still have to tweak it some.
Oddly, now it goes to a blank screen though and hangs at the end. Commenting out any 'call clrscr' crashes it???
INCLUDE Irvine32.inc
;################################################
PromptI PROTO :DWORD
;################################################
.data
i dword ?
xstart dword ?
xhold dword ?
xend dword ? ;
xdelta dword ?
y dword ?
lines dword ?
oops byte "oops",0
buffer BYTE 21 DUP(0) ; input buffer
xahold dword ?
promptia byte "What is the start of the x loop?",0
promptib byte "What is the end of the x loop?",0
promptjla byte "What is the y value?",0
promptlines byte "How many lines ?",0
promptname byte "What is is your name?",0
star byte "*",0
;################################################
.code
main PROC
call InpProc
mov eax,yellow + (black* 16)
call SetTextColor
call DrawBox
call Drawline
call clrscr
main ENDP
;################################################
PromptI PROC lpPromptStr:DWORD
mov edx,lpPromptStr
call WriteString
call ReadInt
ret
PromptI ENDP
;################################################
DrawBox Proc
mov eax, xend
sub eax, xstart
inc eax
mov xdelta,eax
mov ecx,lines
outer:
push ecx
Call Drawline
call crlf
inc y
pop ecx
loop outer
ret
drawbox endp
InpProc PROC
mov eax,0
;*****************reads xstart **************
mov edx, offset promptia
call writestring
CALL READINT
mov xstart, eax
mov xhold,eax
;**********************************************
;*****************reads xend **************
mov edx, offset promptib
call writestring
call readINT ; to eax
mov xend, eax
;**********************************************
;*****************reads y **************
mov edx, offset promptjla
call writestring
call readINT ; to eax
mov y , eax
;**********************************************
;*****************readslines **************
mov edx, offset promptlines
call writestring
CALL READINT
mov lines, eax
;**********************************************
call clrscr
ret
InpProc ENDP
Drawline Proc
mov ecx , xdelta
mov eax, xhold
mov xstart,eax
iloop:
mov eax,xstart
mov dl,al
mov eax,y
mov dh,al
call gotoxy
mov edx,offset star
call writestring
;**********************delay of 2 seconds *********
mov eax,50
call delay
;*******************************************
inc xstart
loop iloop
ret
drawline endp
END main
at the end of the main routine, add this line
INVOKE ExitProcess,0
it's kind of like a RET on steroids :lol
Wow Dave, your awesome.
For the first time my fear level has subsided a little.
Just getting a little hint is helping me see this stuff fit together a little.
Any thoughts of how to return the color back from yellow to white in the program?
mov eax,16*black+white
call SetTextColor
i think black = 0, so....
mov eax,white
call SetTextColor
would probably work
oh - and for the ExitProcess, i think Kip has a macro named "exit"
so.......
exit
could replace that line
it does the same thing
For the first time, I understand the procedure calls.
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
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 (http://www.intel.com/products/processor/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.
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
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
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.