Page 1 of 1

NASM OS Dev Problems

Posted: Fri Jan 18, 2008 12:30 pm
by ExtremeCoder27
There are a few things that I dont get in NASM, how do I define the entry point and how do I define a procedure?

Thanks,

ExtremeCoder27

Posted: Fri Jan 18, 2008 6:32 pm
by XCHG
A procedure? Well a procedure is a label. An offset in a segment in IA-32. You can simply create a label and think of it as a procedure's entry point like this:

Code: Select all

  MyProcedure:
    ; void MyProcedure (void); StdCall;
    RET
NASM also allows you to have local labels for your procedures like this:

Code: Select all

  Procedure1:
    ; void Procedure1 (void); StdCall;
    .Label1:
      RET
  
  Procedure2:
    ; void Procedure2 (void); StdCall;
    .Label1:
    RET
Observe that [.Label1] is defined both in Procedure1 and Procedure2 but NASM differentiates between these since the first label is created after the Procedure1 label and the second Label1 is created after Procedure2. So if you do something like this:

Code: Select all

  Procedure1:
    ; void Procedure1 (void); StdCall;
    .Label1:
      RET
  
  Procedure2:
    ; void Procedure2 (void); StdCall;
    .Label1:
      JMP     .Label1
    RET
The JMP instruction will jump to .Label1 in Proceudre2.

You could however use some distinctive way of creating your procedures. What I do is that I prefix my procedures' name with double underscores like this:

Code: Select all

  __Procedure1:
    ; void __Procedure1 (void); StdCall;
    RET
It is of course a preference. You could then CALL your procedures like this:

Code: Select all

; ——————————————————————————————————————————————————  
  CALL    Procedure1
  JMP     $
; ——————————————————————————————————————————————————  
  __Procedure1:
    ; void __Procedure1 (void); StdCall;
    RET
; ——————————————————————————————————————————————————  
I hope that helps.