; Peter Hutnick ; COSC 2425, section 27540 ; Project ; December 10, 2001 .model small ; Set memory model .stack 100h ; Ask for a 200h byte stack .386 ; Use 386 features node struc ; Label the start of the struct definition txt db 14 dup(?) ; The data element of the node next dw 0 ; The link pointer node ends ; end of struct inputbuffer struc max db 13 total db 0 buffer db 14 dup(?) inputbuffer ends .data ; Begin data segment start dw 0 ; Pointer to the first node in the list (queue) input_msg db "Please enter a string (up to 13 characters)",'$' evendata input_buffer inputbuffer <> .code ; Begin code segment main proc ; Begin the main procedure mov ax,@data ; Place the address of the begining of the data ; segment in AX, ; because we can't set DS directly from memory. mov ds,ax ; Set the DS to the begining of the data segment mov bx,1000h ; I need a 100h byte heap mov ax,4a00h ; Tell DOS that when I int 21h I want to allocate heap int 21h ; Tell DOS to go ahead an allocate the heap call AllocNode ; queue up five strings ; display them ; remove a node, display the string and de-alloc, five times, one line each. mov ah, 4Ch ; Tell DOS that when I int 21h I want to terminate ; the program. int 21h ; Tell DOS to go ahead and terminate the program main endp ; label the end of the main procedure AllocNode proc ; does not attach to list push ax push bx mov bx,1 mov ah,48h int 21h call PopulateNode pop bx pop ax ret ; The carry on error is just "passed through" from the int 21h. IOW, this ; function "returns" carry on alloc error without doing anything! AllocNode endp PutNode proc push ax push bx push es push si mov bx,start mov start,ax mov es,ax xor si,si mov es:[si].next,bx pop si pop es pop bx pop ax ret PutNode endp GetNode proc ; push whatever ; traverse list to node with null pointer ; set ES to that node and call freenode ; pop whatever GetNode endp ListNodes proc ; push whatever ; traverse list outputing each string (with a newline) ; pop whatever ListNodes endp FreeNode proc push ax mov ah,49h int 21h pop ax ret FreeNode endp PopulateNode proc pushf push ax push dx mov ah,9 mov dx,offset input_msg int 21h mov input_buffer.max,13 mov dx, offset input_buffer mov ah,0ah int 21h pop dx pop ax popf ret PopulateNode endp end main ; Label the end of the program, and tell the assembler ; what proc to start with (main).