Bimmerfest BMW banner

1 - 8 of 8 Posts

·
Registered
Joined
·
679 Posts
Discussion Starter #1
Hello Everyone :D I'm having difficulties yet again with program #2 in my computer science class. This program is hard!!! Here is the specs:

Simple Computer

1 word = 2 bytes = 16 bits
4096 words of memory
addresses are 12 bits long with a range of 0-4095 (000-FFF)

CPU:
performs integer operations only
data stored in signed magnitude notation
Registers:
Instruction Address Register:
12 bits (holds address of next instruction to be fetched)
Accumulator
16 bits (holds data used as operand)
Condition Code Register:
2 bits (holds result of a compare operation
00 (acc) < (mem)
01 (acc) = (mem)
10 (acc) > (mem)
11 not used

Instruction Opcodes Mnemonic Operation
1 LDA load accumulator
2 STA store accumulator
3 ADD add
4 SUB subtract
5 MUL multiply
6 DIV divide yielding quotient
7 MOD divide yielding remainder
8 CMP compare
9 JMP unconditional branch
A JLT branch if less than
B JEQ branch if equal to
C JGT branch if greater then
D IN input
E OUT output
F HALT terminate execution


---------------------------------------------------------------
The actual sheet in class for program is in the next post.
 

·
Registered
Joined
·
679 Posts
Discussion Starter #2
This program will require the student to code the simulated computer that is described in class. All of te opcodes that are available must be operational and the three registers (accum, condition code, and instruction address) must also be updated after the execution of each instruction.

In addition, a monitor program must be written that will act as DOS to give command to the simple computer for the execution of test programs that will be used to determine the accuracy of the simulation that the student has developed.

The menu includes: input a number, print to file, edit line option, run a program, exit.

The following test programs are to be written and executed.

1) input two numbers, add the two inputted numbers together, display the addendds and their sum.


------>> I gotta head to work but I'll finish the rest of what the program has to do then......

I hardly know where to start with this program it has to all be in C language but its suppose to look like machine language. I started on the menu with the error checking of a range to print to a file and I got that to work with 000-FFF....but I'm going to need some help.

I'll update later I don't wanna be late for work ;)
 

·
Registered
Joined
·
679 Posts
Discussion Starter #4
I'd tell you but then I'd have viewers calling the school asking for the comp sci profs desk telling him that some kid on the internet is asking for help :angel:

I will tell you this though...... this teacher is definitely the hardest teacher I ever had in my 15 years of schooling. There is only 2 tests all year each containing 4 mini programs on "any". On top of the 8 grueling programs that I am explaining here.

Its hard work and I do believe that you need a challenge to get your degree, but this kind of stress is ludicrous. I have 4 people in my class, I had 10 before it started and one dropped out the first day while the 5 others dropped out after the first program.

I'm working my way threw it this is the last classic to get my degree so I'm chugging along to get that C that he always gives out "if he likes you".
 

·
Registered
Joined
·
679 Posts
Discussion Starter #6
I didn't mean to affend the person asking which school ;O) PM me and I'll let ya know. I'm going to past my code I have so far. I'm doing pretty good so far.

//PROGRAM #2 - Simple Computer
//
//
// Justin Hoover
// August 29th 2002

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define digits "0123456789ABCDEF"

/* Menu Options */
void input(char [][5]);
void outtofile(void);
void runaprogram();
void editoption();
int menuscreen();

/* Other Functions */
int goodinput(char []);
void loadaccum();
void storeaccum();
void tobasehex(int,char *);
void reverse(char *);
void prime();
void main();

#define flush while (getchar () != '\n') {}
FILE *output;

int menuscreen()
{
int selection;

printf("\n Simple Computer Menu\n");
printf("\n 1) Input\n");
printf(" 2) Print to file\n");
printf(" 3) Run a program\n");
printf(" 4) Edit option\n");
printf("\n 5) Exit the program\n\n\n<>: ");
scanf("%d",&selection);
flush;
return(selection);
}

void prime()
{
printf("Enter a number: ");

}

void input(char memory[4095][5])
{
int linenumi=0,j=0;
char linenumhex[5],instruction[5];

while(strcmp(instruction,"$$$$"))
{
tobasehex(linenumi,linenumhex);
printf((linenumi<16 ? "000%s: ": "00%s:"),linenumhex);
gets(instruction);
for(j = 0; j < 5; j++)
{
memory[linenumi][j] = instruction[j];
}
memory[linenumi][5] = '\0';
linenumi++;
}

}

void outtofile(void)
{

int answera,answerb;
char startrange[5],stoprange[5];

printf("Which address range to start [0000-FFFF]: ");
gets(startrange);
printf("Which address range to stop [0000-FFFF]: ");
gets(stoprange);
answera = goodinput(startrange);
answerb = goodinput(stoprange);

if (answera > 3 && answerb > 3)
{
fprintf(output,"SENDING to file");
}
else
{
fprintf(output,"Error in range specified --- RETRY");
}
}

void runaprogram()
{
}

void editoption()
{
}

void openfiles()
{

if ((output = fopen("a:\compfile.txt","w")) != NULL)
{}
else
{
fprintf(output,"File does not exist\n\n");
}
}

int goodinput(char in[])
{
int goody;
int i=0,j=0;

goody=0;
while (in != '\0')
{
j=0;
while (digits[j] != '\0')
{
if (in == digits[j])
{
goody++;
}
j++;
}
i++;
}
return(goody);
}

void tobasehex(int dec, char out[])
{
int count, loc;

strcpy(out,"");
count = 0;
do
{
out[count] = digits[dec%16];
dec = dec/16;
count++;
}
while(dec);
out[count] = '\0';
reverse(out);
}

void reverse(char s[])
{
int i=0;
char temp;

while(i <strlen(s)/2)
{
temp = s;
s = s[strlen(s)-1-i];
s[strlen(s)-1-i] = temp;
i++;
}
}

/* --- Program Mainline -------------------- */
void main()
{
int menuselect=0;
char in[80],memory[4095][5];

openfiles();
while (menuselect != 5)
{
menuselect = menuscreen();
switch (menuselect)
{
case 1 : input(memory); break;
case 2 : outtofile(); break;
case 3 : runaprogram(); break;
case 4 : editoption(); break;
default : break;
}
}


} //simple computer
 

·
The Original Dr. Phil
Joined
·
10,985 Posts
eugeneDC/TX said:
andrew was asking cuz he went to school in PA....
Where did Andrew go to school?

I went to IUP:) Eons ago but I went :eek:

Rufus is going to a school around the state capital so it should be easy to narrow it down. I'd tell you but don't want him to have a nervous break down:rolleyes: But it's not PSU ;)
 

·
Gone Motoring!
Joined
·
2,025 Posts
PM 325xiT said:

Where did Andrew go to school?


oh, and after reading Rufus' post saying that was the last class he needed to graduate, I'm pretty sure that he is not going to my school.

--Andrew
 
1 - 8 of 8 Posts
Top