The document describes a homework assignment to simulate an ARM processor and implement stack operations. The program will read instructions from a file, execute them one by one, and print register and stack contents after each instruction. It will implement instructions like ADD, SUB, LOAD, STORE, BRANCH and handle a stack. The output will show the current instruction, register values and the used portion of the stack.
I am Burrows N. I am an Operating System Assignment Expert at programminghomeworkhelp.com. I hold a PhD. in Programming from, University Of Chicago, USA. I have been helping students with their homework for the past 4 years. I solve assignments related to Operating systems.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with Operating System Assignments.
I am Burrows N. I am an Operating System Assignment Expert at programminghomeworkhelp.com. I hold a PhD. in Programming from, University Of Chicago, USA. I have been helping students with their homework for the past 4 years. I solve assignments related to Operating systems.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with Operating System Assignments.
learn how to program with python
from scratch to be an expert
use the link in the first slide to get the full course
here is the link if you want : https://oke.io/JdxdUl
the link of the documentation : https://oke.io/J6DeY3
link to download python : https://oke.io/BENgRLR2
Introduction to Python Programming | InsideAIMLVijaySharma802
Machine Learning With Python From India’s Most Advanced Learner’s Community. 200+ High-Quality Lectures. 4 Months Live Mentor-ship. 15+ Projects. Industry Insights.
Visit- https://insideaiml.com/course-details/Machine-Learning-with-Python-Statistics
This presentation was presented at IT Audit & IT Security Meetup #4 at Indonesian Cloud, Jakarta.
The exploit development process was quite challenging and we think that it's worth to share.
For educational purposes only.
Python is an interpreted, high-level, and general-purpose programming language.
It is an easy to learn general-purpose programing language.
It is a platform-independent programing language, which means it can be used on any machine and in any operating system.
It has a simple syntax
Python is a case sensitive language.
It is an interrupted language.
It is free to use and even free for commercial products.
Exploit Development: EzServer Buffer Overflow oleh Tom Gregoryzakiakhmad
EzServer adalah video server yang dapat melakukan stream dengan kualitas full HD ke berbagai mesin. Buffer overflow ditemukan pada aplikasi EzServer yang berjalan pada port 8000. Attacker dapat mengirimkan sejumlah kode berbahaya ke port 8000 dan mendapatkan akses setara dengan hak akses aplikasi EzServer. Pada kesempatan ini, penulis akan memaparkan proses pembuatan exploit terhadap aplikasi EzServer menggunakan Python.
Tom Gregory: Security consultant at Spentera, Metasploit exploit developer/contributor.
http://www.python.or.id/2013/04/kopi-darat-komunitas-python-indonesia.html
I am Marianna P. I am a C Exam Expert at programmingexamhelp.com. I hold a Bachelor of Information Technology from, the California Institute of Technology, United States. I have been helping students with their exams for the past 7 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
Program Assignment Process ManagementObjective This program a.docxwkyra78
Program Assignment : Process Management
Objective: This program assignment is given to the Operating Systems course to allow the students to figure out how a single process (parent process) creates a child process and how they work on Unix/Linux(/Mac OS X/Windows) environment. Additionally, student should combine the code for describing inter-process communication into this assignment. Both parent and child processes interact with each other through shared memory-based communication scheme or message passing scheme.
Environment: Unix/Linux environment (VM Linux or Triton Server, or Mac OS X), Windows platform
Language: C or C++, Java
Requirements:
i. You have wide range of choices for this assignment. First, design your program to explain the basic concept of the process management in Unix Kernel. This main idea will be evolved to show your understanding on inter-process communication, file processing, etc.
ii. Refer to the following system calls:
- fork(), getpid(), family of exec(), wait(), sleep() system calls for process management
- shmget(), shmat(), shmdt(), shmctl() for shared memory support or
- msgget(), msgsnd(), msgrcv(), msgctl(), etc. for message passing support
iii. The program should present that two different processes, both parent and child, execute as they are supposed to.
iv. The output should contain the screen capture of the execution procedure of the program.
v. Interaction between parent and child processes can be provided through inter-process communication schemes, such as shared-memory or message passing schemes.
vi. Result should be organized as a document which explains the overview of your program, code, execution results, and the conclusion including justification of your program, lessons you've learned, comments, etc.
Note:
i. In addition, please try to understand how the local and global variables work across the processes
ii. read() or write () functions are used to understand how they work on the different processes.
iii. For extra credit, you can also incorporate advanced features, like socket or thread functions, into your code.
Examples:
1. Process Creation and IPC with Shared Memory Scheme
=============================================================
#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main(){
pid_t pid;
int segment_id; //allocate the memory
char *shared_memory; //pointer to memory
const int size = 4096;
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
shared_memory = (char *) shmat(segment_id, NULL, 0);
pid = fork();
if(pid < 0) { //error
fprintf(stderr, "Fork failed");
return 1;
}
else if(pid == 0){ //child process
char *child_shared_memory;
child_shared_memory = (char *) shmat(segment_id,NULL,0); //attach mem
sprintf(child_shared_memory, "Hello parent process!"); //write to the shared mem
shmdt(child_shared_memory);
}
else ...
Write a C++ program 1. Study the function process_text() in file.pdfjillisacebi75827
Write a C++ program
1. Study the function process_text() in file \"text_processing.cpp\". What do the string member
functions find(), substr(), c_str() do?
//text_processing.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] )
{
string replace_str( \"XXX\" ); //hard-coded string for replacement
int tlen = strlen( target ); //string length of target
int max_len = 200; //maximum length of a line
char s[max_len+1];
clear_screen(); //clear the screen
while ( !ifs.eof() ) {
int i2, i1 = 0, len=0;
ifs.getline( s, max_len ); //get one line from file
string str( s ); //construct a string object
i2 = str.find ( target, i1 ); //find target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //if target found
print_text( str.substr( i1, i2 ).c_str() ); //print up to target
ofs << str.substr( i1, i2 );
}
while ( i2 > -1 ) {
print_text_inverse ( target ); //highlight target
ofs << replace_str;
i1 = i2 + tlen; //new search position
i2 = str.find ( target, i1 ); //find next target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //found target
print_text( str.substr( i1, len ).c_str() ); //print up to target
ofs << str.substr( i1, len );
}
}
len = str.length() - i1;
if ( len > 0 ) { //print the remainder
print_text( str.substr( i1, len ).c_str() );
ofs << str.substr( i1, len );
}
ofs << endl;
getnstr( s, 1 ); //prompt for
} //while ( !ifs.eof() )
restore_screen(); //restore the old screen
return 1;
}
//text_processing.h
#ifndef TEXT_PROCESSING_H
#define TEXT_PROCESSING_H
#include
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] );
#endif
//util.h
#ifndef UTIL_H
#define UTIL_H
#include
#include
#include
#include
#include
using namespace std;
void usage ( char program_name[] );
void clear_screen();
void print_text( const char *s );
void print_text_inverse( const char *s );
void get_input_text( char *s, int max_len );
void restore_screen();
#endif
//util.cpp
#include \"util.h\"
void usage ( char program_name[] )
{
cout << \"Usage: \" << program_name << \" infile outfile search_string\" << endl;
return;
}
/*
The following are some curses functions. You can find
the details by the command \"man ncurses\". But its use
can be transparent to you.
*/
void clear_screen()
{
initscr();
scrollok ( stdscr, true ); //allow window to scroll
}
void print_text ( const char *s )
{
printw(\"%s\", s );
refresh();
}
void print_text_inverse( const char *s )
{
attron( A_REVERSE );
printw(\"%s\", s );
attroff( A_REVERSE );
refresh();
}
void get_input_text( char *s, int max_len )
{
getnstr( s, max_len );
}
void restore_screen()
{
endwin();
}
//str_main.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
/*
Note that grace_open() must be defined in same file
as main(), otherwise the destructor of fstream will
automatically close the opened file as it finds that
its out of scope upon exiting the function.
*/
int grace_open( char *s, fst.
The ProblemUsing C programming language write a program that simul.pdffederaleyecare
The Problem
Using C programming language write a program that simulates the Tiny Machine Architecture.
Your code must implement the basic instruction set that the Tiny Machine Architecture adheres
to (LOAD[1], ADD[2], STORE[3], SUB[4], IN[5], OUT[6], END[7], JMP[8], SKIPZ[9]). Each
piece of the architecture must be accurately represented in your code (Instruction Register,
Program Counter, Memory Address Register, Data Memory, Memory Data Register, and
Accumulator). Data Memory will be represented by a 0-9 array. Your Program Counter will
begin at 10.
For the sake of simplicity Program Memory and Data Memory may be implemented as separate
arrays.
Hint: Implementing a struct for your Instructions and an array of these structs as your Program
Memory greatly simplifies this program.
Example:
typedef struct {
int opCode, deviceOrAddress;
} Instruction;
Instruction programMemory[MAXPROGRAMSIZE];
Input Specifications
Your simulator must run from the command line with a single input file as a parameter to main.
This file will contain a sequence of instructions for your simulator to assemble (store in
“program memory”) and then run via the fetch/execute cycle.
Example:
5 5 //IN 5
6 7 //OUT 7
3 0 //STORE 0
5 5 //IN 5
6 7 //OUT 7
3 1 //STORE 1
1 0 //LOAD 0
4 1 //SUB 1
3 0 //STORE 0
6 7 //OUT 7
1 1 //LOAD 1
6 7 //OUT 7
7 0 //END
Output Specifications
Your simulator should provide output according to the input file. Along with this output your
program should provide status messages identifying details on the workings of your simulator.
Output text does not have to reflect my example word-for-word, but please provide detail on the
program as it runs in a readable format that does not conflict with the actual output of your
simulator. After each instruction print the current state of the Program Counter, Accumulator,
and Data Memory. The INPUT instruction is the only one that should prompt an interaction from
the user.
Example:
Assembling Program…
Program Assembled.
Run.
PC = 10 | A = NULL | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* input value */
X
PC = 11 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* outputting accumulator to screen */
X
PC = 12 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* storing accumulator to memory location 0 */
PC = 13 | A = X | MEM = [X, 0, 0, 0, 0, 0, 0, 0, 0, 0]
… etc
Program complete.
Grading
Your simulator will be graded on the above criteria. Your program should compile and run from
the command line with one input file parameter. Please note that your program will not just be
graded on whether or not it runs successfully; accurate simulation and a thorough demonstration
of your understanding on the workings of this architecture will constitute a large portion of this
grade. As that is the case it is in your best interest to comment your program in a concise and
readable way. However, if your program does not run or compile the maximum points possible
will be 50 (up to 25 may be recovered by debugging and demonstrating a.
I am Joseph G . I am a Programming Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. Programming, Schiller International University, USA. I have been helping students with their homework for the past 8 years. I solve assignments related to Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with Programming Assignments.
learn how to program with python
from scratch to be an expert
use the link in the first slide to get the full course
here is the link if you want : https://oke.io/JdxdUl
the link of the documentation : https://oke.io/J6DeY3
link to download python : https://oke.io/BENgRLR2
Introduction to Python Programming | InsideAIMLVijaySharma802
Machine Learning With Python From India’s Most Advanced Learner’s Community. 200+ High-Quality Lectures. 4 Months Live Mentor-ship. 15+ Projects. Industry Insights.
Visit- https://insideaiml.com/course-details/Machine-Learning-with-Python-Statistics
This presentation was presented at IT Audit & IT Security Meetup #4 at Indonesian Cloud, Jakarta.
The exploit development process was quite challenging and we think that it's worth to share.
For educational purposes only.
Python is an interpreted, high-level, and general-purpose programming language.
It is an easy to learn general-purpose programing language.
It is a platform-independent programing language, which means it can be used on any machine and in any operating system.
It has a simple syntax
Python is a case sensitive language.
It is an interrupted language.
It is free to use and even free for commercial products.
Exploit Development: EzServer Buffer Overflow oleh Tom Gregoryzakiakhmad
EzServer adalah video server yang dapat melakukan stream dengan kualitas full HD ke berbagai mesin. Buffer overflow ditemukan pada aplikasi EzServer yang berjalan pada port 8000. Attacker dapat mengirimkan sejumlah kode berbahaya ke port 8000 dan mendapatkan akses setara dengan hak akses aplikasi EzServer. Pada kesempatan ini, penulis akan memaparkan proses pembuatan exploit terhadap aplikasi EzServer menggunakan Python.
Tom Gregory: Security consultant at Spentera, Metasploit exploit developer/contributor.
http://www.python.or.id/2013/04/kopi-darat-komunitas-python-indonesia.html
I am Marianna P. I am a C Exam Expert at programmingexamhelp.com. I hold a Bachelor of Information Technology from, the California Institute of Technology, United States. I have been helping students with their exams for the past 7 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
Program Assignment Process ManagementObjective This program a.docxwkyra78
Program Assignment : Process Management
Objective: This program assignment is given to the Operating Systems course to allow the students to figure out how a single process (parent process) creates a child process and how they work on Unix/Linux(/Mac OS X/Windows) environment. Additionally, student should combine the code for describing inter-process communication into this assignment. Both parent and child processes interact with each other through shared memory-based communication scheme or message passing scheme.
Environment: Unix/Linux environment (VM Linux or Triton Server, or Mac OS X), Windows platform
Language: C or C++, Java
Requirements:
i. You have wide range of choices for this assignment. First, design your program to explain the basic concept of the process management in Unix Kernel. This main idea will be evolved to show your understanding on inter-process communication, file processing, etc.
ii. Refer to the following system calls:
- fork(), getpid(), family of exec(), wait(), sleep() system calls for process management
- shmget(), shmat(), shmdt(), shmctl() for shared memory support or
- msgget(), msgsnd(), msgrcv(), msgctl(), etc. for message passing support
iii. The program should present that two different processes, both parent and child, execute as they are supposed to.
iv. The output should contain the screen capture of the execution procedure of the program.
v. Interaction between parent and child processes can be provided through inter-process communication schemes, such as shared-memory or message passing schemes.
vi. Result should be organized as a document which explains the overview of your program, code, execution results, and the conclusion including justification of your program, lessons you've learned, comments, etc.
Note:
i. In addition, please try to understand how the local and global variables work across the processes
ii. read() or write () functions are used to understand how they work on the different processes.
iii. For extra credit, you can also incorporate advanced features, like socket or thread functions, into your code.
Examples:
1. Process Creation and IPC with Shared Memory Scheme
=============================================================
#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main(){
pid_t pid;
int segment_id; //allocate the memory
char *shared_memory; //pointer to memory
const int size = 4096;
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
shared_memory = (char *) shmat(segment_id, NULL, 0);
pid = fork();
if(pid < 0) { //error
fprintf(stderr, "Fork failed");
return 1;
}
else if(pid == 0){ //child process
char *child_shared_memory;
child_shared_memory = (char *) shmat(segment_id,NULL,0); //attach mem
sprintf(child_shared_memory, "Hello parent process!"); //write to the shared mem
shmdt(child_shared_memory);
}
else ...
Write a C++ program 1. Study the function process_text() in file.pdfjillisacebi75827
Write a C++ program
1. Study the function process_text() in file \"text_processing.cpp\". What do the string member
functions find(), substr(), c_str() do?
//text_processing.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] )
{
string replace_str( \"XXX\" ); //hard-coded string for replacement
int tlen = strlen( target ); //string length of target
int max_len = 200; //maximum length of a line
char s[max_len+1];
clear_screen(); //clear the screen
while ( !ifs.eof() ) {
int i2, i1 = 0, len=0;
ifs.getline( s, max_len ); //get one line from file
string str( s ); //construct a string object
i2 = str.find ( target, i1 ); //find target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //if target found
print_text( str.substr( i1, i2 ).c_str() ); //print up to target
ofs << str.substr( i1, i2 );
}
while ( i2 > -1 ) {
print_text_inverse ( target ); //highlight target
ofs << replace_str;
i1 = i2 + tlen; //new search position
i2 = str.find ( target, i1 ); //find next target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //found target
print_text( str.substr( i1, len ).c_str() ); //print up to target
ofs << str.substr( i1, len );
}
}
len = str.length() - i1;
if ( len > 0 ) { //print the remainder
print_text( str.substr( i1, len ).c_str() );
ofs << str.substr( i1, len );
}
ofs << endl;
getnstr( s, 1 ); //prompt for
} //while ( !ifs.eof() )
restore_screen(); //restore the old screen
return 1;
}
//text_processing.h
#ifndef TEXT_PROCESSING_H
#define TEXT_PROCESSING_H
#include
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] );
#endif
//util.h
#ifndef UTIL_H
#define UTIL_H
#include
#include
#include
#include
#include
using namespace std;
void usage ( char program_name[] );
void clear_screen();
void print_text( const char *s );
void print_text_inverse( const char *s );
void get_input_text( char *s, int max_len );
void restore_screen();
#endif
//util.cpp
#include \"util.h\"
void usage ( char program_name[] )
{
cout << \"Usage: \" << program_name << \" infile outfile search_string\" << endl;
return;
}
/*
The following are some curses functions. You can find
the details by the command \"man ncurses\". But its use
can be transparent to you.
*/
void clear_screen()
{
initscr();
scrollok ( stdscr, true ); //allow window to scroll
}
void print_text ( const char *s )
{
printw(\"%s\", s );
refresh();
}
void print_text_inverse( const char *s )
{
attron( A_REVERSE );
printw(\"%s\", s );
attroff( A_REVERSE );
refresh();
}
void get_input_text( char *s, int max_len )
{
getnstr( s, max_len );
}
void restore_screen()
{
endwin();
}
//str_main.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
/*
Note that grace_open() must be defined in same file
as main(), otherwise the destructor of fstream will
automatically close the opened file as it finds that
its out of scope upon exiting the function.
*/
int grace_open( char *s, fst.
The ProblemUsing C programming language write a program that simul.pdffederaleyecare
The Problem
Using C programming language write a program that simulates the Tiny Machine Architecture.
Your code must implement the basic instruction set that the Tiny Machine Architecture adheres
to (LOAD[1], ADD[2], STORE[3], SUB[4], IN[5], OUT[6], END[7], JMP[8], SKIPZ[9]). Each
piece of the architecture must be accurately represented in your code (Instruction Register,
Program Counter, Memory Address Register, Data Memory, Memory Data Register, and
Accumulator). Data Memory will be represented by a 0-9 array. Your Program Counter will
begin at 10.
For the sake of simplicity Program Memory and Data Memory may be implemented as separate
arrays.
Hint: Implementing a struct for your Instructions and an array of these structs as your Program
Memory greatly simplifies this program.
Example:
typedef struct {
int opCode, deviceOrAddress;
} Instruction;
Instruction programMemory[MAXPROGRAMSIZE];
Input Specifications
Your simulator must run from the command line with a single input file as a parameter to main.
This file will contain a sequence of instructions for your simulator to assemble (store in
“program memory”) and then run via the fetch/execute cycle.
Example:
5 5 //IN 5
6 7 //OUT 7
3 0 //STORE 0
5 5 //IN 5
6 7 //OUT 7
3 1 //STORE 1
1 0 //LOAD 0
4 1 //SUB 1
3 0 //STORE 0
6 7 //OUT 7
1 1 //LOAD 1
6 7 //OUT 7
7 0 //END
Output Specifications
Your simulator should provide output according to the input file. Along with this output your
program should provide status messages identifying details on the workings of your simulator.
Output text does not have to reflect my example word-for-word, but please provide detail on the
program as it runs in a readable format that does not conflict with the actual output of your
simulator. After each instruction print the current state of the Program Counter, Accumulator,
and Data Memory. The INPUT instruction is the only one that should prompt an interaction from
the user.
Example:
Assembling Program…
Program Assembled.
Run.
PC = 10 | A = NULL | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* input value */
X
PC = 11 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* outputting accumulator to screen */
X
PC = 12 | A = X | MEM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/* storing accumulator to memory location 0 */
PC = 13 | A = X | MEM = [X, 0, 0, 0, 0, 0, 0, 0, 0, 0]
… etc
Program complete.
Grading
Your simulator will be graded on the above criteria. Your program should compile and run from
the command line with one input file parameter. Please note that your program will not just be
graded on whether or not it runs successfully; accurate simulation and a thorough demonstration
of your understanding on the workings of this architecture will constitute a large portion of this
grade. As that is the case it is in your best interest to comment your program in a concise and
readable way. However, if your program does not run or compile the maximum points possible
will be 50 (up to 25 may be recovered by debugging and demonstrating a.
I am Joseph G . I am a Programming Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. Programming, Schiller International University, USA. I have been helping students with their homework for the past 8 years. I solve assignments related to Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with Programming Assignments.
Hello. I was wondering if I could get some help on this C programmin.pdffashionfootwear1
find the area of the sector of a circle of radius 16 units subtended by an angle of 300 degrees
find the area of the sector of a circle of radius 16 units subtended by an angle of 300 degrees
find the area of the sector of a circle of radius 16 units subtended by an angle of 300 degrees
Solution
given radius r=16 ,=300o
area of sector=(/180o)(/2)r2
area of sector=(300o/180o)*(/2)*162
area of sector=(5/3)*(/2)*256
area of sector=640/3 squareunits
area of sector=670.2 squareunits.
Lab01Files/build.bat
@echo off
cls
set DRIVE_LETTER=%1:
set PATH=%DRIVE_LETTER%\MinGW\bin;%DRIVE_LETTER%\MinGW\msys\1.0\bin;c:\Windows;c:\Windows\system32
g++ -c Keyboard.cpp
g++ -c Random.cpp
g++ -c String.cpp
g++ -c ReadFile.cpp
g++ -c WriteFile.cpp
g++ -c PlayerGuessDriver.cpp
g++ -o PlayerGuess.exe PlayerGuessDriver.o ReadFile.o WriteFile.o String.o Keyboard.o Random.o
Lab01Files/Keyboard.cpp
#include "Keyboard.h"
#include <iostream>
int readInt(string prompt)
{
cout << prompt;
int val = 0;
cin >> val;
return val;
}
int getValidatedInt(string prompt, int min, int max)
{
int validated = readInt(prompt);
cout << validated << endl;
while(validated < min || validated > max)
{
validated = readInt(prompt);
cout << validated << endl;
}
return validated;
}
double readDouble(string prompt)
{
cout << prompt;
double val = 0;
cin >> val;
return val;
}
double getValidatedDouble(string prompt, double min, double max)
{
double validated = readDouble(prompt);
cout << validated << endl;
while(validated < min || validated > max)
{
validated = readDouble(prompt);
cout << validated << endl;
}
return validated;
}
String* readString(string prompt)
{
cout << prompt;
string text;
getline(cin, text);
String* str = createString(text.c_str());
return str;
}
Lab01Files/Keyboard.h
#if !defined KEYBOARD
#define KEYBOARD
#include "Text.h"
#include <string>
using namespace std;
//pre: the string (character literal) that will prompt the user for input
//post: the input read from the keyboard interpreted as an int is returned
int readInt(string prompt);
int getValidatedInt(string prompt, int min, int max);
//pre: the string that will prompt the user for input
//post: the input read from the keyboard interpreted as a double is returned
double readDouble(string prompt);
double getValidatedDouble(string prompt, double min, double max);
//pre: the string that will prompt the user for input
// the string to store the user input and the length of the input storage string
//post: the text read from the keyboard is copied into the storage string
String* readString(string prompt);
#endif
Lab01Files/Laboratory 01_ Guessing Game.pdf
8/28/2014 Laboratory 01: Guessing Game
http://mboshart.dyndns.org/boshart/2111Labs/Lab01.html 1/3
Laboratory 01: Guessing Game
Download the following files and place them in your working directory:
Starting code for this lab:
Lab01Files.zip //provided, completed files, refer to header files for method
signatures
PlayerGuessDriver.cpp //most of the work is in this file
range.txt //contains the two integers that define the range for the secret
number
build.bat //convenience file for compiling and linking
Guessing Game
In this lab, you will write a simple guessing game. The computer will generate a
random integer within a valid spe ...
httplinux.die.netman3execfork() creates a new process by.docxadampcarr67227
http://linux.die.net/man/3/exec
fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent#include <unistd.h>pid_t fork(void);
The exec() family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for execve(2). (See the manual page for execve(2) for further details about the replacement of the current process image.)
The exec() family of functions include execl, execlp, execle, execv, execvp, and execvpe to execute a file.
The ANSI prototype for execl() is:
int execl(const char *path, const char *arg0,..., const char *argn, 0)
http://www.cems.uwe.ac.uk/~irjohnso/coursenotes/lrc/system/pc/pc4.htm #inciude <stdio.h> #inciude <unistd.h> main() { execl("/bin/ls", "ls", "-l", 0); printf("Can only get here on error\n"); }
The first parameter to execl() in this example is the full pathname to the ls command. This is the file whose contents will be run, provided the process has execute permission on the file. The rest of the execl() parameters provide the strings to which the argv array elements in the new program will point. In this example, it means that the ls program will see the string ls pointed to by its argv[0], and the string -l pointed to by itsargv[1]. In addition to making all these parameters available to the new program, the exec() calls also pass a value for the variable: extern char **environ;
This variable has the same format as the argv variable except that the items passed via environ are the values in the environment of the process (like any exported shell variables), rather than the command line parameters. In the case of execl(), the value of the environ variable in the new program will be a copy of the value of this variable in the calling process.
The execl() version of exec() is fine in the circumstances where you can ex-plicitly list all of the parameters, as in the previous example. Now suppose you want to write a program that doesn't just run ls, but will run any program you wish, and pass it any number of appropriate command line parameters. Obviously, execl() won't do the job.
The example program below, which implements this requirement, shows, however, that the system call execv() will perform as required: #inciude <stdio.h> main(int argc, char **argv) { if (argc==1) { printf("Usage: run <command> [<paraneters>]\n"); exit(1) } execv(argv[l], &argv[1)); printf("Sorry... couldn't run that!\n"); }
The prototype for execv() shows that it only takes two parameters, the first is the full pathname to the command to execute and the second is the argv value you want to pass into the new program. In the previous example this value was derived from the argv value passed into the run command, so that the run command can take the command line parameter values you pass it and just pass them on. int execl(.
Article link httpiveybusinessjournal.compublicationmanaging-.docxfredharris32
Article link: http://iveybusinessjournal.com/publication/managing-global-risk-to-seize-competitive-advantage/
Requirements: Write one summary and study note both no longer than one pages should include all point of article. Then do a PPT and write a presenting paper only for 5 minutes.
Groups of students will create and offer two MS PowerPoint presentation summarizing the main points of one of the readings for this course along with a one page handout for the students in the class. The aim of the presentations and the handouts is to provide the audience with the main ideas of the article and study notes. Groups will bring to class enough copies of the handout for each student in the class. The handout should list the name of the author, the title of the article, the title of the journal, and the publication date and page numbers along with a summary of its main points. Please do not exceed one page for this material.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* Read a .dat file and reverse it.
*/
public class Reverse {
public static void main(String[]args) {
if (args.length != 3) {
System.err.println(" Incorrect number of arguments");
System.err.println(" Usage: ");
System.err.
println("\tjava Reverse <stack type> <input file> <output file>");
System.exit(1);
}
boolean useList = true;
if (args[0].compareTo("list")==0)
useList = true;
else if (args[0].compareTo("array")==0)
useList = false;
else {
System.err.println("\tSaw "+args[0]+" instead of list or array as first argument");
System.exit(1);
}
try {
//
// Set up the input file to read, and the output file to write to
//
BufferedReader fileIn =
new BufferedReader(new FileReader(args[1]));
PrintWriter fileOut =
new PrintWriter(new
BufferedWriter(new FileWriter(args[2])));
//
// Read the first line of the .dat file to get sample rate.
// We want to store the sample rate value in a variable,
// but we can ignore the "; Sample Rate" part of the line.
// Step through the first line one token (word) at a time
// using the StringTokenizer. The fourth token is the one
// we want (the sample rate).
//
StringTokenizer str;
String oneLine;
int sampleRate;
String strJunk;
oneLine = fileIn.readLine();
str = new StringTokenizer(oneLine);
strJunk = str.nextToken(); // Read in semicolon
strJunk = str.nextToken(); // Read in "Sample"
strJunk = str.nextToken(); // Read in "Rate"
// ...
Explore the world of C programming assignments with expert guidance and practical tips. Dive into a range of C assignment solutions designed for varying complexity levels. Get insights from industry experts passionate about sharing their C programming knowledge. Discover time-saving techniques to boost productivity and meet assignment deadlines. Access 24/7 customer support and budget-friendly pricing options.
Ready to excel in C programming assignments? Head over to https://www.programminghomeworkhelp.com/c-assignment/ to embark on a journey toward academic excellence. Don't let C assignments hold you back. Join us on the path to success today!
Welcome to Programming Homework Help
Python Question Assistance
Making Python Learning Easier
Introducing Python Question Assistance
Are you struggling with Python programming questions? Look no further! ProgrammingHomeworkHelp.com is here to provide comprehensive and reliable Python question assistance. Whether you're a beginner or an experienced programmer, we have the expertise to help you overcome any coding challenge.
Why Choose ProgrammingHomeworkHelp.com?
Expert Python Programmers: Our team consists of experienced Python programmers who are well-versed in the language and its various concepts. They possess the knowledge and skills to tackle any Python question effectively.
Customized Solutions: We understand that each Python question is unique, and we tailor our solutions accordingly. Our experts analyze the problem, devise a strategic approach, and provide you with personalized, step-by-step solutions.
Timely Delivery: We value your time and ensure prompt delivery of solutions. No matter how challenging the question is, our experts work diligently to meet your deadlines.
24/7 Availability: We are available round the clock to assist you with your Python questions. Whether it's day or night, our dedicated team is ready to provide guidance and support whenever you need it.
Our Python Question Assistance Services Include:
Code Debugging: If you're encountering errors or bugs in your Python code, our experts can help you identify and fix them. We'll guide you through the debugging process, explaining the errors and providing solutions.
Code Optimization: Want to improve the efficiency and performance of your Python code? Our programmers can review your code and suggest optimizations to enhance its speed and effectiveness.
Algorithm Design: If you're stuck on designing the right algorithm for a Python question, our experts can guide you through the process. We'll help you understand the problem requirements and devise an efficient algorithmic solution.
How to Get Started:
Visit our website, https://www.programminghomeworkhelp.com/
Submit your Python question along with any additional instructions or requirements.
Receive a quote for the assistance required.
Make a secure payment.
Sit back and relax while our experts work on your Python question.
Don't let Python questions become obstacles in your learning journey. Programming Homework Help is your go-to destination for reliable and comprehensive Python question assistance. Our team of experts is committed to helping you succeed in your programming endeavors. Visit our website today and experience hassle-free Python learning like never before!
I am Hawkins F. Currently associated with programminghomeworkhelp.com as an Algorithms Assignment expert. After completing my Ph.D. in Programming from, Princeton University, USA, I was in search of an opportunity that expands my area of knowledge hence I decided to help students with their assignments. I have written various programming homework till date to help students overcome numerous difficulties they face.
I am Britney P. I love exploring new topics. Academic writing seemed an interesting option for me. After working for many years with progamminghomeworkhelp.com, I have assisted many students with their Design and Analysis of Algorithms Assignments. I can proudly say, each student I have served is happy with the quality of the solution that I have provided. I have acquired my bachelor's from Sunway University, Malaysia.
My name is Cecily Kent. I have been associated with programminghomeworkhelp.com for the past 8 years and have been assisting the programming students with their Algorithm Homework.
I have a PhD. in Programming from, the University of Melbourne, Australia.
I am Irene. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, the California Institute of Technology. I have been helping students with their homework for the past 6 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Homework.
I am Andrew O. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, Southampton, UK. I have been helping students with their homework for the past 11 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Homework.
I am Joe L. I am an Algorithms Design Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, the University of Chicago, USA. I have been helping students with their assignments for the past 10 years. I solve assignments related to Algorithms Design.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Design Assignment.
I am Anne L. I am an Algorithms Design Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, Auburn University, USA. I have been helping students with their homework for the past 8 years. I solve homework related to Algorithms Design.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm Design Homework.
I am Andrew O. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their assignments for the past 12 years. I solve assignment related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with the Algorithm assignment.
I am Frank G. I am an Algorithm Homework Expert at programminghomeworkhelp.com. I hold in Programming from, the University of Waterloo, Canada. I have been helping students with their homework for the past 12 years. I solve homework related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Algorithm homework.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
I am Vincent S. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, University of Minnesota, USA. I have been helping students with their homework for the past 9 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.
I am Elijah L. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Bachelor’s Degree in Programming, Leeds University, UK. I have been helping students with their homework for the past 6 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.
I am Travis W. I am a Computer Science Assignment Expert at programminghomeworkhelp.com. I hold a Master's in Computer Science, Leeds University. I have been helping students with their homework for the past 9 years. I solve assignments related to Computer Science.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Computer Science assignments.
I am Charles B. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming, Texas University, USA. I have been helping students with their homework for the past 6 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.
I am Christopher Hemmingway. I am a Computer Science Assignment Expert at programminghomeworkhelp.com. I hold a Master's in Computer Science, Princeton University, Princeton. I have been helping students with their homework for the past 10 years. I solve assignments related to Computer Science.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Computer Science assignments.
I am Blake H. I am a Software Construction Assignment Expert at programminghomeworkhelp.com. I hold a PhD. in Programming, Curtin University, Australia. I have been helping students with their homework for the past 10 years. I solve assignments related to Software Construction.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Software Construction Assignments.
I am Bernard. I am a C Assignment Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, University of Leeds, UK. I have been helping students with their homework for the past 9 years. I solve assignments related to C Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C Programming Assignments.
I am Gill H. I am a Programming Homework Expert at programminghomeworkhelp.com. I hold a Ph.D. in Programming from, the University of Texas, USA. I have been helping students with their homework for the past 10 years. I solve assignments related to Programming.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Programming Homework.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
1. For any help regarding C Homework Help
visit : - https://www.programminghomeworkhelp.com/ ,
Email :- support@programminghomeworkhelp.com or
call us at :- +1 678 648 4277
2. Simulation of ARM Processor and Stack Operation
Your task for this lab is to write a program that extends the simulation of the ARM
processor and includes stack operations.
The program will have an array that represents the general ARM registers, and a second
multi-dimensional array that represents memory. The program must also have allocated
stack space within the memory array.
The program will read content into the memory array from a file, execute the
instructions it finds in the array one instruction at a time, and print the contents of the
registers (including a program counter) and stack after each instruction. Note, when
printing the stack do not print anything below the stack pointer, or above your stack
base.
The program will implement the following instructions: ADD, ADDI, SUBI, LDUR,
STUR, B, BL, BR. And at least on Conditional Branch instruction.
Instructions in memory will use the assembly mnemonics rather than binary op codes.
Instruction arguments will be register aliases (ex. X0, X1, X2, …) memory locations in
the memory array (100, 104, …), or immediate values (#-3, #5, #0, …).
The program should use the specific address - 200, as the default address for the
start instructions in memory.
programminghomeworkhelp.com
3. Load and store instructions will only use indirect addressing (ie. [Xn, #nn] ).
Branch instructions will use immediate or register addressing.
The program can limit the number of registers available for use in the program. At least 8
must be available, including X0, X1, X9, X10, SP (X28), LR (X30). Additional registers
may be implemented.
Data will be signed integers.
The Stack:
The stack must be at least 100 words deep. Make sure your stack will not
grow over your program/data area.
The program must have a check and a “Ran out of Stack Space/Stack
Overflow” error message.
Choose a high memory area for the stack.
The stack should grow down.
Stack memory locations should be on double word boundaries
(increment/decrement by 8).
Remember to initiate the stack pointer (SP) to the top of the stack.
Use BR XZR to halt the program.
Test Files:
programminghomeworkhelp.com
4. Students will create an input file to test their emulator. The program must be able
to read the name of the file as an argument
The instructions in the file to be executed must include:
At least one example of each instruction implemented.
At least 12 instructions.
Instructions to complete at least one loop.
At least one push and pop on the stack.
At least one function call.
Output
The output of the program will be a listing showing:
The current instruction
The values of any registers used in that instruction. Including the
Program Counter.
The portion of the stack which is in use – (note: this may be limited to
the current stack frame).
Additional information, such as the value of all registers, or other useful
items may be shown as well.
SAMPLE OUTPUT
Instruction executed: LDUR X0, XZR, #100
programminghomeworkhelp.com
5. Registers: X0 = 512, SP=1000, PC=204*
Stack: 1000: 98 ***
Hit enter for next instruction: >
Instruction executed: SUBI SP, SP, #8
Registers: SP=992, PC=208
Stack: 1000: 98
992: **
Hit enter for next instruction:>
Instruction executed: STUR X0, [SP, #0]
Registers: X0 = 512, SP=992, PC=212
programminghomeworkhelp.com
6. Stack: 1000: 4A
992: 512
Hit enter for next instruction: >
Solution:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MEMORY_SIZE 1024 /* by default memory has size 1024
positions */
#define STACK_SIZE 256 /* size of stack */
#define FIELD_LEN 10 /* maximum length for an instruction field
string */
#define MAX_LINE_LEN 100 /* maximum length in a line */
programminghomeworkhelp.com
7. /* definition of the register numbers */
enum {
X0 = 0, X1, X2, X3, X4, X5, X6, X7, X8, X9,
X10, X11, X12, X13, X14, X15, X16, X17, X18, X19,
X20, X21, X22, X23, X24, X25, X26, X27, X28, X29,
X30, X31, SP = 28, FP, LR, XZR
};
/**
* Returns the last character in the string
*/
char lastchar(char *str)
{
return (str[strlen(str) - 1]);
}
/**
* Returns 1 if the given character represents a decimal digit, 0
otherwise
*/
int is_digit(char c)
{
programminghomeworkhelp.com
8. return (c >= '0' && c <='9');
}
/**
* Returns 1 if the given character represents a whitespace char, 0
otherwise
*/
int is_space(char c)
{
return (c == ' ' || c == 'r' || c == 'n' || c == 't'
|| c == 'v' || c == 'f');
}
/**
* Copies the string str2 to str1 removing the first char if fst=1 and
* removing the last char is lst = 1
*/
void copytrim(char *str1, char *str2, int fst, int lst)
{
programminghomeworkhelp.com
9. if (fst == 1)
str2++;
strcpy(str1, str2);
if (lst == 1)
str1[strlen(str1) - 1] = 0;
}
/**
* Check if a string represents a valid int
*/
int valid_int(char *str)
{
int i = 0;
if (str[0] == '-' || str[0] == '+')
i++;
for (; i < strlen(str); i++)
if (!is_digit(str[i])) /* if not a digit,
is not a number */
return 0;
return (1);
}
programminghomeworkhelp.com
10. /**
* Split the instruction line by spaces, save the instruction in memory
*/
int save_instruction(char *inst,char mem[MEMORY_SIZE][FIELD_LEN], int nline)
{
char *ptr;
int nparts;
int address;
ptr = strtok(inst, " "); /* split string using spaces */
if (ptr == NULL) /* if can't split */
{
fprintf(stderr, "Error: line %d: invalid instruction formatn",
nline + 1);
return (-1); /* return error */
}
/* try to get the address */
if (sscanf(ptr, "%d", &address) != 1 || address <0 ||
address >= MEMORY_SIZE || (address & 3)) /* if error or
invalid address */
{
programminghomeworkhelp.com
11. fprintf(stderr, "Error: line %d: invalid addressn", nline + 1);
return (-1); /* return error */
}
ptr = strtok(NULL, " "); /* split next part using spaces */
nparts = 0; /* no parts initially */
while (ptr != NULL)
{
if (nparts >= 4) /* if too many parts */
{
fprintf(stderr, "Error: line %d: invalid instruction
formatn", nline + 1);
return (-1);
}
if (strlen(ptr) > FIELD_LEN) /* if field is too long */
{
fprintf(stderr, "Error: line %d: instruction field %d is too longn", nline +
1, nparts + 1);
return (-1);
}
programminghomeworkhelp.com
12. strcpy(mem[address + nparts], ptr); /* save field in memory */
nparts++; /* we have one more part */
ptr = strtok(NULL, " "); /* split next part of string using
spaces */
}
if (nparts == 0)
{
fprintf(stderr, "Error: line %d: invalid instruction formatn",
nline + 1);
return (-1);
}
if (address < 200) /*if data address*/
{
/* check for valid number */
if (!valid_int(mem[address]))
{
fprintf(stderr, "Error: line %d: invalid datan", nline + 1);
return (-1);
}
}
programminghomeworkhelp.com
13. return (0);
}
/**
* Load program code from a file and saves it in memory in the addresses
given
* as the first field in the line
*/
void load_program(char *filename, char mem[MEMORY_SIZE][FIELD_LEN])
{
FILE *f;
char buffer[MAX_LINE_LEN];
int nline;
f = fopen(filename, "rt"); /* open file for reading */
if (f == NULL) /* error opening */
{
fprintf(stderr, "Error: unable to open file "%s"n", filename);
exit(EXIT_FAILURE);
programminghomeworkhelp.com
14. }
printf("Loading program from "%s"n", filename);
/* read all lines in the file */
nline = 0; /* start at line 0 */
while (fgets(buffer, MAX_LINE_LEN, f) != NULL)
{
/* remove ending spaces and newline */
while (is_space(lastchar(buffer)))
buffer[strlen(buffer) - 1] = 0;
/* skip empty lines */
if (buffer[0] != 0)
{
/* save instruction in memory */
if (save_instruction(buffer, mem, nline) == -1) /* if error
*/
{
fclose(f); /* close file */
exit(EXIT_FAILURE);
}
}
programminghomeworkhelp.com
15. nline++; /* advance line number */
}
fclose(f); /* close the file */
}
/**
* Shows the contents of all changed registers
*/
void print_registers(int *regs, int *affected, int PC)
{
int i;
int first;
printf("Registers:t");
first = 1;
for (i = 0; i < 31; i++)
{
if (affected[i])
{
if (!first)
programminghomeworkhelp.com
16. printf(", ");
switch (i)
{
case SP:
printf("SP");
break;
case FP:
printf("FP");
break;
case LR:
printf("LR");
break;
default:
printf("X%d", i);
}
printf("=%d",regs[i]);
first = 0;
}
}
if (!first)
printf(", ");
printf("PC=%dn", PC);
programminghomeworkhelp.com
17. }
/**
* Prints the stack contents
*/
void print_stack(int sp, char memory[MEMORY_SIZE][FIELD_LEN],
int memused[MEMORY_SIZE])
{
int addr;
int first;
printf("Stack:t");
first = 1;
for (addr = MEMORY_SIZE; addr >= sp; addr-= 8)
{
if (!first)
printf(" t");
printf("%6d: ", addr);
if (memused[addr])
printf("%d", atoi(memory[addr]));
printf("n");
first = 0;
}
programminghomeworkhelp.com
18. if (first)
printf("n");
}
/**
* Prints the memory
*/
void print_memory(char memory[MEMORY_SIZE][FIELD_LEN], int
memused[MEMORY_SIZE])
{
int addr;
int first;
printf("Memory:t");
first = 1;
for (addr = 0; addr < MEMORY_SIZE - STACK_SIZE; addr += 4)
{
if (memused[addr])
{
programminghomeworkhelp.com
19. if (!first)
printf(" t");
printf("%6d: ", addr);
printf("%d", atoi(memory[addr]));
printf("n");
first = 0;
}
}
if (first)
printf("n");
}
/**
* Gets the register number from the string if its a valid register Xn
* If not valid returns -1
*/
int get_register(char *reg)
{
int nreg;
programminghomeworkhelp.com
20. if (!strcmp(reg, "SP"))
nreg = SP;
else if (!strcmp(reg, "FP"))
nreg = FP;
else if (!strcmp(reg, "LR"))
nreg = LR;
else if (!strcmp(reg, "XZR"))
nreg = XZR;
else if (sscanf(reg, "X%d", &nreg) != 1)
return (-1);
if (nreg < 0 || nreg > 31)
return (-1);
return (nreg);
}
/**
* Simulates the program in memory starting at address 200
*
*/
void simulate_program(char memory[MEMORY_SIZE][FIELD_LEN])
{
programminghomeworkhelp.com
21. int PC;
int regs[32]; /* registers */
int affected[32]; /* registers affected */
int flagZ;
int memused[MEMORY_SIZE];
char *opcode, *op1, *op2, *op3;
char t1[FIELD_LEN];
char t2[FIELD_LEN];
char t3[FIELD_LEN];
int i;
int r1, r2, r3, r;
int halt;
PC = 200; /* start simulating at address 200 */
/* initialize registers */
for (i = 0; i < 32; i++)
{
regs[i] = 0;
affected[i] = 0;
}
programminghomeworkhelp.com
22. regs[SP] = MEMORY_SIZE; /* stack top at end of memory */
/* initialize memory used */
for (i = 0; i < MEMORY_SIZE; i++)
{
memused[i] = 0;
}
flagZ = 0; /* initialize flags */
printf("Starting simulation...n");
halt = 0;
while (!halt) /* repeat until halt is found */
{
opcode = memory[PC]; /* fetch instruction */
op1 = memory[PC + 1]; /* fetch operands */
op2 = memory[PC + 2];
op3 = memory[PC + 3];
PC+=4; /* advance to next instruction */
programminghomeworkhelp.com
23. /* clear affected registers */
for (i = 0; i < 31; i++)
affected[i] = 0;
if (!strcmp(opcode, "ADD") || !strcmp(opcode, "ADDS"))
{
if (lastchar(op1) != ',' || lastchar(op2) != ',')
{
printf("n<< Invalid instruction operand at address %d >>n", PC -
4);
halt = -1; /* halt simulation */
}
else
{
copytrim(t1, op1, 0, 1);
copytrim(t2, op2, 0, 1);
r1 = get_register(t1);
r2 = get_register(t2);
r3 = get_register(op3);
if (r1 == -1 || r2 == -1 || r3 == -1)
{
programminghomeworkhelp.com
24. printf("n<< Invalid instruction operand at address
%d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r = regs[r2] + regs[r3];
/* if S instruction, update flag */
if (lastchar(opcode) == 'S')
flagZ = (r == 0);
if (r1 != XZR)
{
regs[r1] = r;
}
affected[r1] = 1;
affected[r2] = 1;
affected[r3] = 1;
}
}
}
else if (!strcmp(opcode, "ADDI") ||
!strcmp(opcode, "ADDIS"))
{
programminghomeworkhelp.com
25. if (lastchar(op1) != ',' || lastchar(op2) != ',' || op3[0] != '#')
{
printf("n<< Invalid instruction operand at address
%d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
copytrim(t1, op1, 0, 1);
copytrim(t2, op2, 0, 1);
copytrim(t3, op3, 1, 0);
r1 = get_register(t1);
r2 = get_register(t2);
if (r1 == -1 || r2 == -1 || !valid_int(t3))
{
printf("n<< Invalid instruction operand at address
%d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
programminghomeworkhelp.com
26. r3 = atoi(t3);
r = regs[r2] + r3;
/* if S instruction, update flag */
if (lastchar(opcode) == 'S')
flagZ = (r == 0);
if (r1 != XZR)
regs[r1] = r;
affected[r1] = 1;
affected[r2] = 1;
}
}
}
else if (!strcmp(opcode, "SUBI") || !strcmp(opcode, "SUBIS"))
{
if (lastchar(op1) != ',' || lastchar(op2) != ',' || op3[0] !=
'#')
{
printf("n<< Invalid instruction operand at address %d
>>n", PC - 4);
halt = -1; /* halt simulation */
programminghomeworkhelp.com
27. }
else
{
copytrim(t1, op1, 0, 1);
copytrim(t2, op2, 0, 1);
copytrim(t3, op3, 1, 0);
r1 = get_register(t1);
r2 = get_register(t2);
if (r1 == -1 || r2 == -1 || !valid_int(t3))
{
printf("n<< Invalid instruction operand at address
%d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r3 = atoi(t3);
r = regs[r2] - r3;
/* if S instruction, update flag */
if (lastchar(opcode) == 'S')
flagZ = (r == 0);
programminghomeworkhelp.com
29. if (r1 == -1 || r2 == -1 || !valid_int(t3))
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r3 = atoi(t3);
if (r2 == SP && (regs[r2] + r3 < MEMORY_SIZE - STACK_SIZE))
{
printf("n<< Stack overflow found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else if (r2 == SP && ((regs[r2] + r3) & 7) != 0)
{
printf("n<< Misaligned stack access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else if (regs[r2] + r3 < 0 || regs[r2] + r3 >= MEMORY_SIZE
programminghomeworkhelp.com
30. || ((regs[r2] + r3) & 3) != 0 /* if not aligned */
|| !valid_int(memory[regs[r2] + r3]))
{
printf("n<< Invalid memory access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
memused[regs[r2] + r3] = 1;
if (r1 != XZR)
regs[r1] = atoi(memory[regs[r2] + r3]);
affected[r1] = 1;
affected[r2] = 1;
}
}
}
}
else if (!strcmp(opcode, "STUR"))
{
if (lastchar(op1) != ',' || lastchar(op2) != ',' || op2[0] != '['
|| op3[0] != '#' || lastchar(op3) != ']')
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
programminghomeworkhelp.com
31. halt = -1; /* halt simulation */
}
else
{
copytrim(t1, op1, 0, 1);
copytrim(t2, op2, 1, 1);
copytrim(t3, op3, 1, 1);
r1 = get_register(t1);
r2 = get_register(t2);
if (r1 == -1 || r2 == -1 || !valid_int(t3))
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r3 = atoi(t3);
if (r2 == SP && (regs[r2] + r3 < MEMORY_SIZE - STACK_SIZE))
{
printf("n<< Stack overflow found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
programminghomeworkhelp.com
32. else if (r2 == SP && ((regs[r2] + r3) & 7) != 0)
{
printf("n<< Misaligned stack access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else if (regs[r2] + r3 < 0 || regs[r2] + r3 >= MEMORY_SIZE
|| ((regs[r2] + r3) & 3) != 0 /* if not aligned */
|| !valid_int(memory[regs[r2] + r3]))
{
printf("n<< Invalid memory access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
memused[regs[r2] + r3] = 1;
sprintf(memory[regs[r2] + r3], "%d", regs[r1]);
affected[r1] = 1;
affected[r2] = 1;
}
}
}
}
programminghomeworkhelp.com
33. else if (!strcmp(opcode, "B"))
{
if (!valid_int(op1))
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r1 = atoi(op1);
if (r1 < 0 || r1 >= MEMORY_SIZE
|| (r1 & 3) != 0) /* if not aligned */
{
printf("n<< Invalid memory access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
PC = r1;
}
}
}
programminghomeworkhelp.com
34. else if (!strcmp(opcode, "BL"))
{
if (!valid_int(op1))
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r1 = atoi(op1);
if (r1 < 0 || r1 >= MEMORY_SIZE
|| (r1 & 3) != 0) /* if not aligned */
{
printf("n<< Invalid memory access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
regs[LR] = PC;
PC = r1;
affected[LR] = 1;
}
programminghomeworkhelp.com
35. }
}
else if (!strcmp(opcode, "BR"))
{
r1 = get_register(op1);
if (r1 == -1)
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
if (regs[r1] < 0 || regs[r1] >= MEMORY_SIZE
|| (regs[r1] & 3) != 0) /* if not aligned */
{
printf("n<< Invalid memory access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
programminghomeworkhelp.com
36. else
{
PC = regs[r1];
affected[r1] = 1;
if (r1 == XZR)
halt = 1; /* BR XZR halts the program */
}
}
}
else if (!strcmp(opcode, "B.EQ"))
{
if (!valid_int(op1))
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r1 = atoi(op1);
if (r1 < 0 || r1 >= MEMORY_SIZE
|| (r1 & 3) != 0) /* if not aligned */
{
programminghomeworkhelp.com
37. printf("n<< Invalid memory access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
if (flagZ)
PC = r1;
}
}
}
else if (!strcmp(opcode, "B.NE"))
{
if (!valid_int(op1))
{
printf("n<< Invalid instruction operand at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
r1 = atoi(op1);
if (r1 < 0 || r1 >= MEMORY_SIZE
|| (r1 & 3) != 0) /* if not aligned */
programminghomeworkhelp.com
38. {
printf("n<< Invalid memory access found at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
else
{
if (!flagZ)
PC = r1;
}
}
}
else /*if invalid opcode */
{
printf("n<< Invalid instruction at address %d >>n", PC - 4);
halt = -1; /* halt simulation */
}
if (halt != -1)
{
printf("nInstruction executed:t%s %s %s %sn",opcode, op1,
op2, op3);
programminghomeworkhelp.com
39. print_registers(regs, affected, PC);
print_stack(regs[SP], memory, memused);
print_memory(memory, memused);
printf("nHit enter for next instruction: >");
fflush(stdout);
getchar();
}
}
printf("nEnd of simulationn");
}
int main(int argc, char **argv)
{
int i;
char memory[MEMORY_SIZE][FIELD_LEN]; /* memory array */
/* by default use code.txt as the input file */
char *filename = "code.txt";
if (argc >= 2) /* if an input file was given */
filename = argv[1]; /* use it as the input filename */
programminghomeworkhelp.com
40. /* clear memory */
for (i = 0; i < MEMORY_SIZE; i++)
strcpy(memory[i], "0");
/* load program from file */
load_program(filename, memory);
/* simulate the program in memory */
simulate_program(memory);
return (EXIT_SUCCESS);
}
programminghomeworkhelp.com