# Assignments and Challenges

• (5 Pages)
• « First
• 3
• 4
• 5

## 64 Replies - 88455 Views - Last Post: 10 March 2015 - 05:00 PM

### #61 ivaylo9603

• New D.I.C Head

Reputation: 1
• Posts: 21
• Joined: 05-November 12

## Re: Assignments and Challenges

Posted 06 November 2012 - 11:14 AM

Ah, had great fun with project Euler. 10 solved so far, more to come!
Was This Post Helpful? 0

### #62 Fineaffiliate

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 25-May 14

## Re: Assignments and Challenges

Posted 25 May 2014 - 11:27 PM

I worked all night and all i could find is being left with two questions to answer. Functions getting on my nerves..
The last digit in a n interger value can be extracted from the interger value as the remainder when the interger value is divided by 10. Write a function that uses this method to return the last digit of an interger value.
Was This Post Helpful? 0

### #63 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11314
• Posts: 42,619
• Joined: 27-December 08

## Re: Assignments and Challenges

Posted 26 May 2014 - 11:18 AM

Just a heads up Fineaffiliate- this isn't the place to ask for help on your assignment, but rather to share fun challenges.
Was This Post Helpful? 0

### #64 lexielynne95

• New D.I.C Head

Reputation: 0
• Posts: 17
• Joined: 06-October 14

## Re: Assignments and Challenges

Posted 06 October 2014 - 02:14 PM

Wishing code academy would have a C# course...

Khan Academy allows you to write code and it immediately gives you tips on things it sees wrong
Was This Post Helpful? 0

### #65 lili214

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 10-March 15

## Re: Assignments and Challenges

Posted 10 March 2015 - 05:00 PM

here is one assignment

nt you will write your own simulation of a memory management system for a
process. We are only looking at one process and NOT worrying about multiple processes! There
are several key parts described below that you must consider.
Virtual Memory Map:
You will need to provide a translation map to convert addresses from virtual to physical.
• Addresses are 32-bit.
• Pages are 2KB in size.
• Virtual addresses are composed of PDir (11 bits), PTable (10 bits) and Offset (11 bits).
• Addresses that are below 1GB are in the kernel section (no swapping or virtual memory
area allowed). Addresses above 1GB are in the user section where swapping and virtual
memory areas exist.
• For each page you need to track whether it is a VM Area, swapped, clean/dirty, and
accessed. Since we know pages are 2K aligned you can (MUST) use the trailing bits in the
page table reference to store this information.
Virtual Memory Area:
Virtual memory areas are used to map files (executables, libraries, shared files) to the virtual
memory space of a process.
• Virtual memory areas are given a file to map to the region.
• A starting address is provided where the file is mapped.
• The entire file is mapped contiguously at this location.
• You can assume the file will always fit – no error checking needed.
• VM areas can be read-only OR copy-on-write.
o If Read-only then the page is not stored when you swap out.
o If copy-on-write then the page is stored when you swap out IF the page was
updated.
• Files are loaded only when accessed AND only the portion used is loaded.
• You can use the standard fopen(), fread(), fseek() and fclose() to manage
the file to get the data.
Swap Space:
For swap space you can use a swap file. You can use the standard fopen(), fread(),
fwrite(), fseek() and fclose() to manage the file to read/write the data. I will leave the
design decision to you on how you want to locate pages in this file. However:
• The file should only grow as you need it to (swap file starts at size 0).
• You should only keep one copy of a page in the swap file – the most recent version of the
page that is swapped out.• Remember: You can use part of the virtual address of the page as a key to find the page in
the swap file.
• Lastly … kernel pages are never swapped out!
Paging:
The system is provided with a number of frames that are provided to the user process for use.
When a frame is required by the kernel, it gets a frame, but it is not counted against the number of
frames allocated to the user process (kernel frames are taken from a different unlimited pool of
memory frames).
Searching for a page to replace begins where the last search for a page ended (Round Robin style).
The page replacement algorithm (pseudo code) is as follows:
i = #pages
While (page not allocated AND i > 0)
If (page is free)
Allocate this page and return
If (page is accessed)
Mark page as unaccessed
Decrement i
i = #pages
While (page not allocated AND i > 0)
If (page is clean)
Allocate this page and return
Decrement i
Allocate this page and return
Note that when you allocate a page you must swap out the page (if necessary) and update your
Virtual Memory Map and Swap Space tables accordingly.
Program Interface:
Input to the program is provided through command line arguments. You can assume that all
arguments are valid and ample space will be provided to fit a file that is mapped to memory. A
sample invocation is the following:
swap_sim –l my_exe 1073741824 –l my_kernel 0 –s share_space 1500000000 –f 1024 –r
mem_trace
options:
-l gives the name of a read-only file followed by the address where the file is mapped. This option
can be repeated as many times for each file mapped.
-s gives the name of a copy-on-write file followed by the address where the file is mapped. This
option can be repeated as many times for each file mapped.
-f specifies the number of frames allocated to the user process.-r specifies the memory trace file that is to be processed. This file specifies the virtual addresses
for the sequence of read and write actions that take place during the execution. Each line of the file
specifies either a read or a write.
r address
w address data
For each read and write action specified in the trace file, the simulation will print the contents (32-
bits in hexadecimal) of the memory at that address.
Final statistic output from the program will be the following:
• A count of the number of page faults
• A count of the number of pages swapped out
• A count of the number of pages swapped in
• The number of pages in the swap file you created
• The number of virtual memory pages loaded
Was This Post Helpful? 0

• (5 Pages)
• « First
• 3
• 4
• 5

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }