RAM.html
RAM.html
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How RAM Works - Visual Demonstration</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
background-color: #f0f4f8;
color: #333;
}
header {
background-color: #2c3e50;
color: white;
padding: 1rem;
text-align: center;
}
main {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}
.container {
display: flex;
flex-direction: column;
gap: 2rem;
}
.section {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 1.5rem;
margin-bottom: 2rem;
}
h1, h2, h3 {
color: #2c3e50;
}
.simulation {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
}
.simulation-container {
position: relative;
width: 100%;
height: 400px;
border: 2px solid #ddd;
border-radius: 8px;
overflow: hidden;
background-color: #f8f9fa;
}
.controls {
display: flex;
gap: 1rem;
margin: 1rem 0;
}
button {
background-color: #3498db;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
}
button:hover {
background-color: #2980b9;
}
.cpu {
position: absolute;
top: 150px;
left: 50px;
width: 120px;
height: 100px;
background-color: #e74c3c;
border-radius: 8px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
z-index: 2;
}
.ram {
position: absolute;
top: 100px;
right: 50px;
width: 80px;
height: 200px;
background-color: #2ecc71;
border-radius: 8px;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
color: white;
font-weight: bold;
z-index: 2;
}
.memory-cell {
width: 60px;
height: 20px;
background-color: #27ae60;
border: 1px solid white;
display: flex;
justify-content: center;
align-items: center;
font-size: 0.8rem;
}
.memory-bus {
position: absolute;
top: 200px;
left: 170px;
width: 280px;
height: 8px;
background-color: #3498db;
z-index: 1;
}
.data-packet {
position: absolute;
width: 40px;
height: 25px;
background-color: #f39c12;
border-radius: 4px;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
font-size: 0.8rem;
z-index: 3;
transition: left 1s ease-in-out;
}
.process-list {
position: absolute;
top: 20px;
left: 50px;
width: 130px;
background-color: #9b59b6;
border-radius: 8px;
padding: 10px;
color: white;
}
.process {
font-size: 0.9rem;
margin-bottom: 5px;
}
.memory-address {
position: absolute;
top: 20px;
right: 140px;
width: 100px;
background-color: #34495e;
border-radius: 8px;
padding: 10px;
color: white;
}
.address {
font-size: 0.9rem;
margin-bottom: 5px;
}
.step-explanation {
background-color: #f8f9fa;
border-left: 4px solid #3498db;
padding: 1rem;
margin: 1rem 0;
}
.info-box {
margin-top: 2rem;
background-color: #f8f9fa;
border-radius: 8px;
padding: 1rem;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<header>
<h1>How RAM Works - Visual Demonstration</h1>
</header>
<main>
<div class="container">
<section class="section">
<h2>Understanding RAM (Random Access Memory)</h2>
<p>RAM is your computer's short-term memory. It's where your
computer stores data that active programs need to access quickly. Unlike long-term
storage (hard drives or SSDs), RAM is volatile—it loses all stored information when
the power is turned off.</p>
<div class="info-box">
<h3>Key RAM Functions:</h3>
<ul>
<li>Provides fast access to data (measured in
nanoseconds)</li>
<li>Allows the CPU to directly access any memory
address</li>
<li>Stores running programs and their data temporarily</li>
<li>Enables multitasking by providing space for multiple
programs</li>
</ul>
</div>
</section>
<section class="section">
<h2>Interactive RAM Simulation</h2>
<p>This simulation demonstrates how data moves between the CPU
and RAM. Click the buttons below to see different RAM operations in action.</p>
<div class="simulation">
<div class="controls">
<button id="read-data">Read Data from RAM</button>
<button id="write-data">Write Data to RAM</button>
<button id="reset">Reset</button>
</div>
<div class="simulation-container">
<div class="cpu">
<div>CPU</div>
<div id="cpu-data"></div>
</div>
<div class="ram">
<div>RAM</div>
<div class="memory-cell" id="cell-1">0x01: A</div>
<div class="memory-cell" id="cell-2">0x02: B</div>
<div class="memory-cell" id="cell-3">0x03: C</div>
<div class="memory-cell" id="cell-4">0x04: D</div>
<div class="memory-cell" id="cell-5">0x05: ?</div>
</div>
<div class="memory-bus"></div>
<div class="process-list">
<div>Active Processes:</div>
<div class="process">Browser</div>
<div class="process">Word</div>
<div class="process">Music</div>
</div>
<div class="memory-address">
<div>Addresses:</div>
<div class="address">0x01-0x05</div>
</div>
<section class="section">
<h2>How RAM Works in Detail</h2>
<script>
const readButton = document.getElementById('read-data');
const writeButton = document.getElementById('write-data');
const resetButton = document.getElementById('reset');
const dataPacket = document.getElementById('data-packet');
const explanation = document.getElementById('explanation');
const cpuData = document.getElementById('cpu-data');
const cell5 = document.getElementById('cell-5');
readButton.addEventListener('click', () => {
if (isAnimating) return;
isAnimating = true;
setTimeout(() => {
dataPacket.textContent = "Req";
dataPacket.style.left = "170px";
dataPacket.style.top = "190px";
dataPacket.classList.remove('hidden');
setTimeout(() => {
dataPacket.style.left = "430px";
explanation.textContent = "Step 2: Memory controller receives
request and locates data at address 0x03";
setTimeout(() => {
dataPacket.textContent = "C";
setTimeout(() => {
dataPacket.style.left = "170px";
explanation.textContent = "Step 3: Data 'C' travels back
to the CPU through the memory bus";
setTimeout(() => {
cpuData.textContent = "Data: C";
dataPacket.classList.add('hidden');
explanation.textContent = "Step 4: CPU receives
and processes the data. The entire operation took only a few nanoseconds!";
isAnimating = false;
}, 1000);
}, 1000);
}, 1000);
}, 1000);
}, 500);
});
writeButton.addEventListener('click', () => {
if (isAnimating) return;
isAnimating = true;
explanation.textContent = "Step 1: CPU prepares to write data 'E' to
memory address 0x05";
cpuData.textContent = "Data: E";
setTimeout(() => {
dataPacket.textContent = "E";
dataPacket.style.left = "170px";
dataPacket.style.top = "190px";
dataPacket.classList.remove('hidden');
setTimeout(() => {
dataPacket.style.left = "430px";
explanation.textContent = "Step 2: Data 'E' travels through the
memory bus to RAM";
setTimeout(() => {
cell5.textContent = "0x05: E";
dataPacket.classList.add('hidden');
explanation.textContent = "Step 3: Memory controller writes
data 'E' to address 0x05. This operation also took only a few nanoseconds!";
isAnimating = false;
}, 1000);
}, 1000);
}, 500);
});
resetButton.addEventListener('click', () => {
if (isAnimating) return;
dataPacket.classList.add('hidden');
cpuData.textContent = "";
cell5.textContent = "0x05: ?";
explanation.textContent = "Click one of the buttons above to start the
demonstration.";
});
</script>
</body>
</html>