Author Topic: Understanding Procedures  (Read 2484 times)

Ampersand Laboratories Team

  • Guest
Understanding Procedures
« on: December 17, 2006, 09:05:03 PM »
I have the book "The Ultimate DOS Programmer's Manual" 2nd Edition by John Mueller at hand right now. Chapter 7 of that book discusses BIOS-independent interrupts to do BIOS routines (not DOS stuff). I found a few interrupt I might want to program floppy disk boot sectors for (512 byte files that are written to the first 512 bytes of a floppy disk).

I think Mueller uses TASM or MASM because I see Assembly code in the following fashion (taking a part from one of its examples and stripping it of comments):

==========
HexConv   PROC   NEAR

MOV    CX,10
NextChar: XOR    DX,DX
          DIV    CX
          ADD    DL,30h
          MOV    [DI],DL
          DEC    DI
          CMP    AX,10
          JGE    NextChar
          ADD    AL,30h
          MOV    [DI],AL

RET

HexConv   ENDP
==========
(from Mueller, John. "The Ultimate DOS Programmer's Manual", 2/e, pg. 129; code by John Mueller)

I understand the format: HexConv is a procedure and NextChar is a local label in that procedure that only code in HexConv can JMP to.

I want to know this: how do I do the same thing in NASM? More specifically, how do I make a procedure in NASM and then give it an internal label?

Also, what is PROC NEAR and PROC FAR and how do I use them in NASM?

Ampersand Laboratories Team

  • Guest
Re: Understanding Procedures
« Reply #1 on: December 17, 2006, 09:06:33 PM »
PS - I forgot to say that the ENDP thing marks the end of the procedure.

nobody

  • Guest
Re: Understanding Procedures
« Reply #2 on: December 18, 2006, 02:56:45 AM »
Easy, in this case. "PROC NEAR" and "ENDP" don't do *anything* in this code - except possibly to make the label "local" (I didn't know that). Just delete 'em. If you want "NextChar" to be "local", put a "." in front of it (and where you jump to it). Then you can use ".NextChar" again in your "DecConv" routine... Wait a minute! This routine does convert to decimal, although the name suggests otherwise. Well, in your "BinConv" routine, then. :)

This isn't a "true local label", because you *can* jump to it from outside its scope by using the "full name" - "HexConv.NextChar". But that's the way Nasm does it.

The rest of the code should assemble with Nasm as-is. (the general rule is: if Nasm complains, delete it! :)

Best,
Frank

Ampersand Laboratories Team

  • Guest
Re: Understanding Procedures
« Reply #3 on: December 18, 2006, 02:03:56 PM »
So how do I know when a procedure ends? Is it when NASM sees RET?