About me
Home
Resumé
CV
Pictures

Course Work
CSE300-FA98

Teaching
Portfolio
CSE240-SP99
CSE207-FA03

Misc
eHarmony
Documents

Tools

Writing Library Modules

Since you have been using explicit segments in your coding so far, you will find it fairly simple to convert one of your procedures into a library module. Below is a sample of a module.

TITLE killTime.ASM
;=======================================================================
; killTime is a function designed to waste a large amount of time
;=======================================================================
;   PreCond  -- None
;   PostCond -- This task will run indefinately
;=======================================================================
PUBLIC killTime

_TEXT SEGMENT USE16 WORD PUBLIC 'CODE'
    ASSUME cs:_TEXT

killTime PROC FAR
    push    cx                      ;save register contents
    push    bx

    mov     bx, TimeKillConst       ;outer count of Kill time loops
  KillMoreTime:
    xor     cx, cx                  ;max loop time (inner loop)
    loop    $                       ;loop in place
    dec     bx
    jz      SHORT KillTimeDone      ;break out of loops when done
    jmp     SHORT KillMoreTime      ;not finished with outter loop, continue

  KillTimeDone:
    pop     bx                      ;restore register contents
    pop     cx
    ret
killTime ENDP
_TEXT ENDS
END

So, lets walk through this file. As usual, there is the TITLE specification at the top of the file to let us know the name of the source file followed by the standard procedure comment block. Next is a strange line PUBLIC name. This is the name other files can use to call this procedure. When you assemble and link a source file that uses this module, the PUBLIC name is what will be used. Be careful - this is case sensitive! The code segment starts, notice that this is the same name as the main code segment we typically use. You can use other code segments, but if you do - make sure that you set the segment as you enter the module otherwise your assumption about CS will be incorrect. The procedure body is the same as it would be if it were in a single source file. The key word END does not have the word Start after it like we would typically see in a single file. The reason is that this is only one module in the program. The main routine will be the file that will have the END Start in it. Last observations, there is no data segment or stack declared here. They may be if you are going to use them, but they are not necessary in this case. If you need to have access to variables that are not part of this module, or if you want to declare variables here and use them in the main module, you will need to learn how to use the EXTRN key word. I will try to put a file together with an example of external data and code in the next few days

Last Modified: January 26, 1999 - Barry E. Mapen