-----------------------------------------------------CPU.java---------------------------------------------------
--------------------------------------------------------
import java.io.*;
import java.util.Random;
import java.util.Scanner;
public class CPU
{
/*
Declare required registers
*/
static int PC = 0, SP = 1000, IR, AC, X, Y, timerFlag, num_of_instructions = 0;
static int systemStack_top = 2000, userStack_top = 1000;
static boolean userMode = true; // initially set it to true.
// On interrupt set it to false to indicate
//kernel mode
static boolean processingInterrupt = false; // flag to avoid nested interrupt execution
public static void main(String args[])
{
String fileName = null;
// check the command line argument length
if(args.length == 2)
{
fileName = args[0];
timerFlag = Integer.parseInt(args[1]); // set timer ineterrupt value
}
else // if incorrect number of parameters then exit
{
System.out.println(\"Incorrect number of parameters. Process ended.\");
System.exit(0);
}
try
{
/*
Create child process and set up I/O streams
*/
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(\"java Memory\");
OutputStream os = proc.getOutputStream();
PrintWriter pw = new PrintWriter(os);
InputStream is = proc.getInputStream();
Scanner memory_reader = new Scanner(is); // direct input stream to a Scanner object
// Send file name to child process
fileNameToMemory(pw, is, os, fileName);
// this loop will keep the communication going between CPU and memory
while (true)
{
// check to see if timer interrupt has occured
if(num_of_instructions > 0
&& (num_of_instructions % timerFlag) == 0 && processingInterrupt == false)
{
// process the interrupt
processingInterrupt = true;
interruptFromTimer(pw, is, memory_reader, os);
}
// read instruction from memory
int value = readFromMemory(pw, is, memory_reader, os, PC);
if (value != -1)
{
processInstruction(value, pw, is, memory_reader, os);
}
else
break;
}
proc.waitFor();
int exitVal = proc.exitValue();
System.out.println(\"Process exited: \" + exitVal);
}
catch (IOException | InterruptedException t)
{
t.printStackTrace();
}
}
/*
function to send file name to memory
*/
private static void fileNameToMemory(PrintWriter pw, InputStream is, OutputStream os,
String fileName)
{
pw.printf(fileName + \"\ \"); //send filename to memory
pw.flush();
}
// function to read data at given address from memory
private static int readFromMemory(PrintWriter pw, InputStream is, Scanner memory_reader,
OutputStream os, int address)
{
checkMemoryViolation(address);
pw.printf(\"1,\" + address + \"\ \");
pw.flush();
if (memory_reader.hasNext())
{
String temp = memory_reader.next();
if(!temp.isEmpty())
{
int temp2 = Integer.parseInt(temp);
return (temp2);
}
}
return -1;
}
//function to tell child process to write data at the given address in memory
private static void writeToMemory(PrintWriter pw, InputStream is, OutputStream os, int
address, int data) {
pw.printf(\"2,\" + address + \",\" + data + \"\ \"); //2 at the start on st.
This document discusses embedded system development. It begins with definitions of embedded systems and some of their common characteristics like limited resources and real-time constraints. It then discusses specific issues like memory alignment, flash and RAM sizes, and performance optimizations. Examples are given of embedded projects like digital video recorders and how to address issues like file sorting, memory usage and stack overflows. The conclusion emphasizes that embedded systems involve knowledge from many technical fields and stresses the importance of experience, observation, and a positive problem-solving attitude.
This document contains code snippets and outputs from several programming assignments. The assignments involve tasks like displaying logged in users, listing connected devices, modifying process priorities, and measuring system memory. Code examples are provided in C, C++, Python, Java, Shell and Perl to demonstrate the various tasks. The outputs confirm that the programs are working as intended by displaying the expected results.
This sample program demonstrates how to access Meinberg GPS receivers via the binary data protocol. It can work via a serial port or network socket connection depending on the target operating system. It requires several other modules and supports Windows, Linux, QNX, and DOS targets. The program checks return codes from API functions, gets receiver information, status information, position, time zone, and synthesizer settings. It also has the ability to set the synthesizer frequency and phase.
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)CODE BLUE
Modern operating systems include hardened security mechanisms to block exploit attempts. ASLR and NX (DEP) are two examples of the mechanisms that are widely implemented for the sake of security. However, there exists ways to bypass such protections by leveraging advanced exploitation techniques. It becomes harder to achieve code execution when the exploitation originates from a remote location, such as when the attack originates from a client, targeting server daemons. In such cases it is harder to find out the context information of target systems and, therefore, harder to achieve code execution. Knowledge on the memory layout of the targeted process is a crucial piece of the puzzle in developing an exploit, but it is harder to figure out when the exploit attempt is performed remotely. Recently, there have been techniques to leverage information disclosure (memory leak) vulnerabilities to figure out where specific library modules are loaded in the memory layout space, and such classes of vulnerabilities have been proven to be useful to bypass ASLR. However, there is also a different way of figuring out the memory layout of a process running in a remote environment. This method involves probing for valid addresses in target remote process. In a Linux environment, forked child processes will inherit already randomized memory layout from the parent process. Thus every client connection made to server daemons will share the same memory layout. The memory layout randomization is only done during the startup of the parent service process, and not randomized again when it is forking a child process to handle client connections. Due to the inheritance of child processes, it is possible to figure out a small piece of different information from every connection, and these pieces can be assembled later to get the idea of a big picture of the target process's remote memory layout. Probing to see if a given address is a valid memory address in context of the target remote process and assembling such information together, an attacker can figure out where the libc library is loaded on the memory, thus allowing exploits to succeed further in code execution. One might call it brute force, but with a smart brute forcing strategy, the number of minimal required attempts are significantly reduced to less than 10 in usual cases. In this talk, we will be talking about how it is possible to probe for memory layout space utilizing a piece of code to put the target in a blocked state, and to achieve stable code execution in remote exploit attempt scenarios using such information, as well as other tricks that are often used in remote exploit development in the Linux environment.
http://codeblue.jp/en-speaker.html#SeokHaLee
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...Marco Balduzzi
Protocol gateways are embedded devices used in industrial facilities to integrate legacy equipment such as serial PLCs with modern control networks. Given the importance that these devices play in the operation of manufacturing plants, we conducted a vendor agnostic analysis of the technology behind protocol translation, by identifying new unexplored weaknesses and vulnerabilities. We evaluated five popular gateway products and discovered translation problems that enable potential adversaries to conduct stealthy and difficult-to-detect attacks, for example to arbitrarily disable, or enable a targeted machinery by mean of innocent-looking packets that bypass common ICS firewalls. In this presentation, we share the results of our findings and discuss the impact to the problems that we identified and their potential countermeasures.
This document summarizes common C programming concepts including data types, arrays, functions, conditionals, loops, and the main function. It discusses declaring variables of basic data types like int, float, and double. It also covers one-dimensional and two-dimensional arrays, defining functions with different return types, and using if/else, switch, for, while loops for control flow. The main() function is described as the required entry point for all C programs.
This document discusses embedded system development. It begins with definitions of embedded systems and some of their common characteristics like limited resources and real-time constraints. It then discusses specific issues like memory alignment, flash and RAM sizes, and performance optimizations. Examples are given of embedded projects like digital video recorders and how to address issues like file sorting, memory usage and stack overflows. The conclusion emphasizes that embedded systems involve knowledge from many technical fields and stresses the importance of experience, observation, and a positive problem-solving attitude.
This document contains code snippets and outputs from several programming assignments. The assignments involve tasks like displaying logged in users, listing connected devices, modifying process priorities, and measuring system memory. Code examples are provided in C, C++, Python, Java, Shell and Perl to demonstrate the various tasks. The outputs confirm that the programs are working as intended by displaying the expected results.
This sample program demonstrates how to access Meinberg GPS receivers via the binary data protocol. It can work via a serial port or network socket connection depending on the target operating system. It requires several other modules and supports Windows, Linux, QNX, and DOS targets. The program checks return codes from API functions, gets receiver information, status information, position, time zone, and synthesizer settings. It also has the ability to set the synthesizer frequency and phase.
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)CODE BLUE
Modern operating systems include hardened security mechanisms to block exploit attempts. ASLR and NX (DEP) are two examples of the mechanisms that are widely implemented for the sake of security. However, there exists ways to bypass such protections by leveraging advanced exploitation techniques. It becomes harder to achieve code execution when the exploitation originates from a remote location, such as when the attack originates from a client, targeting server daemons. In such cases it is harder to find out the context information of target systems and, therefore, harder to achieve code execution. Knowledge on the memory layout of the targeted process is a crucial piece of the puzzle in developing an exploit, but it is harder to figure out when the exploit attempt is performed remotely. Recently, there have been techniques to leverage information disclosure (memory leak) vulnerabilities to figure out where specific library modules are loaded in the memory layout space, and such classes of vulnerabilities have been proven to be useful to bypass ASLR. However, there is also a different way of figuring out the memory layout of a process running in a remote environment. This method involves probing for valid addresses in target remote process. In a Linux environment, forked child processes will inherit already randomized memory layout from the parent process. Thus every client connection made to server daemons will share the same memory layout. The memory layout randomization is only done during the startup of the parent service process, and not randomized again when it is forking a child process to handle client connections. Due to the inheritance of child processes, it is possible to figure out a small piece of different information from every connection, and these pieces can be assembled later to get the idea of a big picture of the target process's remote memory layout. Probing to see if a given address is a valid memory address in context of the target remote process and assembling such information together, an attacker can figure out where the libc library is loaded on the memory, thus allowing exploits to succeed further in code execution. One might call it brute force, but with a smart brute forcing strategy, the number of minimal required attempts are significantly reduced to less than 10 in usual cases. In this talk, we will be talking about how it is possible to probe for memory layout space utilizing a piece of code to put the target in a blocked state, and to achieve stable code execution in remote exploit attempt scenarios using such information, as well as other tricks that are often used in remote exploit development in the Linux environment.
http://codeblue.jp/en-speaker.html#SeokHaLee
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...Marco Balduzzi
Protocol gateways are embedded devices used in industrial facilities to integrate legacy equipment such as serial PLCs with modern control networks. Given the importance that these devices play in the operation of manufacturing plants, we conducted a vendor agnostic analysis of the technology behind protocol translation, by identifying new unexplored weaknesses and vulnerabilities. We evaluated five popular gateway products and discovered translation problems that enable potential adversaries to conduct stealthy and difficult-to-detect attacks, for example to arbitrarily disable, or enable a targeted machinery by mean of innocent-looking packets that bypass common ICS firewalls. In this presentation, we share the results of our findings and discuss the impact to the problems that we identified and their potential countermeasures.
This document summarizes common C programming concepts including data types, arrays, functions, conditionals, loops, and the main function. It discusses declaring variables of basic data types like int, float, and double. It also covers one-dimensional and two-dimensional arrays, defining functions with different return types, and using if/else, switch, for, while loops for control flow. The main() function is described as the required entry point for all C programs.
Raw sockets allow direct access to network protocols like ICMP and IGMP without using TCP or UDP. They enable implementing new IPv4 protocols, controlling packet headers, and building custom packets. However, raw sockets lose reliability guarantees and require handling network details like packet fragmentation manually. They also require root access on most systems.
The document describes how to port and modify drivers for UART, Ethernet, LCD, and keypad on a Mango100 board running Android. It provides instructions on configuring the kernel, modifying driver source code files, and checking that the drivers are functioning properly. Key steps include enabling drivers in the kernel .config file, adding device registration code, and modifying functions to set GPIO pins and timing parameters for devices like the LCD. It also explains how to view input events in logcat and trace the flow of key events through the Android framework.
The document describes data structures and their implementation using C and C++. It includes:
1) An introduction to data structures and their use in organizing data efficiently.
2) Requirements for using data structures in C and C++ including hardware requirements like RAM and software requirements like Turbo C++.
3) Examples of programs to implement basic data structures like linked lists, stacks, queues and sorting algorithms like insertion sort, bubble sort, quick sort and merge sort.
The document describes data structures and their implementation using C and C++. It includes:
1) An introduction to data structures and their use in organizing data efficiently.
2) Requirements for using data structures in C and C++ including hardware requirements like RAM and software requirements like Turbo C++.
3) Examples of programs to implement basic data structures like linked lists, stacks, queues and sorting algorithms like insertion sort, bubble sort, quick sort and merge sort.
下記論文を扱った研究室内輪読用の資料です
This is slides for group reading in Lab.
Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, "Operating Systems: Three Easy Pieces"
http://pages.cs.wisc.edu/~remzi/OSTEP/
The following code is an implementation of the producer consumer pro.pdfmarketing413921
The following code is an implementation of the producer consumer problem using a software
locking mechanism. Your tasks here require you to debug the code with the intent of achieving
the following tasks:
Task 1: Identifying the critical section
Task 2: Identify the software locks and replace them with a simplified mutex lock and unlock.
HINT: The code provided relies heavily on the in and out pointers of the buffer. You should
make the code run on a single count variable.
#include
#include
#include
#include
#define MAXSIZE 100
#define ITERATIONS 1000
int buffer[MAXSIZE]; // buffer
int nextp, nextc; // temporary storage
int count=0;
void printfunction(void * ptr)
{
int count = *(int *) ptr;
if (count==0)
{
printf(\"All items produced are consumed by the consumer \ \");
}
else
{
for (int i=0; i<=count; i=i+1)
{
printf(\"%d, \\t\",buffer[i]);
}
printf(\"\ \");
}
}
void *producer(void *ptr)
{
int item, flag=0;
int in = *(int *) ptr;
do
{
item = (rand()%7)%10;
flag=flag+1;
nextp=item;
buffer[in]=nextp;
in=((in+1)%MAXSIZE);
while(count <= MAXSIZE)
{
count=count+1;
printf(\"Count = %d - incremented at producer\ \", count);
}
} while (flag<=ITERATIONS);
pthread_exit(NULL);
}
void *consumer(void *ptr)
{
int item, flag=ITERATIONS;
int out = *(int *) ptr;
do
{
while (count >0)
{
nextc = buffer[out];
out=(out+1)%MAXSIZE;
printf(\"\\tCount = %d - decremented at consumer\ \", count, flag);
count = count-1;
flag=flag-1;
}
if (count <= 0)
{
printf(\"consumer made to wait...faster than producer.\ \");
}
}while (flag>=0);
pthread_exit(NULL);
}
int main(void)
{
int in=0, out=0; //pointers
pthread_t pro, con;
// Spawn threads
pthread_create(&pro, NULL, producer, &count);
pthread_create(&con, NULL, consumer, &count);
if (rc1)
{
printf(\"ERROR; return code from pthread_create() is %d\ \", rc1);
exit(-1);
}
if (rc2)
{
printf(\"ERROR; return code from pthread_create() is %d\ \", rc2);
exit(-1);
}
// Wait for the threads to finish
// Otherwise main might run to the end
// and kill the entire process when it exits.
pthread_join(pro, NULL);
pthread_join(con, NULL);
printfunction(&count);
}
Solution
#include
#include
#include
#include
#define MAXSIZE 100
#define ITERATIONS 1000
int buffer[MAXSIZE]; // buffer
int nextp, nextc; // temporary storage
int count=0;
void printfunction(void * ptr)
{
int count = *(int *) ptr;
if (count==0)
{
printf(\"All items produced are consumed by the consumer \ \");
}
else
{
for (int i=0; i<=count; i=i+1)
{
printf(\"%d, \\t\",buffer[i]);
}
printf(\"\ \");
}
}
void *producer(void *ptr)
{
int item, flag=0;
int in = *(int *) ptr;
do
{
item = (rand()%7)%10;
flag=flag+1;
nextp=item;
buffer[in]=nextp;
in=((in+1)%MAXSIZE);
while(count <= MAXSIZE)
{
count=count+1;
printf(\"Count = %d - incremented at producer\ \", count);
}
} while (flag<=ITERATIONS);
pthread_exit(NULL);
}
void *consumer(void *ptr)
{
int item, flag=ITERATIONS;
int out = *(int *) ptr;
do
{
while (count >0)
{
nextc = buffer[out];
out=(out+1)%MAXSIZE;
printf(\"\\tCount = %d - decreme.
Implementing Software Machines in Go and CEleanor McHugh
Early draft of a tutorial on techniques for implementing virtual machines and language interpreters. Contains example programs for functional stacks and despatch loops.
#define ENABLE_COMMANDER
#define ENABLE_REPORTER
#include <cctype> // for toupper()
#include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE
#include <cstring> // for strerror()
#include <cerrno> // for errno
#include <deque> // for deque (used for ready and blocked queues)
#include <fstream> // for ifstream (used for reading simulated process programs)
#include <iostream> // for cout, endl, and cin
#include <sstream> // for stringstream (for parsing simulated process programs)
#include <sys/wait.h> // for wait()
#include <unistd.h> // for pipe(), read(), write(), close(), fork(), and _exit()
#include <vector> // for vector (used for PCB table)
using namespace std;
class Instruction {
public:
char operation;
int intArg;
string stringArg;
};
class Cpu {
public:
vector<Instruction> *pProgram;
int programCounter;
int value;
int timeSlice;
int timeSliceUsed;
};
enum State {
STATE_READY,
STATE_RUNNING,
STATE_BLOCKED,
STATE_END
};
class PcbEntry {
public:
int processId;
int parentProcessId;
vector<Instruction> program;
unsigned int programCounter;
int value;
unsigned int priority;
State state;
unsigned int startTime;
unsigned int timeUsed;
};
// The number of valid priorities.
#define NUM_PRIORITIES 4
// An array that maps priorities to their allotted time slices.
static const unsigned int PRIORITY_TIME_SLICES[NUM_PRIORITIES] = {
1,
2,
4,
8
};
unsigned int timestamp = 0;
Cpu cpu;
// For the states below, -1 indicates empty (since it is an invalid index).
int runningState = -1; // The index of the running process in the PCB table.
// readyStates is an array of queues. Each queue holds PCB indices for ready processes
// of a particular priority.
deque<int> readyStates[NUM_PRIORITIES];
deque<int> blockedState; // A queue fo PCB indices for blocked processes.
deque<int> deadState;
// In this implementation, we'll never explicitly clear PCB entries and the
// index in the table will always be the process ID. These choices waste memory,
// but since this program is just a simulation it the easiest approach.
// Additionally, debugging is simpler since table slots and process IDs are
// never re-used.
vector<PcbEntry *> pcbTable;
double cumulativeTimeDiff = 0;
int numTerminatedProcesses = 0;
// Sadly, C++ has no built-in way to trim strings:
string &trim(string &argument)
{
string whitespace(" \t\n\v\f\r");
size_t found = argument.find_last_not_of(whitespace);
if (found != string::npos) {
argument.erase(found + 1);
argument.erase(0, argument.find_first_not_of(whitespace));
} else {
argument.clear(); // all whitespace
}
return argument;
}
bool createProgram(const string &filename, vector<Instruction> &program)
{
ifstream file;
int lineNum = 0;
program.clear();
file.open(filename.c_str());
if (!file.is_open()) {
cout << "Error opening file " << filename << ...
The run-time stack stores information needed for function calls such as return addresses, parameters, local variables, and CPU register states. It allows for recursive calls, variable parameters, and passing data between the caller and callee functions. The stack grows downward on x86 processors, with the top of the stack represented by the stack pointer register (SP).
The document provides an overview of Arduino programming structures and concepts. It discusses the setup and loop functions, variables and data types, arrays, operators, constants, control structures, and input/output functions like pinMode, digitalRead, analogRead, and analogWrite. It also covers other functions for delay, random numbers, serial communication, and working with sensors like a vibration sensor, accelerometer, ultrasonic sensor, and Bluetooth shield. Example code is provided to read and display sensor values and control an LED.
Buffer overruns occur when a program allows writing more data to a buffer than it was allocated to hold. This can lead to code injection attacks by overwriting memory addresses like return addresses on the stack. Common types of buffer overruns include stack overruns, heap overruns, array indexing errors, and format string bugs. Developers can prevent buffer overruns by carefully handling untrusted user input, using bounds-checked functions, and compiling with protections like GS flags.
The document contains Verilog code for a single cycle processor including modules for a program counter, accumulator, ALU, adder, multiplexers, controller, data memory, instruction memory, and a test bench. It describes the design and implementation of the datapath and controller for a simple CPU using Verilog that performs arithmetic and logical operations on data stored in memory locations.
The document discusses code for serial port (com) device drivers in FreeBSD. It shows code from the comstart() function, which is called by the tty layer when there is outgoing data to transmit. Comstart() grabs the data from the tty queue and sets up the com_softc structure to start transmission. It then calls the chip-specific transmit function. The com_softc structure contains a pointer to the associated tty structure.
This C code defines an exploit that can be used to remotely gain root access on an Apache 2.2.17 server by sending a crafted buffer to port 80. It includes encoded shellcode that executes a reverse shell, and builds a buffer containing NOP sleds, shellcode, and trailing characters to exploit a vulnerability. It connects to the target, sends the malicious buffer, and waits for a reverse shell if successful.
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
The document describes a C++ program that uses object-oriented programming concepts to represent matrices and perform operations on them such as reading, writing, adding, summing elements, and finding the maximum element. The main functionality includes defining a struct to represent matrix elements and nodes, reading in matrices from user input, writing matrices to output, adding two matrices by iterating through their elements, summing all elements of a matrix, and finding the maximum value and its position. The program uses a menu to allow the user to choose which operation to perform on sample matrices.
This document discusses concurrency and parallelism in .NET. It covers three pillars of concurrency: scalability using Parallel.For, responsiveness using tasks and async/await, and consistency using locks, interlocked operations, and mutexes/events/semaphores. It also discusses challenges with shared state and race conditions when naively using Parallel.For on shared data. Several solutions are presented such as not sharing data, using smaller work chunks to reduce overhead, and running completely independent tasks in parallel. The document emphasizes the importance of measuring performance before and after optimizations.
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
The document describes a C++ program that uses object-oriented programming concepts to represent matrices and perform operations on them like addition, finding the maximum value, and calculating the total sum. The program uses linked lists to store the matrix elements and defines functions for reading, writing, adding, and analyzing matrices. It provides a menu-driven interface for users to choose different operations to perform on matrices of varying sizes.
HSA enables more efficient compilation of high-level programming interfaces like OpenACC and C++AMP. For OpenACC, HSA provides flexibility in implementing data transfers and optimizing nested parallel loops. For C++AMP, HSA allows efficient compilation from an even higher level interface where GPU data and kernels are modeled as C++ containers and lambdas, without needing to specify data transfers. Overall, HSA aims to reduce boilerplate code for heterogeneous programming and provide better portability across devices.
You will want to look at electronegativity differ.pdfannikasarees
You will want to look at electronegativity differences between elements in a
molecule. Ionic bonds will only occur when the difference of electronegativity for the bonding
elemets is high, such as Sodium (very low electronegativity) and Chlorine (very high
electronegativity). Depending on which chemistry you are taking, you could even go as simple is
ionic bonding occurs only when bonding elements on different sides of the periodic table.
Phosphorous and Antimony are fairly close to Chlorine, and thus will form a covalent bond. To
find out whether it is polar or non-polar, you must look closer into the difference of
electronegativity in the entire molecule, but for this example, just take a quick glance at a Lewis
Dot Diagram. If the molecule is symmetric (like most organic chemicals), the molecule is non-
polar (like most organic chemicals). If the molecule is not symmetric, it will be polar, like water.
Solution
You will want to look at electronegativity differences between elements in a
molecule. Ionic bonds will only occur when the difference of electronegativity for the bonding
elemets is high, such as Sodium (very low electronegativity) and Chlorine (very high
electronegativity). Depending on which chemistry you are taking, you could even go as simple is
ionic bonding occurs only when bonding elements on different sides of the periodic table.
Phosphorous and Antimony are fairly close to Chlorine, and thus will form a covalent bond. To
find out whether it is polar or non-polar, you must look closer into the difference of
electronegativity in the entire molecule, but for this example, just take a quick glance at a Lewis
Dot Diagram. If the molecule is symmetric (like most organic chemicals), the molecule is non-
polar (like most organic chemicals). If the molecule is not symmetric, it will be polar, like water..
Well 1-Heptanol is a straight chained 7 carbon mo.pdfannikasarees
Well 1-Heptanol is a straight chained 7 carbon molecule with an OHgroup attached
to one end, to state the obvious. Because 1-Heptanol is longer than Ethanol, the Oxygen does
not havemuch of an effect on the electron distribution at the far end ofthe molecule. Conversely,
Ethanol has two carbons attached toan OH group. The electrons around those two carbons
aregreatly affected by the OH group. So if you made a map of polarity of each of these
molecules, theentire Ethanol molecule would likely be affected by the OHgroup. In 1-Heptanol,
the polarity would be concentrated nearthe OH group, but the other end of the molecule would
likely beunaffected by the presence of the OH group. Therefore theEthanol molecule is more
polar, because the entire molecule\'selectron density is affected. Does this make sense? If you
have any questions about myexplanation or you want clarification please ask.
Solution
Well 1-Heptanol is a straight chained 7 carbon molecule with an OHgroup attached
to one end, to state the obvious. Because 1-Heptanol is longer than Ethanol, the Oxygen does
not havemuch of an effect on the electron distribution at the far end ofthe molecule. Conversely,
Ethanol has two carbons attached toan OH group. The electrons around those two carbons
aregreatly affected by the OH group. So if you made a map of polarity of each of these
molecules, theentire Ethanol molecule would likely be affected by the OHgroup. In 1-Heptanol,
the polarity would be concentrated nearthe OH group, but the other end of the molecule would
likely beunaffected by the presence of the OH group. Therefore theEthanol molecule is more
polar, because the entire molecule\'selectron density is affected. Does this make sense? If you
have any questions about myexplanation or you want clarification please ask..
More Related Content
Similar to -----------------------------------------------------CPU.java------.pdf
Raw sockets allow direct access to network protocols like ICMP and IGMP without using TCP or UDP. They enable implementing new IPv4 protocols, controlling packet headers, and building custom packets. However, raw sockets lose reliability guarantees and require handling network details like packet fragmentation manually. They also require root access on most systems.
The document describes how to port and modify drivers for UART, Ethernet, LCD, and keypad on a Mango100 board running Android. It provides instructions on configuring the kernel, modifying driver source code files, and checking that the drivers are functioning properly. Key steps include enabling drivers in the kernel .config file, adding device registration code, and modifying functions to set GPIO pins and timing parameters for devices like the LCD. It also explains how to view input events in logcat and trace the flow of key events through the Android framework.
The document describes data structures and their implementation using C and C++. It includes:
1) An introduction to data structures and their use in organizing data efficiently.
2) Requirements for using data structures in C and C++ including hardware requirements like RAM and software requirements like Turbo C++.
3) Examples of programs to implement basic data structures like linked lists, stacks, queues and sorting algorithms like insertion sort, bubble sort, quick sort and merge sort.
The document describes data structures and their implementation using C and C++. It includes:
1) An introduction to data structures and their use in organizing data efficiently.
2) Requirements for using data structures in C and C++ including hardware requirements like RAM and software requirements like Turbo C++.
3) Examples of programs to implement basic data structures like linked lists, stacks, queues and sorting algorithms like insertion sort, bubble sort, quick sort and merge sort.
下記論文を扱った研究室内輪読用の資料です
This is slides for group reading in Lab.
Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, "Operating Systems: Three Easy Pieces"
http://pages.cs.wisc.edu/~remzi/OSTEP/
The following code is an implementation of the producer consumer pro.pdfmarketing413921
The following code is an implementation of the producer consumer problem using a software
locking mechanism. Your tasks here require you to debug the code with the intent of achieving
the following tasks:
Task 1: Identifying the critical section
Task 2: Identify the software locks and replace them with a simplified mutex lock and unlock.
HINT: The code provided relies heavily on the in and out pointers of the buffer. You should
make the code run on a single count variable.
#include
#include
#include
#include
#define MAXSIZE 100
#define ITERATIONS 1000
int buffer[MAXSIZE]; // buffer
int nextp, nextc; // temporary storage
int count=0;
void printfunction(void * ptr)
{
int count = *(int *) ptr;
if (count==0)
{
printf(\"All items produced are consumed by the consumer \ \");
}
else
{
for (int i=0; i<=count; i=i+1)
{
printf(\"%d, \\t\",buffer[i]);
}
printf(\"\ \");
}
}
void *producer(void *ptr)
{
int item, flag=0;
int in = *(int *) ptr;
do
{
item = (rand()%7)%10;
flag=flag+1;
nextp=item;
buffer[in]=nextp;
in=((in+1)%MAXSIZE);
while(count <= MAXSIZE)
{
count=count+1;
printf(\"Count = %d - incremented at producer\ \", count);
}
} while (flag<=ITERATIONS);
pthread_exit(NULL);
}
void *consumer(void *ptr)
{
int item, flag=ITERATIONS;
int out = *(int *) ptr;
do
{
while (count >0)
{
nextc = buffer[out];
out=(out+1)%MAXSIZE;
printf(\"\\tCount = %d - decremented at consumer\ \", count, flag);
count = count-1;
flag=flag-1;
}
if (count <= 0)
{
printf(\"consumer made to wait...faster than producer.\ \");
}
}while (flag>=0);
pthread_exit(NULL);
}
int main(void)
{
int in=0, out=0; //pointers
pthread_t pro, con;
// Spawn threads
pthread_create(&pro, NULL, producer, &count);
pthread_create(&con, NULL, consumer, &count);
if (rc1)
{
printf(\"ERROR; return code from pthread_create() is %d\ \", rc1);
exit(-1);
}
if (rc2)
{
printf(\"ERROR; return code from pthread_create() is %d\ \", rc2);
exit(-1);
}
// Wait for the threads to finish
// Otherwise main might run to the end
// and kill the entire process when it exits.
pthread_join(pro, NULL);
pthread_join(con, NULL);
printfunction(&count);
}
Solution
#include
#include
#include
#include
#define MAXSIZE 100
#define ITERATIONS 1000
int buffer[MAXSIZE]; // buffer
int nextp, nextc; // temporary storage
int count=0;
void printfunction(void * ptr)
{
int count = *(int *) ptr;
if (count==0)
{
printf(\"All items produced are consumed by the consumer \ \");
}
else
{
for (int i=0; i<=count; i=i+1)
{
printf(\"%d, \\t\",buffer[i]);
}
printf(\"\ \");
}
}
void *producer(void *ptr)
{
int item, flag=0;
int in = *(int *) ptr;
do
{
item = (rand()%7)%10;
flag=flag+1;
nextp=item;
buffer[in]=nextp;
in=((in+1)%MAXSIZE);
while(count <= MAXSIZE)
{
count=count+1;
printf(\"Count = %d - incremented at producer\ \", count);
}
} while (flag<=ITERATIONS);
pthread_exit(NULL);
}
void *consumer(void *ptr)
{
int item, flag=ITERATIONS;
int out = *(int *) ptr;
do
{
while (count >0)
{
nextc = buffer[out];
out=(out+1)%MAXSIZE;
printf(\"\\tCount = %d - decreme.
Implementing Software Machines in Go and CEleanor McHugh
Early draft of a tutorial on techniques for implementing virtual machines and language interpreters. Contains example programs for functional stacks and despatch loops.
#define ENABLE_COMMANDER
#define ENABLE_REPORTER
#include <cctype> // for toupper()
#include <cstdlib> // for EXIT_SUCCESS and EXIT_FAILURE
#include <cstring> // for strerror()
#include <cerrno> // for errno
#include <deque> // for deque (used for ready and blocked queues)
#include <fstream> // for ifstream (used for reading simulated process programs)
#include <iostream> // for cout, endl, and cin
#include <sstream> // for stringstream (for parsing simulated process programs)
#include <sys/wait.h> // for wait()
#include <unistd.h> // for pipe(), read(), write(), close(), fork(), and _exit()
#include <vector> // for vector (used for PCB table)
using namespace std;
class Instruction {
public:
char operation;
int intArg;
string stringArg;
};
class Cpu {
public:
vector<Instruction> *pProgram;
int programCounter;
int value;
int timeSlice;
int timeSliceUsed;
};
enum State {
STATE_READY,
STATE_RUNNING,
STATE_BLOCKED,
STATE_END
};
class PcbEntry {
public:
int processId;
int parentProcessId;
vector<Instruction> program;
unsigned int programCounter;
int value;
unsigned int priority;
State state;
unsigned int startTime;
unsigned int timeUsed;
};
// The number of valid priorities.
#define NUM_PRIORITIES 4
// An array that maps priorities to their allotted time slices.
static const unsigned int PRIORITY_TIME_SLICES[NUM_PRIORITIES] = {
1,
2,
4,
8
};
unsigned int timestamp = 0;
Cpu cpu;
// For the states below, -1 indicates empty (since it is an invalid index).
int runningState = -1; // The index of the running process in the PCB table.
// readyStates is an array of queues. Each queue holds PCB indices for ready processes
// of a particular priority.
deque<int> readyStates[NUM_PRIORITIES];
deque<int> blockedState; // A queue fo PCB indices for blocked processes.
deque<int> deadState;
// In this implementation, we'll never explicitly clear PCB entries and the
// index in the table will always be the process ID. These choices waste memory,
// but since this program is just a simulation it the easiest approach.
// Additionally, debugging is simpler since table slots and process IDs are
// never re-used.
vector<PcbEntry *> pcbTable;
double cumulativeTimeDiff = 0;
int numTerminatedProcesses = 0;
// Sadly, C++ has no built-in way to trim strings:
string &trim(string &argument)
{
string whitespace(" \t\n\v\f\r");
size_t found = argument.find_last_not_of(whitespace);
if (found != string::npos) {
argument.erase(found + 1);
argument.erase(0, argument.find_first_not_of(whitespace));
} else {
argument.clear(); // all whitespace
}
return argument;
}
bool createProgram(const string &filename, vector<Instruction> &program)
{
ifstream file;
int lineNum = 0;
program.clear();
file.open(filename.c_str());
if (!file.is_open()) {
cout << "Error opening file " << filename << ...
The run-time stack stores information needed for function calls such as return addresses, parameters, local variables, and CPU register states. It allows for recursive calls, variable parameters, and passing data between the caller and callee functions. The stack grows downward on x86 processors, with the top of the stack represented by the stack pointer register (SP).
The document provides an overview of Arduino programming structures and concepts. It discusses the setup and loop functions, variables and data types, arrays, operators, constants, control structures, and input/output functions like pinMode, digitalRead, analogRead, and analogWrite. It also covers other functions for delay, random numbers, serial communication, and working with sensors like a vibration sensor, accelerometer, ultrasonic sensor, and Bluetooth shield. Example code is provided to read and display sensor values and control an LED.
Buffer overruns occur when a program allows writing more data to a buffer than it was allocated to hold. This can lead to code injection attacks by overwriting memory addresses like return addresses on the stack. Common types of buffer overruns include stack overruns, heap overruns, array indexing errors, and format string bugs. Developers can prevent buffer overruns by carefully handling untrusted user input, using bounds-checked functions, and compiling with protections like GS flags.
The document contains Verilog code for a single cycle processor including modules for a program counter, accumulator, ALU, adder, multiplexers, controller, data memory, instruction memory, and a test bench. It describes the design and implementation of the datapath and controller for a simple CPU using Verilog that performs arithmetic and logical operations on data stored in memory locations.
The document discusses code for serial port (com) device drivers in FreeBSD. It shows code from the comstart() function, which is called by the tty layer when there is outgoing data to transmit. Comstart() grabs the data from the tty queue and sets up the com_softc structure to start transmission. It then calls the chip-specific transmit function. The com_softc structure contains a pointer to the associated tty structure.
This C code defines an exploit that can be used to remotely gain root access on an Apache 2.2.17 server by sending a crafted buffer to port 80. It includes encoded shellcode that executes a reverse shell, and builds a buffer containing NOP sleds, shellcode, and trailing characters to exploit a vulnerability. It connects to the target, sends the malicious buffer, and waits for a reverse shell if successful.
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
The document describes a C++ program that uses object-oriented programming concepts to represent matrices and perform operations on them such as reading, writing, adding, summing elements, and finding the maximum element. The main functionality includes defining a struct to represent matrix elements and nodes, reading in matrices from user input, writing matrices to output, adding two matrices by iterating through their elements, summing all elements of a matrix, and finding the maximum value and its position. The program uses a menu to allow the user to choose which operation to perform on sample matrices.
This document discusses concurrency and parallelism in .NET. It covers three pillars of concurrency: scalability using Parallel.For, responsiveness using tasks and async/await, and consistency using locks, interlocked operations, and mutexes/events/semaphores. It also discusses challenges with shared state and race conditions when naively using Parallel.For on shared data. Several solutions are presented such as not sharing data, using smaller work chunks to reduce overhead, and running completely independent tasks in parallel. The document emphasizes the importance of measuring performance before and after optimizations.
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
The document describes a C++ program that uses object-oriented programming concepts to represent matrices and perform operations on them like addition, finding the maximum value, and calculating the total sum. The program uses linked lists to store the matrix elements and defines functions for reading, writing, adding, and analyzing matrices. It provides a menu-driven interface for users to choose different operations to perform on matrices of varying sizes.
HSA enables more efficient compilation of high-level programming interfaces like OpenACC and C++AMP. For OpenACC, HSA provides flexibility in implementing data transfers and optimizing nested parallel loops. For C++AMP, HSA allows efficient compilation from an even higher level interface where GPU data and kernels are modeled as C++ containers and lambdas, without needing to specify data transfers. Overall, HSA aims to reduce boilerplate code for heterogeneous programming and provide better portability across devices.
Similar to -----------------------------------------------------CPU.java------.pdf (20)
You will want to look at electronegativity differ.pdfannikasarees
You will want to look at electronegativity differences between elements in a
molecule. Ionic bonds will only occur when the difference of electronegativity for the bonding
elemets is high, such as Sodium (very low electronegativity) and Chlorine (very high
electronegativity). Depending on which chemistry you are taking, you could even go as simple is
ionic bonding occurs only when bonding elements on different sides of the periodic table.
Phosphorous and Antimony are fairly close to Chlorine, and thus will form a covalent bond. To
find out whether it is polar or non-polar, you must look closer into the difference of
electronegativity in the entire molecule, but for this example, just take a quick glance at a Lewis
Dot Diagram. If the molecule is symmetric (like most organic chemicals), the molecule is non-
polar (like most organic chemicals). If the molecule is not symmetric, it will be polar, like water.
Solution
You will want to look at electronegativity differences between elements in a
molecule. Ionic bonds will only occur when the difference of electronegativity for the bonding
elemets is high, such as Sodium (very low electronegativity) and Chlorine (very high
electronegativity). Depending on which chemistry you are taking, you could even go as simple is
ionic bonding occurs only when bonding elements on different sides of the periodic table.
Phosphorous and Antimony are fairly close to Chlorine, and thus will form a covalent bond. To
find out whether it is polar or non-polar, you must look closer into the difference of
electronegativity in the entire molecule, but for this example, just take a quick glance at a Lewis
Dot Diagram. If the molecule is symmetric (like most organic chemicals), the molecule is non-
polar (like most organic chemicals). If the molecule is not symmetric, it will be polar, like water..
Well 1-Heptanol is a straight chained 7 carbon mo.pdfannikasarees
Well 1-Heptanol is a straight chained 7 carbon molecule with an OHgroup attached
to one end, to state the obvious. Because 1-Heptanol is longer than Ethanol, the Oxygen does
not havemuch of an effect on the electron distribution at the far end ofthe molecule. Conversely,
Ethanol has two carbons attached toan OH group. The electrons around those two carbons
aregreatly affected by the OH group. So if you made a map of polarity of each of these
molecules, theentire Ethanol molecule would likely be affected by the OHgroup. In 1-Heptanol,
the polarity would be concentrated nearthe OH group, but the other end of the molecule would
likely beunaffected by the presence of the OH group. Therefore theEthanol molecule is more
polar, because the entire molecule\'selectron density is affected. Does this make sense? If you
have any questions about myexplanation or you want clarification please ask.
Solution
Well 1-Heptanol is a straight chained 7 carbon molecule with an OHgroup attached
to one end, to state the obvious. Because 1-Heptanol is longer than Ethanol, the Oxygen does
not havemuch of an effect on the electron distribution at the far end ofthe molecule. Conversely,
Ethanol has two carbons attached toan OH group. The electrons around those two carbons
aregreatly affected by the OH group. So if you made a map of polarity of each of these
molecules, theentire Ethanol molecule would likely be affected by the OHgroup. In 1-Heptanol,
the polarity would be concentrated nearthe OH group, but the other end of the molecule would
likely beunaffected by the presence of the OH group. Therefore theEthanol molecule is more
polar, because the entire molecule\'selectron density is affected. Does this make sense? If you
have any questions about myexplanation or you want clarification please ask..
The rings cannot attach to each other on C atoms .pdfannikasarees
The rings cannot attach to each other on C atoms in the ring. So the middle CH2 is
assumed present unless otherwise mentioned
Solution
The rings cannot attach to each other on C atoms in the ring. So the middle CH2 is
assumed present unless otherwise mentioned.
Waters bent structure leads to its polar nature.pdfannikasarees
Water\'s bent structure leads to its polar nature, which is the cause for most of its
unique properties. It the molecule were straight, it would not be polar and this would be quite
disruptive. Water would no longer be strongly attracted to itself or other polar molecules. So
water would no longer have surface tension. Insects which walk on water would fall through.
Water would have a far lower boiling point, so it would evaporate much more easily. Also,
boiling water would no longer be hot enough to cook food. The hydrogen bonding character of
water would change, resulting in that ice would no longer be less dense than liquid water, and
therefore ice would sink to the bottom of bodies of water. Most disastrous would be the effect on
living things. Water would no longer be a solvent and so anything which is dissolved in water in
animal\'s bodies would come out of solution. Ions and electrolytes would come out of the water
and clump up in the body. Without water to dissolve things, the blood could no longer carry
certain essential chemicals to the cells, nor could it carry certain toxic wastes away from cells.
Cellular metabolism would soon cease to function and life as we know it would for the most part
cease. ===================== If water were a linear molecule, would it still be polar? 1
Yes No .Would the water molecules still be able to form hydrogen bonds with one another? 2
Yes No . ANsWER Answer Details 1. no 2. yes. note: if the water molecule is linear, the net
dipole moment is zero. thus, it is not polar. However, the O-H bond is still polar due to the
different electronegativity of O and H atoms. Thus, the H---O-H hydrogen bonds still exist.
Solution
Water\'s bent structure leads to its polar nature, which is the cause for most of its
unique properties. It the molecule were straight, it would not be polar and this would be quite
disruptive. Water would no longer be strongly attracted to itself or other polar molecules. So
water would no longer have surface tension. Insects which walk on water would fall through.
Water would have a far lower boiling point, so it would evaporate much more easily. Also,
boiling water would no longer be hot enough to cook food. The hydrogen bonding character of
water would change, resulting in that ice would no longer be less dense than liquid water, and
therefore ice would sink to the bottom of bodies of water. Most disastrous would be the effect on
living things. Water would no longer be a solvent and so anything which is dissolved in water in
animal\'s bodies would come out of solution. Ions and electrolytes would come out of the water
and clump up in the body. Without water to dissolve things, the blood could no longer carry
certain essential chemicals to the cells, nor could it carry certain toxic wastes away from cells.
Cellular metabolism would soon cease to function and life as we know it would for the most part
cease. ===================== If water were a linear molecule, would it still be pol.
The given set of values cannot be represented as .pdfannikasarees
The given set of values cannot be represented as a combination of one another.
There they are linearly independent,
Solution
The given set of values cannot be represented as a combination of one another.
There they are linearly independent,.
Solution containing HCN and NaCN in ions form as .pdfannikasarees
Solution
containing HCN and NaCN in ions form as HCN(aq), H3O+(aq) ,CN- (aq) and Na+ (aq) when
adding acid H3O+ (of acid) + CN- <--> HCN + H2O When adding base OH- + H3O+ --> 2H2O.
lone pairs of electrons also occupy the orbitals .pdfannikasarees
lone pairs of electrons also occupy the orbitals in the valence shell of an atom in a
molecule. Thus, it affect the hybridization of an atom and the geometry of the molecule.
Solution
lone pairs of electrons also occupy the orbitals in the valence shell of an atom in a
molecule. Thus, it affect the hybridization of an atom and the geometry of the molecule..
What is the relationship between Accounting and an Accounting inform.pdfannikasarees
What is the relationship between Accounting and an Accounting information system? (2.5
Marks)
Accounting-Methods, procedures, and standards followed in accumulating, classifying,
recording, and reporting business events and transactions. The accounting system includes the
formal records and original source data. Regulatory requirements may exist on how a particular
accounting system is to be maintained (e.g., insurance company).
Accounting Information System-Subsystem of a Management Information System (MIS) that
processes financial transactions to provide (1) internal reporting to managers for use in planning
and controlling current and future operations and for nonroutine decision making; (2) external
reporting to outside parties such as to stockholders, creditors, and government agencies.
• What has happened to the relationship over the years? (2.5 Marks)
Accounting and Information technology are two terms which are the used in every business .
Because both are needed for effective working of a corporate or company. It is the need of time
that we should understand the relationship between Accounting and Information Technology .
Accounting is related recording and utilisation of recorded data . Information technology is
scientific , technological , engineering disciplines and management technique used in
information handling and processing , their application , computers and their interaction with
men and machines and associated , economical and cultural matters . In Simple wording IT is
that technique which and get and utilize the information with effective and efficient way.
Now , we are ready for giving the relationship between Accounting And Information
technology.
Both are related to get information and utilization of that information . So both are
interconnected with each other . If our specialize of both area merge both system with scientific
and technical way , then they easily overcome the different problems due to lack of correct and
adequate information related to business.
• What is accounting information? (1 marks)
Accounting information can be classified into two categories: financial accounting or public
information and managerial accounting or private information. Financial accounting includes
information disseminated to parties that are not part of the enterprise proper—stockholders,
creditors, customers, suppliers, regulatory commissions, financial analysts, and trade
associations—although the information is also of interest to the company\'s officers and
managers. Such information relates to the financial position, liquidity (that is, ability to convert
to cash), and profitability of an enterprise.
Managerial accounting deals with cost-profit-volume relationships, efficiency and productivity,
planning and control, pricing decisions, capital budgeting, and similar matters. This information
is not generally disseminated outside the company. Whereas the general-purpose financial
statements of financial accounting are assumed.
Yes,all macromolecule are passed from nuclear pore envelope to cytop.pdfannikasarees
Yes,all macromolecule are passed from nuclear pore envelope to cytoplasmic
compartments(including ER).Transport of macromolecules between the nuclear and cytoplasmic
compartments occurs through nuclear pore complexes that span the double membrane of this
envelope.
Solution
Yes,all macromolecule are passed from nuclear pore envelope to cytoplasmic
compartments(including ER).Transport of macromolecules between the nuclear and cytoplasmic
compartments occurs through nuclear pore complexes that span the double membrane of this
envelope..
The transport of sodium ions and glucose into the cell is through sy.pdfannikasarees
The transport of sodium ions and glucose into the cell is through symnport. For every two
sodium ions transported into cell, one glucose is also transported in the same direction. The
concentration gradient of sodium is used to transport glucose into the cell, against its own
concentration gradient (that is, irrespective of the concentration of glucose). This is why, though
the glucose concentration inside the cell is higher compared to the cell exterior, glucose is
transported inside.
In the given experiment, the concentration of sodium ions inside the cell is initially low or very
less. There is a large concentration gradient of Na+ ions, due to which they are transported into
the cell easily. Glucose is also transported along with, without any hindrance. When equilibrium
is attained between the cell exterior and the cell interior with respect to sodium ions, there is no
net movement of ions into the cell. Therefore, symport of glucose is stopped.
When the concentration of extracellular Na+ ions increases, the concentration gradient also
increases as a result of which there is high net movement of Na+ ions into the cells. The cells
reaches equilibrium quickly, and this is why the plateau is reached.
B. Leaky channels allow leaking of Na+ and K+ ions to leak down their concentration gradient.
Therefore, apart from Na+ K+ pump, the channels also transport the ions, without transporting
glucose. Therefore, less glucose enters the cells, the cells reach equilibrium quickly.
Solution
The transport of sodium ions and glucose into the cell is through symnport. For every two
sodium ions transported into cell, one glucose is also transported in the same direction. The
concentration gradient of sodium is used to transport glucose into the cell, against its own
concentration gradient (that is, irrespective of the concentration of glucose). This is why, though
the glucose concentration inside the cell is higher compared to the cell exterior, glucose is
transported inside.
In the given experiment, the concentration of sodium ions inside the cell is initially low or very
less. There is a large concentration gradient of Na+ ions, due to which they are transported into
the cell easily. Glucose is also transported along with, without any hindrance. When equilibrium
is attained between the cell exterior and the cell interior with respect to sodium ions, there is no
net movement of ions into the cell. Therefore, symport of glucose is stopped.
When the concentration of extracellular Na+ ions increases, the concentration gradient also
increases as a result of which there is high net movement of Na+ ions into the cells. The cells
reaches equilibrium quickly, and this is why the plateau is reached.
B. Leaky channels allow leaking of Na+ and K+ ions to leak down their concentration gradient.
Therefore, apart from Na+ K+ pump, the channels also transport the ions, without transporting
glucose. Therefore, less glucose enters the cells, the cells reach equilibrium qu.
the issue of camera and cell phone privecy is importent many cell ph.pdfannikasarees
the issue of camera and cell phone privecy is importent many cell phone cameras by default and
automatically reveal amount of information such as physical location of picture,time,and date
etc...a number of companies facilities along with laws and implimentation have increased it is
often difficult what privacy protection you have.
according to the indectments the accused conducted sexual conversation with researcher person
posting as 13 years old girls.some of them committed indecent act before the women\'s
eyes.others sent them pronography. and all of themarranged to meet researchers apartments an
acters was waiting for them there. after the man spoke with her briefly the program moderator
showed up andconfronted them. thje men were arrested on camera by police
Solution
the issue of camera and cell phone privecy is importent many cell phone cameras by default and
automatically reveal amount of information such as physical location of picture,time,and date
etc...a number of companies facilities along with laws and implimentation have increased it is
often difficult what privacy protection you have.
according to the indectments the accused conducted sexual conversation with researcher person
posting as 13 years old girls.some of them committed indecent act before the women\'s
eyes.others sent them pronography. and all of themarranged to meet researchers apartments an
acters was waiting for them there. after the man spoke with her briefly the program moderator
showed up andconfronted them. thje men were arrested on camera by police.
Statement showing distribution of income to XavierThus answer will.pdfannikasarees
Statement showing distribution of income to Xavier
Thus answer will be $42500Interest on investment5000Salary27000Remainder income
(21000/2)10500Total distribution42500
Solution
Statement showing distribution of income to Xavier
Thus answer will be $42500Interest on investment5000Salary27000Remainder income
(21000/2)10500Total distribution42500.
SolutionBy observing the graph , the graph the given function is .pdfannikasarees
Solution
:
By observing the graph , the graph the given function is not a function;
Vertical test:
if u draw a vertical line on the graph , then it touches the graph at one point only, then the grpah
is a function.
but in the given graph , iit is touchig more than one point . Therefore, it is not a function..
R is a very flexible and powerful programming language, as well as a.pdfannikasarees
R is a very flexible and powerful programming language, as well as a package that is written
using that language (and others like C). The following program demonstrates many of its basic
features. You can cut and paste it into R, or download the file that includes it from here. If you
run it line by line, many of its features will become clear. Both editions of R for SAS and SPSS
Users and R for Stata Users work through a version of this program line-by-line, showing the
output and explaining what R is doing.
# Filename: ProgrammingBasics.R
# ---Simple Calculations---
2 + 3
x <- 2
y <- 3
x + y
x * y
# ---Data Structures---
# Vectors
workshop <- c(1, 2, 1, 2, 1, 2, 1, 2)
print(workshop)
workshop
gender <- c(\"f\", \"f\", \"f\", NA, \"m\", \"m\", \"m\", \"m\")
q1 <- c(1, 2, 2, 3, 4, 5, 5, 4)
q2 <- c(1, 1, 2, 1, 5, 4, 3, 5)
q3 <- c(5, 4, 4,NA, 2, 5, 4, 5)
q4 <- c(1, 1, 3, 3, 4, 5, 4, 5)
# Selecting Elements of Vectors
q1[5]
q1[ c(5, 6, 7, 8) ]
q1[5:8]
q1[gender == \"m\"]
mean( q1[ gender == \"m\" ], na.rm = TRUE)
# ---Factors---
# Numeric Factors
# First, as a vector
workshop <- c(1, 2, 1, 2, 1, 2, 1, 2)
workshop
table(workshop)
mean(workshop)
gender[workshop == 2]
# Now as a factor
workshop <- c(1, 2, 1, 2, 1, 2, 1, 2)
workshop <- factor(workshop)
workshop
table(workshop)
mean(workshop) #generates error now.
gender[workshop == 2]
gender[workshop == \"2\"]
# Recreate workshop, making it a factor
# including levels that don\'t yet exist.
workshop <- c(1, 2, 1, 2, 1, 2, 1, 2)
workshop <- factor(
workshop,
levels = c( 1, 2, 3, 4),
labels = c(\"R\", \"SAS\", \"SPSS\", \"Stata\")
)
# Recreate it with just the levels it
# curently has.
workshop <- c(1, 2, 1, 2, 1, 2, 1, 2)
workshop <- factor(
workshop,
levels = c( 1, 2),
labels = c(\"R\",\"SAS\")
)
workshop
table(workshop)
gender[workshop == 2]
gender[workshop == \"2\"]
gender[workshop == \"SAS\"]
# Character factors
gender <- c(\"f\", \"f\", \"f\", NA, \"m\", \"m\", \"m\", \"m\")
gender <- factor(
gender,
levels = c(\"m\", \"f\"),
labels = c(\"Male\", \"Female\")
)
gender
table(gender)
workshop[gender == \"m\"]
workshop[gender == \"Male\"]
# Recreate gender and make it a factor,
# keeping simpler m and f as labels.
gender <- c(\"f\", \"f\", \"f\", NA, \"m\", \"m\", \"m\", \"m\")
gender <- factor(gender)
gender
# Data Frames
mydata <- data.frame(workshop, gender, q1, q2, q3, q4)
mydata
names(mydata)
row.names(mydata)
# Selecting components by index number
mydata[8, 6] #8th obs, 6th var
mydata[ , 6] #All obs, 6th var
mydata[ , 6][5:8] #6th var, obs 5:8
# Selecting components by name
mydata$q1
mydata$q1[5:8]
# Example renaming gender to sex while
# creating a data frame (left as a comment)
#
# mydata <- data.frame(workshop, sex = gender,
# q1, q2, q3, q4)
# Matrices
# Creating from vectors
mymatrix <- cbind(q1, q2, q3, q4)
mymatrix
dim(mymatrix)
# Creating from matrix function
# left as a comment so we keep
# version with names q1, q2...
#
# mymatrix <- matrix(
# c(1, 1, 5, 1,
# 2, 1, 4, 1,
# 2, 2, 4, 3.
please give the name of author so that i can give u solution manual .pdfannikasarees
please give the name of author so that i can give u solution manual !!
thanks
Solution
please give the name of author so that i can give u solution manual !!
thanks.
PetTest.javaimport java.util.Scanner; public class PetTest {.pdfannikasarees
PetTest.java
import java.util.Scanner;
public class PetTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Pet p[] = new Pet[2];
for(int i=0; i
Solution
PetTest.java
import java.util.Scanner;
public class PetTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Pet p[] = new Pet[2];
for(int i=0; i.
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
How to Fix the Import Error in the Odoo 17Celine George
An import error occurs when a program fails to import a module or library, disrupting its execution. In languages like Python, this issue arises when the specified module cannot be found or accessed, hindering the program's functionality. Resolving import errors is crucial for maintaining smooth software operation and uninterrupted development processes.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
1. -----------------------------------------------------CPU.java---------------------------------------------------
--------------------------------------------------------
import java.io.*;
import java.util.Random;
import java.util.Scanner;
public class CPU
{
/*
Declare required registers
*/
static int PC = 0, SP = 1000, IR, AC, X, Y, timerFlag, num_of_instructions = 0;
static int systemStack_top = 2000, userStack_top = 1000;
static boolean userMode = true; // initially set it to true.
// On interrupt set it to false to indicate
//kernel mode
static boolean processingInterrupt = false; // flag to avoid nested interrupt execution
public static void main(String args[])
{
String fileName = null;
// check the command line argument length
if(args.length == 2)
{
fileName = args[0];
timerFlag = Integer.parseInt(args[1]); // set timer ineterrupt value
}
else // if incorrect number of parameters then exit
{
System.out.println("Incorrect number of parameters. Process ended.");
System.exit(0);
}
try
2. {
/*
Create child process and set up I/O streams
*/
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("java Memory");
OutputStream os = proc.getOutputStream();
PrintWriter pw = new PrintWriter(os);
InputStream is = proc.getInputStream();
Scanner memory_reader = new Scanner(is); // direct input stream to a Scanner object
// Send file name to child process
fileNameToMemory(pw, is, os, fileName);
// this loop will keep the communication going between CPU and memory
while (true)
{
// check to see if timer interrupt has occured
if(num_of_instructions > 0
&& (num_of_instructions % timerFlag) == 0 && processingInterrupt == false)
{
// process the interrupt
processingInterrupt = true;
interruptFromTimer(pw, is, memory_reader, os);
}
// read instruction from memory
int value = readFromMemory(pw, is, memory_reader, os, PC);
if (value != -1)
{
processInstruction(value, pw, is, memory_reader, os);
}
else
break;
3. }
proc.waitFor();
int exitVal = proc.exitValue();
System.out.println("Process exited: " + exitVal);
}
catch (IOException | InterruptedException t)
{
t.printStackTrace();
}
}
/*
function to send file name to memory
*/
private static void fileNameToMemory(PrintWriter pw, InputStream is, OutputStream os,
String fileName)
{
pw.printf(fileName + " "); //send filename to memory
pw.flush();
}
// function to read data at given address from memory
private static int readFromMemory(PrintWriter pw, InputStream is, Scanner memory_reader,
OutputStream os, int address)
{
checkMemoryViolation(address);
pw.printf("1," + address + " ");
pw.flush();
if (memory_reader.hasNext())
{
String temp = memory_reader.next();
if(!temp.isEmpty())
{
int temp2 = Integer.parseInt(temp);
return (temp2);
}
}
4. return -1;
}
//function to tell child process to write data at the given address in memory
private static void writeToMemory(PrintWriter pw, InputStream is, OutputStream os, int
address, int data) {
pw.printf("2," + address + "," + data + " "); //2 at the start on string indicates write
pw.flush();
}
// function to process an instruction received from the memory
private static void processInstruction(int value, PrintWriter pw, InputStream is, Scanner
memory_reader, OutputStream os)
{
IR = value; //store instruction in Instruction register
int operand; //to store operand
switch(IR)
{
case 1: //Load the value into the AC
PC++; // increment counter to get operand
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = operand;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 2: // Load the value at the address into the AC
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = readFromMemory(pw, is, memory_reader, os, operand);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 3: // Load the value from the address found in the address into the AC
5. PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
operand = readFromMemory(pw, is, memory_reader, os, operand);
AC = readFromMemory(pw, is, memory_reader, os, operand);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 4: // Load the value at (address+X) into the AC
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = readFromMemory(pw, is, memory_reader, os, operand + X);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 5: //Load the value at (address+Y) into the AC
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = readFromMemory(pw, is, memory_reader, os, operand + Y);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 6: //Load from (Sp+X) into the AC
AC = readFromMemory(pw, is, memory_reader, os, SP + X);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 7: //Store the value in the AC into the address
6. PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
writeToMemory(pw, is, os, operand, AC);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 8: //Gets a random int from 1 to 100 into the AC
Random r = new Random();
int i = r.nextInt(100) + 1;
AC = i;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 9: //If port=1, writes AC as an int to the screen
//If port=2, writes AC as a char to the screen
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
if(operand == 1)
{
System.out.print(AC);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
}
else if (operand == 2)
{
System.out.print((char)AC);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
7. }
else
{
System.out.println("Error: Port = " + operand);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
System.exit(0);
break;
}
case 10: // Add the value in X to the AC
AC = AC + X;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 11: //Add the value in Y to the AC
AC = AC + Y;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 12: //Subtract the value in X from the AC
AC = AC - X;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 13: //Subtract the value in Y from the AC
AC = AC - Y;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
8. break;
case 14: //Copy the value in the AC to X
X = AC;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 15: //Copy the value in X to the AC
AC = X;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 16: //Copy the value in the AC to Y
Y = AC;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 17: //Copy the value in Y to the AC
AC = Y;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 18: //Copy the value in AC to the SP
SP = AC;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
9. break;
case 19: //Copy the value in SP to the AC
AC = SP;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 20: // Jump to the address
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 21: // Jump to the address only if the value in the AC is zero
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
if (AC == 0)
{
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
}
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 22: // Jump to the address only if the value in the AC is not zero
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
10. if (AC != 0)
{
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
}
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 23: //Push return address onto stack, jump to the address
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
pushValueToStack(pw, is, os,PC+1);
userStack_top = SP;
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 24: //Pop return address from the stack, jump to the address
operand = popValueFromStack(pw, is, memory_reader, os);
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 25: //Increment the value in X
X++;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
11. case 26: //Decrement the value in X
X--;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 27: // Push AC onto stack
pushValueToStack(pw, is, os,AC);
PC++;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 28: //Pop from stack into AC
AC = popValueFromStack(pw, is, memory_reader, os);
PC++;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 29: // Int call. Set system mode, switch stack, push SP and PC, set new SP and PC
processingInterrupt = true;
userMode = false;
operand = SP;
SP = 2000;
pushValueToStack(pw, is, os, operand);
operand = PC + 1;
PC = 1500;
pushValueToStack(pw, is, os, operand);
if(processingInterrupt == false)
num_of_instructions++;
12. break;
case 30: //Restore registers, set user mode
PC = popValueFromStack(pw, is, memory_reader, os);
SP = popValueFromStack(pw, is, memory_reader, os);
userMode = true;
num_of_instructions++;
processingInterrupt = false;
break;
case 50: // End Execution
if(processingInterrupt == false)
num_of_instructions++;
System.exit(0);
break;
default:
System.out.println("Unknown error - default");
System.exit(0);
break;
}
}
// function to check if user program if trying to access system memory and stack
private static void checkMemoryViolation(int address)
{
if(userMode && address > 1000)
{
System.out.println("Error: User tried to access system stack. Process exiting.");
System.exit(0);
}
}
// function to handle interrupts caused by the timer
13. private static void interruptFromTimer(PrintWriter pw, InputStream is, Scanner
memory_reader, OutputStream os)
{
int operand;
userMode = false;
operand = SP;
SP = systemStack_top;
pushValueToStack(pw, is, os, operand);
operand = PC;
PC = 1000;
pushValueToStack(pw, is, os, operand);
}
// function to push a value to the appropriate stack
private static void pushValueToStack(PrintWriter pw, InputStream is, OutputStream os, int
value)
{
SP--;
writeToMemory(pw, is, os, SP, value);
}
// function to pop a value from the appropriate stack
private static int popValueFromStack(PrintWriter pw, InputStream is, Scanner
memory_reader, OutputStream os)
{
int temp = readFromMemory(pw, is, memory_reader, os, SP);
writeToMemory(pw, is, os, SP, 0);
SP++;
return temp;
}
// function to debug program
/*private static void printDebug(String desc, int value)
{
System.out.println("");
System.out.println(desc);
System.out.println("PC = " + PC + " SP = " + SP + " AC = " + AC + " X = " + X + "
Y = " + Y);
14. System.out.println("instructions = " + num_of_instructions + " timerFlag = " +
timerFlag);
System.out.println("user mode = " + userMode + " value read from mem = " + value);
System.out.println("processing Interrupt = " + processingInterrupt);
}*/
}
--------------------------------------------------------------Memory.java--------------------------------------
---------------------------------------------------
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Memory
{
final static int [] memory = new int[2000]; // int array to implement memory
public static void main(String args[])
{
try
{
//Create a File object and a scanner to read it
Scanner CPU_reader = new Scanner(System.in);
File file = null;
if(CPU_reader.hasNextLine()) // read file name from CPU
{
file = new File(CPU_reader.nextLine());
if(!file.exists()) //exit if file not found
{
System.out.println("File not found");
System.exit(0);
}
}
// call function to read file and initialize memory array
15. readFile(file);
String line;
int temp2;
/*
This while loop will keep on reading instructions from the CPU process
and perform the read or write function appropriately
*/
while(true)
{
if(CPU_reader.hasNext())
{
line = CPU_reader.nextLine(); //read the comma delimited line sent by the CPU
if(!line.isEmpty())
{
String [] j = line.split(","); //split the line to get the necessary tokens
// if first token is 1 then CPU is requesting to read
// from an address
if(j[0].equals("1"))
{
temp2 = Integer.parseInt(j[1]);
System.out.println(read(temp2));// send requested data to CPU
}
// else it will be 2, which means CPu is requesting to
// write data at a particular address
else
{
int i1 = Integer.parseInt(j[1]);
int i2 = Integer.parseInt(j[2]);
write(i1,i2); // invoke the write function
}
}
else
break;
}
16. else
break;
}
} catch(NumberFormatException e)
{
e.printStackTrace();
}
}
// function to read the data in the address provided by the CPU
public static int read(int address)
{
return memory[address];
}
// function to write data into an address based on intruction given by CPU
public static void write(int address, int data)
{
memory[address] = data;
}
// function to read instructions from file and initialize memory
private static void readFile(File file) {
try
{
Scanner scanner = new Scanner(file);
String temp;
int temp_int;
int i = 0;
/*
* Read the file to load memory instructions
*/
while(scanner.hasNext())
{
//if integer found then write to memory array
17. if(scanner.hasNextInt())
{
temp_int = scanner.nextInt();
memory[i++] = temp_int;
}
else
{
temp = scanner.next();
// if token starts with ".", then move the counter appropriately
if(temp.charAt(0) == '.')
{
i = Integer.parseInt(temp.substring(1));
}
// else if the token is a comment then skip the line
else if(temp.equals("//"))
{
scanner.nextLine();
}
// skip the line if anything else
else
scanner.nextLine();
}
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
}
}
Solution
18. -----------------------------------------------------CPU.java---------------------------------------------------
--------------------------------------------------------
import java.io.*;
import java.util.Random;
import java.util.Scanner;
public class CPU
{
/*
Declare required registers
*/
static int PC = 0, SP = 1000, IR, AC, X, Y, timerFlag, num_of_instructions = 0;
static int systemStack_top = 2000, userStack_top = 1000;
static boolean userMode = true; // initially set it to true.
// On interrupt set it to false to indicate
//kernel mode
static boolean processingInterrupt = false; // flag to avoid nested interrupt execution
public static void main(String args[])
{
String fileName = null;
// check the command line argument length
if(args.length == 2)
{
fileName = args[0];
timerFlag = Integer.parseInt(args[1]); // set timer ineterrupt value
}
else // if incorrect number of parameters then exit
{
System.out.println("Incorrect number of parameters. Process ended.");
System.exit(0);
}
try
{
19. /*
Create child process and set up I/O streams
*/
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("java Memory");
OutputStream os = proc.getOutputStream();
PrintWriter pw = new PrintWriter(os);
InputStream is = proc.getInputStream();
Scanner memory_reader = new Scanner(is); // direct input stream to a Scanner object
// Send file name to child process
fileNameToMemory(pw, is, os, fileName);
// this loop will keep the communication going between CPU and memory
while (true)
{
// check to see if timer interrupt has occured
if(num_of_instructions > 0
&& (num_of_instructions % timerFlag) == 0 && processingInterrupt == false)
{
// process the interrupt
processingInterrupt = true;
interruptFromTimer(pw, is, memory_reader, os);
}
// read instruction from memory
int value = readFromMemory(pw, is, memory_reader, os, PC);
if (value != -1)
{
processInstruction(value, pw, is, memory_reader, os);
}
else
break;
}
20. proc.waitFor();
int exitVal = proc.exitValue();
System.out.println("Process exited: " + exitVal);
}
catch (IOException | InterruptedException t)
{
t.printStackTrace();
}
}
/*
function to send file name to memory
*/
private static void fileNameToMemory(PrintWriter pw, InputStream is, OutputStream os,
String fileName)
{
pw.printf(fileName + " "); //send filename to memory
pw.flush();
}
// function to read data at given address from memory
private static int readFromMemory(PrintWriter pw, InputStream is, Scanner memory_reader,
OutputStream os, int address)
{
checkMemoryViolation(address);
pw.printf("1," + address + " ");
pw.flush();
if (memory_reader.hasNext())
{
String temp = memory_reader.next();
if(!temp.isEmpty())
{
int temp2 = Integer.parseInt(temp);
return (temp2);
}
}
return -1;
21. }
//function to tell child process to write data at the given address in memory
private static void writeToMemory(PrintWriter pw, InputStream is, OutputStream os, int
address, int data) {
pw.printf("2," + address + "," + data + " "); //2 at the start on string indicates write
pw.flush();
}
// function to process an instruction received from the memory
private static void processInstruction(int value, PrintWriter pw, InputStream is, Scanner
memory_reader, OutputStream os)
{
IR = value; //store instruction in Instruction register
int operand; //to store operand
switch(IR)
{
case 1: //Load the value into the AC
PC++; // increment counter to get operand
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = operand;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 2: // Load the value at the address into the AC
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = readFromMemory(pw, is, memory_reader, os, operand);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 3: // Load the value from the address found in the address into the AC
PC++;
22. operand = readFromMemory(pw, is, memory_reader, os, PC);
operand = readFromMemory(pw, is, memory_reader, os, operand);
AC = readFromMemory(pw, is, memory_reader, os, operand);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 4: // Load the value at (address+X) into the AC
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = readFromMemory(pw, is, memory_reader, os, operand + X);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 5: //Load the value at (address+Y) into the AC
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
AC = readFromMemory(pw, is, memory_reader, os, operand + Y);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 6: //Load from (Sp+X) into the AC
AC = readFromMemory(pw, is, memory_reader, os, SP + X);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 7: //Store the value in the AC into the address
PC++;
23. operand = readFromMemory(pw, is, memory_reader, os, PC);
writeToMemory(pw, is, os, operand, AC);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 8: //Gets a random int from 1 to 100 into the AC
Random r = new Random();
int i = r.nextInt(100) + 1;
AC = i;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 9: //If port=1, writes AC as an int to the screen
//If port=2, writes AC as a char to the screen
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
if(operand == 1)
{
System.out.print(AC);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
}
else if (operand == 2)
{
System.out.print((char)AC);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
}
24. else
{
System.out.println("Error: Port = " + operand);
if(processingInterrupt == false)
num_of_instructions++;
PC++;
System.exit(0);
break;
}
case 10: // Add the value in X to the AC
AC = AC + X;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 11: //Add the value in Y to the AC
AC = AC + Y;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 12: //Subtract the value in X from the AC
AC = AC - X;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 13: //Subtract the value in Y from the AC
AC = AC - Y;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
25. case 14: //Copy the value in the AC to X
X = AC;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 15: //Copy the value in X to the AC
AC = X;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 16: //Copy the value in the AC to Y
Y = AC;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 17: //Copy the value in Y to the AC
AC = Y;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 18: //Copy the value in AC to the SP
SP = AC;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
26. case 19: //Copy the value in SP to the AC
AC = SP;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 20: // Jump to the address
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 21: // Jump to the address only if the value in the AC is zero
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
if (AC == 0)
{
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
}
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 22: // Jump to the address only if the value in the AC is not zero
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
if (AC != 0)
27. {
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
}
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 23: //Push return address onto stack, jump to the address
PC++;
operand = readFromMemory(pw, is, memory_reader, os, PC);
pushValueToStack(pw, is, os,PC+1);
userStack_top = SP;
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 24: //Pop return address from the stack, jump to the address
operand = popValueFromStack(pw, is, memory_reader, os);
PC = operand;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 25: //Increment the value in X
X++;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
28. case 26: //Decrement the value in X
X--;
if(processingInterrupt == false)
num_of_instructions++;
PC++;
break;
case 27: // Push AC onto stack
pushValueToStack(pw, is, os,AC);
PC++;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 28: //Pop from stack into AC
AC = popValueFromStack(pw, is, memory_reader, os);
PC++;
if(processingInterrupt == false)
num_of_instructions++;
break;
case 29: // Int call. Set system mode, switch stack, push SP and PC, set new SP and PC
processingInterrupt = true;
userMode = false;
operand = SP;
SP = 2000;
pushValueToStack(pw, is, os, operand);
operand = PC + 1;
PC = 1500;
pushValueToStack(pw, is, os, operand);
if(processingInterrupt == false)
num_of_instructions++;
29. break;
case 30: //Restore registers, set user mode
PC = popValueFromStack(pw, is, memory_reader, os);
SP = popValueFromStack(pw, is, memory_reader, os);
userMode = true;
num_of_instructions++;
processingInterrupt = false;
break;
case 50: // End Execution
if(processingInterrupt == false)
num_of_instructions++;
System.exit(0);
break;
default:
System.out.println("Unknown error - default");
System.exit(0);
break;
}
}
// function to check if user program if trying to access system memory and stack
private static void checkMemoryViolation(int address)
{
if(userMode && address > 1000)
{
System.out.println("Error: User tried to access system stack. Process exiting.");
System.exit(0);
}
}
// function to handle interrupts caused by the timer
private static void interruptFromTimer(PrintWriter pw, InputStream is, Scanner
30. memory_reader, OutputStream os)
{
int operand;
userMode = false;
operand = SP;
SP = systemStack_top;
pushValueToStack(pw, is, os, operand);
operand = PC;
PC = 1000;
pushValueToStack(pw, is, os, operand);
}
// function to push a value to the appropriate stack
private static void pushValueToStack(PrintWriter pw, InputStream is, OutputStream os, int
value)
{
SP--;
writeToMemory(pw, is, os, SP, value);
}
// function to pop a value from the appropriate stack
private static int popValueFromStack(PrintWriter pw, InputStream is, Scanner
memory_reader, OutputStream os)
{
int temp = readFromMemory(pw, is, memory_reader, os, SP);
writeToMemory(pw, is, os, SP, 0);
SP++;
return temp;
}
// function to debug program
/*private static void printDebug(String desc, int value)
{
System.out.println("");
System.out.println(desc);
System.out.println("PC = " + PC + " SP = " + SP + " AC = " + AC + " X = " + X + "
Y = " + Y);
System.out.println("instructions = " + num_of_instructions + " timerFlag = " +
31. timerFlag);
System.out.println("user mode = " + userMode + " value read from mem = " + value);
System.out.println("processing Interrupt = " + processingInterrupt);
}*/
}
--------------------------------------------------------------Memory.java--------------------------------------
---------------------------------------------------
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Memory
{
final static int [] memory = new int[2000]; // int array to implement memory
public static void main(String args[])
{
try
{
//Create a File object and a scanner to read it
Scanner CPU_reader = new Scanner(System.in);
File file = null;
if(CPU_reader.hasNextLine()) // read file name from CPU
{
file = new File(CPU_reader.nextLine());
if(!file.exists()) //exit if file not found
{
System.out.println("File not found");
System.exit(0);
}
}
// call function to read file and initialize memory array
readFile(file);
32. String line;
int temp2;
/*
This while loop will keep on reading instructions from the CPU process
and perform the read or write function appropriately
*/
while(true)
{
if(CPU_reader.hasNext())
{
line = CPU_reader.nextLine(); //read the comma delimited line sent by the CPU
if(!line.isEmpty())
{
String [] j = line.split(","); //split the line to get the necessary tokens
// if first token is 1 then CPU is requesting to read
// from an address
if(j[0].equals("1"))
{
temp2 = Integer.parseInt(j[1]);
System.out.println(read(temp2));// send requested data to CPU
}
// else it will be 2, which means CPu is requesting to
// write data at a particular address
else
{
int i1 = Integer.parseInt(j[1]);
int i2 = Integer.parseInt(j[2]);
write(i1,i2); // invoke the write function
}
}
else
break;
}
else
33. break;
}
} catch(NumberFormatException e)
{
e.printStackTrace();
}
}
// function to read the data in the address provided by the CPU
public static int read(int address)
{
return memory[address];
}
// function to write data into an address based on intruction given by CPU
public static void write(int address, int data)
{
memory[address] = data;
}
// function to read instructions from file and initialize memory
private static void readFile(File file) {
try
{
Scanner scanner = new Scanner(file);
String temp;
int temp_int;
int i = 0;
/*
* Read the file to load memory instructions
*/
while(scanner.hasNext())
{
//if integer found then write to memory array
if(scanner.hasNextInt())
34. {
temp_int = scanner.nextInt();
memory[i++] = temp_int;
}
else
{
temp = scanner.next();
// if token starts with ".", then move the counter appropriately
if(temp.charAt(0) == '.')
{
i = Integer.parseInt(temp.substring(1));
}
// else if the token is a comment then skip the line
else if(temp.equals("//"))
{
scanner.nextLine();
}
// skip the line if anything else
else
scanner.nextLine();
}
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
}
}