.MODEL SMALL
.DATA
    MSG1 DB 13,10, "--------------------------------------------", 13,10
         DB "--  WELCOME TO LIBRARY MANAGEMENT SYSTEM  --", 13,10
         DB "--------------------------------------------", 13,10,13,10
         DB "1-> Register a Member", 13,10
         DB "2-> View Members", 13,10
         DB "3-> View Members From  File", 13,10
         DB "4-> Add Book", 13,10
         DB "5-> View Books", 13,10
         DB "6-> View Books From Files", 13,10
         DB "7-> Exit Program", 13,10
         DB "Choose Your Option : $"

    REG_MSG DB 13,10, "Enter Member's Name to register: $"
    VIEW_MEMBERS_MSG DB 10,13, "Viewing Registered Members: $"
    ADD_MSG DB 13,10, "Enter Book Name & Author Name to Add (Separated By Comma): $"
    VIEW_BOOKS_MSG DB 10,13, "Viewing Books in Library: $"
    EXIT_MSG DB 10,13, "----------------- ", 13,10
             DB "Exiting Program...", 13,10
             DB "See you again  :')", 13,10
             DB "------------------$"

    MEMBERS_FILE DB "MEMBERS.txt", 0
    BOOKS_FILE DB "BOOKS.txt", 0
    BUFFER_SIZE EQU 5000
    BUFFER_MEM DB BUFFER_SIZE DUP(?)
    BUFFER_BOOK DB BUFFER_SIZE DUP(?)
    bytesRead DW ?
    REGISTER DW 1
    VIEW_MEMBERS DW 2
    VIEW_MF DW 3
    ADD_BOOK DW 4
    VIEW_BOOKS DW 5
    VIEW_BF DW 6
    EXITP DW 7
    MEMBER_SIZE EQU 20
    MEMBERS DB MEMBER_SIZE DUP(?)
    NUM_MEMBERS DW ?

    BOOK_SIZE EQU 30
    BOOKS DB BOOK_SIZE DUP(?)
    NUM_BOOKS DW ?

.CODE
MAIN PROC
    MOV AX, @DATA
    MOV DS, AX

START:
    MOV AH, 9
    LEA DX, MSG1
    INT 21h
    
    MOV AH, 1
    INT 21h
    SUB AL, 30h  ; Convert ASCII to integer

    ; Handle user input
    CMP AL, '1'  ; Check if the user selected option 1
    JE REG_M
    CMP AL, '2'  ; Check if the user selected option 2
    JE VIEW_M
    CMP AL, '7'  ; Check if the user selected option 7
    JE EXIT_MENU

    JMP START

REG_M:
    ; Register a member
    MOV AH, 9
    LEA DX, REG_MSG
    INT 21h
    
    ; Set up registers for reading input
    MOV AH, 0Ah      ; Function to read string
    MOV DX, OFFSET MEMBERS  ; Offset of buffer to store input
    INT 21h
    
    ; Increment NUM_MEMBERS
    INC NUM_MEMBERS

    JMP START

VIEW_M:
    ; View registered members
    MOV AH, 9
    LEA DX, VIEW_MEMBERS_MSG
    INT 21h

    ; Display registered members
    MOV CX, NUM_MEMBERS    ; Counter for the number of registered members
    MOV SI, OFFSET MEMBERS    ; Point SI to the start of the MEMBERS buffer

PRINT_MEMBER:
    MOV AH, 2    ; Print character function
    MOV DL, [SI]    ; Load character to print from MEMBERS buffer
    INT 21h

    INC SI    ; Move to the next character in MEMBERS buffer
    DEC CX    ; Decrement the counter
    LOOP PRINT_MEMBER  ; Repeat until all members are printed

    JMP START

EXIT_MENU:
    ; Exit program
    MOV AH, 9
    LEA DX, EXIT_MSG
    INT 21h

    MOV AH, 4Ch
    INT 21h

MAIN ENDP

READINT PROC
    MOV AH, 01h
    INT 21h
    SUB AL, 30h  ; Convert ASCII to integer
    RET
READINT ENDP
END MAIN
 
by

Assembly Online Compiler

Write, Run & Share Assembly code online using OneCompiler's Assembly online compiler for free. It's one of the robust, feature-rich online compilers for Assembly language. Getting started with the OneCompiler's Assembly compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Assembly and start coding.

About Assembly

Assembly language(asm) is a low-level programming language, where the language instructions will be more similar to machine code instructions.

Every assembler may have it's own assembly language designed for a specific computers or an operating system.

Assembly language requires less execution time and memory. It is more helful for direct hardware manipulation, real-time critical applications. It is used in device drivers, low-level embedded systems etc.

Syntax help

Assembly language usually consists of three sections,

  1. Data section

    To initialize variables and constants, buffer size these values doesn't change at runtime.

  2. bss section

    To declare variables

  3. text section

    _start specifies the starting of this section where the actually code is written.

Variables

There are various define directives to allocate space for variables for both initialized and uninitialized data.

1. To allocate storage space to Initialized data

Syntax

variable-name    define-directive    initial-value 
Define DirectiveDescriptionAllocated Space
DBDefine Byte1 byte
DWDefine Word2 bytes
DDDefine Doubleword4 bytes
DQDefine Quadword8 bytes
DTDefine Ten Bytes10 bytes

2. To allocate storage space to un-initialized data

Define DirectiveDescription
RESBReserve a Byte
RESWReserve a Word
RESDReserve a Doubleword
RESQReserve a Quadword
RESTReserve a Ten Bytes

Constants

Constants can be defined using

1. equ

  • To define numeric constants
CONSTANT_NAME EQU regular-exp or value

2. %assign

  • To define numeric constants.
%assign constant_name value

3. %define

  • To define numeric or string constants.
%define constant_name value

Loops

Loops are used to iterate a set of statements for a specific number of times.

mov ECX,n
L1:
;<loop body>
loop L1

where n specifies the no of times loops should iterate.

Procedures

Procedure is a sub-routine which contains set of statements. Usually procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

procedure_name:
   ;procedure body
   ret