How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Mr. Gregory White Your Own Question

Mr. Gregory White
Mr. Gregory White, Professor
Category: Homework
Satisfied Customers: 5239
Experience:  M.A., M.S. Education / Educational Administration
46856550
Type Your Homework Question Here...
Mr. Gregory White is online now
A new question is answered every 9 seconds

Computer Science Fundamentals You have been asked to write a

Customer Question

Computer Science Fundamentals
You have been asked to write a C program that simulates a 'Brooks hear Machine'.
The program reads machine code from a text file "a3.txt".
Each line in the file contains 4 hexadecimal digits.
The first two digits on the first line make up an 8-bit byte that is to be stored at location 0 in the memory of the Brooks hear Machine. The second two digits make up an 8-bit byte that is to be stored at location 1 in memory.
The next line contains two bytes that are stored at locations 2 and 3.
This is repeated until you get to the end of file.
Each line will be valid, and the data will fit into 256 bytes.
The Brook shear Program that these instructions form may not be particularly interesting, but it will be valid.
Your program steps though the machine code, one instruction at a time. Before each instruction, your program prints out a line of text that describes the current contents of the Program Counter, the instruction to be executed and the registers.
Each time an instruction is executed your program alters the Program Counter, Registers and Memory accordingly.
The format of the output line is:
PC INST – [R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 RA RB RC RD RE RF]
Where PC is the program counter, INST is the current instruction and R0 through to RF are the value of the sixteen registers. Each field is output as a 2 or 4 digit hexadecimal value (use the X format specifier to get capital letters) with a leading 0 if necessary.
Output continues (with no user intervention) until the Halt instruction is executed, at which time your program also stops.
A Halt instruction will occur in all test programs.
Example: if a3.txt contains:
B404
239A
2412
5345
350C
C000
Then the output is:
00 B404 – [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
04 2412 - [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
06 5345 - [00 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00]
08 350C - [00 00 00 00 12 12 00 00 00 00 00 00 00 00 00 00]
0A C000 - [00 00 00 00 12 12 00 00 00 00 00 00 00 00 00 00]
Use unsigned char's for your PC, registers and memory.
When reading the a3.txt file, be careful with alignment problems in the scanf-like functions. First read each line into an unsigned int variable, then extract out the two bytes using bit-wise operators and store them in your memory array.
Your program must open the file a3.txt for reading by using the following arguments to the fopen function call
f = fopen("a3.txt","r"); //you may change 'f' if you prefer!
Brook shear machine instructions
1RXY Load register R with the value at memory address XY
2RXY Load register R with the value XY
3RXY Store the value in register R at memory address XY
40RS Copy/move the value in register R to register S
5RST add the values in registers R and S and put the answer in register T
7RST Bit-wise OR the values in registers R and S and put the answer in register T
8RST Bit-wise AND the values in registers R and S and put the answer in register T
9RST Bit-wise XOR the values in registers R and S and put the answer in register T
AR0X Rotate the contents of register R X times to the right
BRXY Jump to the instruction located at memory address XY if the value in register R is equal to the value in register 0 (i.e. change the PC to XY)
C000 Halt
Submitted: 1 year ago.
Category: Homework
Expert:  Mr. Gregory White replied 1 year ago.
THIS ANSWER IS LOCKED!

You need to spend $3 to view this post. Add Funds to your account and buy credits.
Customer: replied 1 year ago.
This i do.
Expert:  Mr. Gregory White replied 1 year ago.

After going through my resources, I do not have what is necessary to complete at this time.

I am opting out and opening up to the other professionals and messaging a couple who might be able to help.

Someone should be with you shortly.

Customer: replied 1 year ago.
Thanks
Customer: replied 1 year ago.
What???
Please dont tell me you guys cant answer my question....If you guys do, please give me some direction on how to begin..That will help alot, since i paid you guys $50.....