Author Topic: Procs on console projects: Where?  (Read 2366 times)

AssemblyChallenge

  • Member
  • **
  • Posts: 110
Procs on console projects: Where?
« on: July 07, 2015, 02:42:34 AM »
Hi all.

This is a no brainer on GUI projects but is killing me on console ones: Where should I put the Proc(s) code ??

Acording to MASM examples should be something like:

Code: [Select]
include1
include2
etc
.............
TheProc  PROTO ; not needed on EasyCode
...............
.data
..................
.code
main proc
.
invoke TheProc
.

invoke ExitProcess,0

main endp
..................
TheProc proc
    .
    code
    more code
    etc
    .
    ret
TheProc endp
..................
end main

My problem: If I put the Proc's code between Main and End, the theoretical "right" place:

Code: [Select]
Main EndP

   TheProc Proc
       blah
   TheProc Endp

End start

I get syntax errors, undefined symbols, etc. all over the Proc(s), even its labels explode. In the other hand, placing the Proc(s) outside of everything throws "unresolved external symbol" (which seems legit):

Code: [Select]
Main EndP

End start

TheProc Proc
       blah
TheProc Endp

The odd part: I'm very sure it was compiling fine with the first approach and then all of the sudden stopped working  :dazzled:  In EasyCode we don't need PROTO (which I tested anyway) so, what am I doing wrong here ??  :shock:

dedndave

  • Member
  • *****
  • Posts: 8807
  • Still using Abacus 2.0
    • DednDave
Re: Procs on console projects: Where?
« Reply #1 on: July 07, 2015, 03:02:14 AM »
My problem: If I put the Proc's code between Main and End, the theoretical "right" place:

some old school teaching was that dependent routines went first
it shouldn't really matter, so long as you have a PROTO

Code: [Select]
Main EndP

   TheProc Proc
       blah
   TheProc Endp

End start

"start" is defined in the end statement, but the entry is "Main"   :P

rrr314159

  • Member
  • *****
  • Posts: 1382
Re: Procs on console projects: Where?
« Reply #2 on: July 07, 2015, 03:24:17 AM »
There's confusion between "main" and "start". Normally you wouldn't have both. One of them is defined as your entry in the linker statement, that's the (only) one to use. You can't put procs, or any other code, after the "real" end statement. Apart from that they can go anywhere above (except of course inside another proc, or structure or macro definition, and after .code of course). As long as there's a proto statement at the top you're ok; you can leave that out when the proc is called only from below, so - to keep things simple - just always put it in.

Quote from: AssemblyChallenge
I'm very sure it was compiling fine with the first approach and then all of the sudden stopped working  :dazzled:

- you must have  changed something to do with the end statement (confusion between start and main), that's what u need to straighten out, not the proc placement

I am NaN ;)

AssemblyChallenge

  • Member
  • **
  • Posts: 110
Re: Procs on console projects: Where?
« Reply #3 on: July 07, 2015, 05:38:38 AM »
Thank you guys.

One mistake on my behalf was using "End" as a Label  :icon_redface: . Yet, the biggest reason for compiling errors was using the Local directive inside the Procs.

Not sure if EasyCode takes the procedure's variables as local by default; couldnt find it on the manual. Maybe Ramon could make it clear for me if:

Code: [Select]
MyProc1 Proc Public
Local MyVar DB 'A', 0 ; this way fails compiling
       
        ; rest of the code
Ret
MyProc1 EndP

Is the same as:

Code: [Select]
MyProc1 Proc Public
MyVar DB 'A', 0 ; this one compiles fine
       
        ; rest of the code
Ret
MyProc1 EndP

With no risk of misunderstanding by the compiler.

dedndave

  • Member
  • *****
  • Posts: 8807
  • Still using Abacus 2.0
    • DednDave
Re: Procs on console projects: Where?
« Reply #4 on: July 07, 2015, 06:23:58 AM »
the syntax for local variables is different than globals
Code: [Select]
MyFunc PROC

    LOCAL   bLocal        :BYTE    ;1 byte
    LOCAL   abLocal[24]   :BYTE    ;24 bytes

notice that, in MASM, locals are always uninitialized
if you want them initialized, you have to do it with code

AssemblyChallenge

  • Member
  • **
  • Posts: 110
Re: Procs on console projects: Where?
« Reply #5 on: July 07, 2015, 06:49:03 AM »
What the heck. I was defining local strings in a very very happy way  :lol:

Code: [Select]
Local MyString:DB "My string defined", 0

No wonder it failed  :icon_redface: Your explanation makes a lot of sense and my book only has examples of strings passed as parameters but not defined internally in the Procedures.

You nailed it. Thank you.  :t :t