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

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?

hutch--

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

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bcddd214

#2
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

dedndave

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

dedndave

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

;################################################

bcddd214

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.

dedndave

in the code that you posted that gives you the nest error,
you are missing these two lines...
        ret

DrawBox ENDP

dedndave

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

mineiro


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

baltoro

#9
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,...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. You might find it informative.
Baltoro

bcddd214

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.

bcddd214

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

dedndave

at the end of the main routine, add this line
        INVOKE  ExitProcess,0

it's kind of like a RET on steroids   :lol

bcddd214

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?

dedndave

        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