Reputation: 11
these are my project requirements
mark the space occupied by instructions as read-only and the rest as read/write Otherwise, perform swapping: move a program into virtual memory to free up space in RAM then load it into memory Once loaded, show that it is running and display all of its instructions Step 4: View RAM and Virtual Memory Status
this is my code in masm x86 Assembly. when i build this code. it builds succesfully. but when i run it it throws me an exception. Exception Error is attached in an image. i can specify the line where is this exception thrown. the Exception is thrown at line no 72
.this is the exception image
INCLUDE Irvine32.inc
; Constants
RAM_SIZE EQU 4 \* 1024 ; Simulated 4 KB RAM
VM_SIZE EQU 10 \* 1024 ; Simulated 10 KB Virtual Memory
MAX_PROGRAMS EQU 10 ; Maximum number of programs
; Permissions
PERM_READ EQU 1
PERM_WRITE EQU 2
.DATA
RAM DB RAM_SIZE DUP(0) ; Simulated RAM memory region
VirtualMem DB VM_SIZE DUP(0) ; Virtual memory region
; Program metadata
ProgramStatus DB MAX_PROGRAMS DUP(0) ; 0 = Closed, 1 = Running, 2 = Swapped
ProgramRAMStart DW MAX_PROGRAMS DUP(0) ; Start address in RAM
ProgramRAMSize DW MAX_PROGRAMS DUP(0) ; Size occupied in RAM
ProgramVMStart DW MAX_PROGRAMS DUP(0) ; Start address in Virtual Memory
; Buffers for user input and program data
inputBuffer DB 50 DUP(0)
programBuffer DB 100 DUP(0)
; Menu options
Menu DB "1. Load Program", 13, 10, "2. View Memory Status", 13, 10, "3. Close Program", 13, 10, "4. Use Program", 13, 10, "5. Request Memory Access", 13, 10, "6. Exit", 0
; Status and error messages
NoFreeSlotMsg DB "Error: No free slots available for new programs.", 13, 10, 0
ProgramLoadedMsg DB "Program loaded successfully.", 13, 10, 0
CloseProgramMsg DB "Program closed successfully.", 13, 10, 0
UseProgramMsg DB "Using the selected program.", 13, 10, 0
RAMStatus DB "RAM and Virtual Memory Status:", 13, 10, 0
AccessDeniedMsg DB "Access denied: Invalid permissions or memory address.", 13, 10, 0
AccessGrantedMsg DB "Access granted.", 13, 10, 0
.CODE
MAIN PROC
; Initialize RAM and Virtual Memory
CALL InitializeMemory
; Display menu and process user input
WHILE_TRUE:
CALL DisplayMenu
CALL GetUserInput
CMP AL, '1'
JE LoadProgram
CMP AL, '2'
JE ViewMemory
CMP AL, '3'
JE CloseProgram
CMP AL, '4'
JE UseProgram
CMP AL, '5'
JE RequestMemoryAccess
CMP AL, '6'
JE ExitProgram
JMP WHILE_TRUE
ExitProgram:
MOV AX, 4C00h
INT 21h
MAIN ENDP
; Initialize simulated memory
InitializeMemory PROC
; Zero out RAM
LEA DI, RAM ; Load effective address of RAM
MOV CX, RAM_SIZE ; Set count to RAM size
MOV AL, 0 ; Value to store (0)
REP STOSB ; Fill RAM with 0
; Zero out Virtual Memory
LEA DI, VirtualMem ; Load effective address of VirtualMem
MOV CX, VM_SIZE ; Set count to VM size
MOV AL, 0 ; Value to store (0)
REP STOSB ; Fill Virtual Memory with 0
; Reset program metadata
MOV CX, MAX_PROGRAMS ; Loop counter for MAX_PROGRAMS
XOR DI, DI ; Clear DI to use it as an index
Upvotes: 0
Views: 39