NASM OS Dev Problems

Programming, for all ages and all languages.
Post Reply
ExtremeCoder27
Posts: 2
Joined: Thu Jan 17, 2008 4:13 am

NASM OS Dev Problems

Post 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
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post 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.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
Post Reply