具体可以解决的问题:
C、C++、Java语法:
if、else、for、while loop
File、 Input、Output、Function
Class、Method、 Inheritance、Polymorphism、Overload、Override
JUnit、test、Database、Web、JS、CSS
C、C++使用gcc和g++编译器,写Makefile
 
Data structure:
Dynamic memory allocate
        LinkedList、OrderedList、DoubleList
       Sort、 Heap、 Stack、 Queue
       Binary Search Tree(BST)
       Hashtable、Graph、TopoSort
 
Operating System:
Thread、Process、shell、fork、 exec、pipe、dup2
Socket、CPU、Job、Schedule、Memory、File System
      我只是业余代写,能做就做,不能做不强求,所以时间原因,目前只做国外的题目(英文),国内及其他语言的不接,谢谢合作!
      QQ:2365427650

代写Processing Calculator with JOptionPane

COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Part (1) Calculator with JOptionPane
For this part, you are going to develop a simple calculator which have these arithmetic
operators:
● +
this is addition
● -
this is minus
● *
this is multiple
● /
this is division
● %
this is not percentage! it is modulus which gives you the reminder
For this part of the assignment you are required to use these techniques:
1. import javax.swing.JOptionPane;
2. methods with a return type of double.
3. while loops
4. Using logical OR operator ||
5. Using logical AND operator &&
6. Use arguments (parameters) for all your methods. (passing your both numbers to the
methods). You are not allowed to define any variable outside of your methods.
“You can use other techniques which you have learnt so far in previous units such as if, else if,
else, etc.”. For this part, you do not need to have the draw () function.
you must create all the following method with the return type of double and use the suggested
names for your methods:
● add (double number1, double number2) for Addition
● minus (double number1, double number2) for Subtraction
● multiply (double number1, double number2) for Multiplication
● divide (double number1, double number2) for Division
● modul (double number1, double number2) for Modulus
You are required only to call one method in your setup (), and that is a void method that is called
process () that has no parameters, you should not have any variables inside your setup.
However, you can create your variables in the process () method. So, your setup () must be
identical to the following code:
void setup ()
{
process ();
}
Your output must be something similar to the figure below after running your program.
Run your program and ask the user to enter the first number:

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
After pressing OK, your system must show this input message which is asking for choosing
arithmetic operators:
I entered
*
After this window your system needs to show the window which asks for the second number:
number 55 has been entered
Now your system must calculate the result and print it like this on the screen:

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
As you can see the result is 1265.0 which is a double primitive data type.
Next task is to ask your user if he/she wants to continue using your software.
I answered yes in here and kept using the program
So now your system must again ask for the first number
this time you see, there is no welcome message in this window, and number 8.5 has been
entered as the first number.
now it’s the time for asking the arithmetic operator:

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
we want to divide now
and here we ask for the second number:
and as usual, after clicking on OK button, you can see the result.
Now your system must ask again (your while loop) if you want to continue or not!

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
this time we enter no or No. (ignore the case in your program)
and by pressing the OK button, your system must show the following message:
Remember that this is not the programming standard exit message. You must have 1 more
message for that.
There is only 1 more thing left! Keep reading...
What if the user didn’t type a correct arithmetic operator? You should have a check for that
somewhere in your code before you ask for your second number.
as you can see the word “asd” is entered instead of a valid operator.
Your program should keep asking the user till a valid arithmetic operator is entered. You can
see that in the dialog box bellow asd is mentioned as a wrong operator in the first line.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
And after you enter a valid operator it should continue calculation.
End of part 1.
Submit your A3P1.pde to your dropbox.
Continue reading for the next part...

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
Part (2) Look of a fancy calculator with some functionality
○ This is the last part of your assignment 3. In this part, you are going to create a
calculator that looks like” a Windows os or Mac os or a custom one that has five
rows and four columns.” Your calculator does not need to be functional like a
calculator. This means the operators like “+, -, * and /” or numbers do not need to
be working! You just need to create the look of it plus some other small
functionality that will be explained below. For this part, you are required to have
the draw () method and call the other functions in the draw () method.
○ For this section of the assignment you are required to apply the following
techniques:
○ 1. Use of constants and use them correctly
○ 2. Usage of global variable and using it properly
○ 3. Usage of for loops
○ 4. Implementing user defined methods
○ 5. Usage of && operator
○ You can use other techniques that you have learnt so far to show the final output,
but all the requested techniques must be included in your solution.
○ ○
You are required to implement the following methods in your assignment:
○ ● void drawRowsCols ()
○ This method has only one job, and that is drawing horizontal and vertical lines of
your calculator. These lines separate numbers and operators and other
components. You must draw these lines with the usage of for loop/s. Figure
below demonstrate the outcome of this method.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● void fillNumbers ()
○ The task for this method is to fill up the numbers 0 to 9 using two for loops.
○ Make sure you do not have any number next to 0. This means your first row
from the bottom only contains one number that is 0.
○ The very right column should not contain any numbers. We will put the operators
later in these spots. Figure below demonstrate the outcome of this method
● void fillOperators ()
○ This method fills other operators such as {“+”, “-”, “*”, “/”, “=”, “.”, “sin”, “cos”,
“sqrt” and “AC”}
○ You can put them in different locations if you want to. Or you can follow the same
pattern that the figure below shows:

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● void clearScreen ()
○ This method just draw a white rectangle on the upper space of your calculator
that it is empty and whenever you call this method it looks like you clear the
screen.
○ If the height of the canvas is 700 then this rectangle should occupy 200 px of the
height (two rows).
○ Make sure your rectangle does not have any stroke! The figure below
demonstrates the outcome of this method.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● void mouseClicked ()
○ This method has two tasks.
■ The first task is, If the user clicks on any of the numbers or operators
(clicks anywhere in five rows and four columns from bottom) then you are
required to have a counter and keep adding up the clicks and show the
updated number on the white space on top. The figure below with three
pictures indicates that the user clicked three times on the keys and the
calculator shows the updated number after each time of clicking.

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● The second task is, if the user clicked on anywhere on the upper side of
the calculator (the space that you did not use for loops to make grids on
it), it would erase the all the numbers. It also will reset your counter to 0.
Figure below is the sample output after clicking in that area.
Some useful information:
● The size of your canvas should be 500 by 700
● The height from 0 to 200 and width from 0 to 500 is reserved for the clearing the text
● The width and height of every column are 125 and 100 respectively.
● You are only allowed to call the following methods in the draw ()
○ drawRowsColsOld ();
○ fillNumbers ();
○ fillOperators ();

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
● You can also use a boolean variable in the draw () if you needed. But just one time!
● Call the clearScreen in the mouseClicked () properly. You do not need to call it
anywhere else.
● You can define a proper text size by yourself if it fits in one grid and it is not very small to
see
● The counting should start from the left side of the white rectangle.
End of part 2.
Submit your A3P2.pde to your dropbox.
Continue reading for the next part...
__________________________________
Assignment 3 Grading Guide:
Q1:(Calculator with JOptionPane) (39 marks)
1. Import JOptionPane and use it properly to show messages and get inputs from user (10)
2. Not having any global variables and usage of local variables (2)
3. Usage of while loop to ask if the user wants to keep using the calculator or terminate it.
(5)
4. Usage of while loop to keep asking for a correct operator in case of entering wrong input
as the operator. (5)
5. Usage of logical OR operator || (1)
6. Usage of logical AND operator && (1)
7. Implementing the following user defined method and return a proper value (10)
a. add (double number1, double number2)
b. minus (double number1, double number2)
c. multiply (double number1, double number2)
d. divide (double number1, double number2)
e. modul (double number1, double number2)
8. Following programming standards and adding proper comments for all the blocks (5)
Q3: Look of a Fancy Calculator with Some Functionality (34 marks)
1. Usage of constants and use them properly (2)
2. Usage of global variable and use them properly (2)
3. Implementing the void drawRowsCols () (6)
4. Implementing the void fillNumbers () (6)
5. Implementing the void fillOperators () (6)
6. Implementing the void clearScreen () (3)
7. Implementing the void mouseClicked () (6)
8. Usage of && or || operator (1)
9. Not having additional method calls and declaration in the draw () method. (It is explained
above) (2)

Assignment 3
COMP 1010 Centre for Advance of Teaching and Learning
Course Title: Introduction to Computer Science 1
Term: Winter 2017
Total Marks: 73
The due date is March 14 at 11:30 pm. Remember that the programming standards carry some
marks and do not forget to apply it to your code.
Don’t forget to be active in the discussion forums and ask your questions. It DOES help a lot!

代写C++ The square laser maze

The square laser maze
Consider a sample laser maze shown on the left below:
In maze 1, the orange laser beam starts from coordinates (1,2) with laser going along the
East direction. The laser first hits a single‐sided mirror at (2,2), and then travels North, hits a
double‐sided mirror at (2,4), and then goes East, hits another double‐sized mirror at (5,4),
and direction changes to South. Finally, arriving the destination at (5,3). The green laser
beam starts from (0,3) with laser going along the East direction. If you follow the path of the
laser beam, you will notice the laser hits a few mirrors and finally arriving the destination at
(4,1).
In maze 1, both laser beams arrive at a destination. On the other hand, all beams in maze 2
cannot reach a destination. The orange laser beam goes off the boundary, the green laser
beam is blocked at (2,5) and cannot go further, and the red laser beam is blocked at (3,0) as
well.
A typical laser maze contains these items:
At least 1 and at most 5 laser beam sources. Laser beam source will point to one of
these directions: North, East, South, West.
At least 1 and at most 5 destinations. Number of destinations can be different from
the number of sources.
Zero or more single‐sided mirrors. There are 4 kinds of single‐sided mirror, facing
NW, SE, SW, or NE.
Zero or more double‐sided mirrors. There are 2 kinds of double‐sided mirror.
Zero or more laser blocks. This is the cross shown in maze 2 above. A laser block will
stop any laser beam at the space that it is located.
Note that in a laser maze, there will be at most 20 items, and no two items share the same
coordinates. Smallest possible laser maze is 2x2.
x
y
0 1 2 3 4 5 6
6
5
4
3
2
1
0
Maze 1 Maze 2

ENGG1111 A1 2016/17
‐2‐
Converting the graphical maze into words
Somehow the laser maze needs to be entered into the program. We will give each item in
the laser maze a name. Below is the conversion table:

代写汇编Assembly MIPS LC3 Computer System

Listing 1: “Hello World!” in LC-3.
The above listing is a typical hello world program written in LC-3 assembly language. The program
outputs “Hello World!” to the console and quits. We will now look at the composition of this
program.
Lines 1 and 2 of the program are comments. LC-3 uses the semi-colon to denote the beginning
of a comment, the same way C++ uses “//” to start a comment on a line. As you probably already
know, comments are very helpful in programming in high-level languages such as C++ or Java. You
will find that they are even more necessary when writing assembly programs. For example in C++,
the subtraction of two numbers would only take one statement, while in LC-3 subtraction usually
takes three instructions, creating a need for further clarity through commenting.
Line 3 contains the .ORIG pseudo-op. A pseudo-op is an instruction that you can use when
writing LC-3 assembly programs, but there is no corresponding instruction in LC-3’s instruction
set. All pseudo-ops start with a period. The best way to think of pseudo-ops are the same way you
would think of preprocessing directives in C++. In C++, the #include statement is really not a C++
statement, but it is a directive that helps a C++ complier do its job. The .ORIG pseudo-op, with its
numeric parameter, tells the assembler where to place the code in memory.
Memory in LC-3 can be thought of as one large 16-bit array. This array can hold LC-3 instructions or it can hold data values that those instructions will manipulate. The standard place for code
to begin at is memory location x3000. Note that the “x” in front of the number indicates it is in
hexadecimal. This means that the “.ORIG x3000” statement will put “LEA R0, HW” in memory
location x3000, “PUTS” will go into memory location x3001, “HALT” into memory location x3002,
and so on until the entire program has been placed into memory. All LC-3 programs begin with the
.ORIG pseudo-op.
Lines 4 and 5 are LC-3 instructions. The first instruction, loads the address of the “Hello World!”
Revision: 1.17, January 20, 2007 viiProgramming in LC-3
string and the next instruction prints the string to the console. It is not important to know how these
instructions actually work right now, as they will be covered in the labs.
Line 6 is the HALT instruction. This instruction tells the LC-3 simulator to stop running the
program. You should put this in the spot where you want to end your program.
Line 7 is another pseudo-op .STRINGZ. After the main program code section, that was ended
by HALT, you can use the pseudo-ops, .STRINGZ, .FILL, and .BLKW to save space for data that
you would like to manipulate in the program. This is a similar idea to declaring variables in C++.
The .STRINGZ pseudo-op in this program saves space in memory for the “Hello World!” string.
Line 8 contains the .END pseudo-op. This tells the assembler that there is no more code to assemble. This should be the very last instruction in your assembly code file. .END can be sometimes
confused with the HALT instruction. HALT tells the simulator to stop a program that is running.
.END indicates where the assembler should stop assembling your code into a program.
Syntax of an LC-3 Instruction
Each LC-3 instruction appears on line of its own and can have up to four parts. These parts in order
are the label, the opcode, the operands, and the comment.
Each instruction can start with a label, which can be used for a variety of reasons. One reason
is that it makes it easier to reference a data variable. In the hello world example, line 7 contains
the label “HW.” The program uses this label to reference the “Hello World!” string. Labels are also
used for branching, which are similar to labels and goto’s in C++. Labels are optional and if an
instruction does not have a label, usually empty space is left where one would be.
The second part of an instruction is the opcode. This indicates to the assembler what kind of
instruction it will be. For example in line 4, LEA indicates that the instruction is a load effective
address instruction. Another example would be ADD, to indicate that the instruction is an addition
instruction. The opcode is mandatory for any instruction.
Operands are required by most instructions. These operands indicate what data the instruction
will be manipulating. The operands are usually registers, labels, or immediate values. Some instructions like HALT do not require operands. If an instruction uses more than one operand like LEA in
the example program, then they are separated by commas.
Lastly an instruction can also have a comment attached to it, which is optional. The operand
section of an instruction is separated from the comment section by a semicolon.
LC-3 Memory
LC-3 memory consists of 216 locations, each being 16 bits wide. Each location is identified with an
address, a positive integer in the range 0 through 216 ? 1. More often we use 4-digit hexadecimal
numbers for the addresses. Hence, addresses range from x0000 to xFFFF.
The LC-3 memory with its various regions is shown in figure 1 on page ix.
viiiProgramming in LC-3
xE000
x0000 ? x00FF Trap Vector Table
x0100 ? x01FF Interrupt Vector Table
x0200 ? x2FFF OS and Supervisor Stack
x3000 ? xFDFF User Program Area
xFE00 ? xFFFF Device Register Addresses
Key
x0000
x1000
x2000
x3000
x4000
x5000
x6000
x7000
x8000
x9000
xA000
xB000
xC000
xD000
xFFFF
xF000
Figure 1: LC-3 memory map: the various regions.
ixLC3 Quick Reference Guide
Instruction Set
Op Format Description Example
ADD ADD DR, SR1, SR2
ADD DR, SR1, imm5
Adds the values in SR1 and
SR2/imm5 and sets DR to that
value.
ADD R1, R2, #5
The value 5 is added to the value in
R2 and stored in R1.
AND AND DR, SR1, SR2
AND DR, SR1, imm5
Performs a bitwise and on the
values in SR1 and SR2/imm5
and sets DR to the result.
AND R0, R1, R2
A bitwise and is preformed on the
values in R1 and R2 and the result
stored in R0.
BR BR(n/z/p) LABEL
Note: (n/z/p) means
any combination of
those letters can appear
there, but must be in
that order.
Branch to the code section
indicated by LABEL, if the bit
indicated by (n/z/p) has been set
by a previous instruction. n:
negative bit, z: zero bit, p:
positive bit. Note that some
instructions do not set condition
codes bits.
BRz LPBODY
Branch to LPBODY if the last
instruction that modified the
condition codes resulted in zero.
BRnp ALT1
Branch to ALT1 if last instruction
that modified the condition codes
resulted in a positive or negative
(non-zero) number.
JMP JMP SR1 Unconditionally jump to the
instruction based upon the
address in SR1.
JMP R1
Jump to the code indicated by the
address in R1.
JSR JSR LABEL Put the address of the next
instruction after the JSR
instruction into R7 and jump to
the subroutine indicated by
LABEL.
JSR POP
Store the address of the next
instruction into R7 and jump to the
subroutine POP.
JSRR JSSR SR1 Similar to JSR except the
address stored in SR1 is used
instead of using a LABEL.
JSSR R3
Store the address of the next
instruction into R7 and jump to the
subroutine indicated by R3’s value.
LD LD DR, LABEL Load the value indicated by
LABEL into the DR register.
LD R2, VAR1
Load the value at VAR1 into R2.
LDI LDI DR, LABEL Load the value indicated by the
address at LABEL’s memory
location into the DR register.
LDI R3, ADDR1
Suppose ADDR1 points to a
memory location with the value
x3100. Suppose also that memory
location x3100 has the value 8. 8
then would be loaded into R3.
LDR LDR DR, SR1, offset6 Load the value from the memory
location found by adding the
value of SR1 to offset6 into DR.
LDR R3, R4, #-2
Load the value found at the address
(R4 –2) into R3.
LEA LEA DR, LABEL Load the address of LABEL into
DR.
LEA R1, DATA1
Load the address of DATA1 into
R1.
NOT NOT DR, SR1 Performs a bitwise not on SR1
and stores the result in DR.
NOT R0, R1
A bitwise not is preformed on R1
and the result is stored in R0.
RET RET Return from a subroutine using
the value in R7 as the base
address.
RET
Equivalent to JMP R7.
LC-3 Quick Reference Guide
xRTI RTI Return from an interrupt to the
code that was interrupted. The
address to return to is obtained
by popping it off the supervisor
stack, which is automatically
done by RTI.
RTI
Note: RTI can only be used if the
processor is in supervisor mode.
ST ST SR1, LABEL Store the value in SR1 into the
memory location indicated by
LABEL.
ST R1, VAR3
Store R1’s value into the memory
location of VAR3.
STI STI SR1, LABEL Store the value in SR1 into the
memory location indicated by
the value that LABEL’s memory
location contains.
STI R2, ADDR2
Suppose ADDR2’s memory
location contains the value x3101.
R2’s value would then be stored
into memory location x3101.
STR STR SR1, SR2, offset6 The value in SR1 is stored in the
memory location found by
adding SR2 and offest6 together.
STR R2, R1, #4
The value of R2 is stored in
memory location (R1 + 4).
TRAP TRAP trapvector8 Performs the trap service
specified by trapvector8. Each
trapvector8 service has its own
assembly instruction that can
replace the trap instruction.
TRAP x25
Calls a trap service to end the
program. The assembly instruction
HALT can also be used to replace
TRAP x25.
Symbol Legend
Symbol Description Symbol Description
SR1, SR2 Source registers used by instruction. LABEL Label used by instruction.
DR Destination register that will hold
the instruction’s result.
trapvector8 8 bit value that specifies trap service
routine.
imm5 Immediate value with the size of 5
bits.
offset6 Offset value with the size of 6 bits.
TRAP Routines
Trap Vector Equivalent Assembly
Instruction
Description
x20 GETC Read one input character from the keyboard and store it into R0
without echoing the character to the console.
x21 OUT Output character in R0 to the console.
x22 PUTS Output null terminating string to the console starting at address
contained in R0.
x23 IN Read one input character from the keyboard and store it into R0 and
echo the character to the console.
x24 PUTSP Same as PUTS except that it outputs null terminated strings with
two ASCII characters packed into a single memory location, with
the low 8 bits outputted first then the high 8 bits.
x25 HALT Ends a user’s program.
Pseudo-ops
Pseudo-op Format Description
.ORIG .ORIG # Tells the LC-3 simulator where it should place the segment of
code starting at address #.
.FILL .FILL # Place value # at that code line.
.BLKW .BLKW # Reserve # memory locations for data at that line of code.
.STRINGZ .STRINGZ “<String>” Place a null terminating string <String> starting at that location.
.END .END Tells the LC-3 assembler to stop assembling your code.
LC-3 Quick Reference Guide
xiLC-3 Quick Reference Guide
xiiLAB 1
ALU Operations
1.1 Problem Statement
The numbers X and Y are found at locations x3100 and x3101, respectively. Write an LC-3 assembly
language program that does the following.
? Compute the sum X +Y and place it at location x3102.
? Compute X AND Y and place it at location x3103.
? Compute X OR Y and place it at location x3104.
? Compute NOT(X) and place it at location x3105.
? Compute NOT(Y) and place it at location x3106.
? Compute X +3 and place it at location x3107.
? Compute Y ?3 and place it at location x3108.
? If the X is even, place 0 at location x3109. If the number is odd, place 1 at the same location.
The operations AND, OR, and NOT are bitwise. The operation signified by + is the usual
arithmetic addition.
1.1.1 Inputs
The numbers X and Y are in locations x3100 and x3101, respectively:
x3100 X
x3101 Y
1.1.2 Outputs
The outputs at their corresponding locations are as follows:
Revision: 1.12, January 20, 2007 1–1LAB 1 1.2. INSTRUCTIONS IN LC-3
x3102 X +Y
x3103 X AND Y
x3104 X OR Y
x3105 NOT(X)
x3106 NOT(Y)
x3107 X +3
x3108 Y ?3
x3109 Z
where Z is defined as
Z = (0 if 1 if X X is even is odd. (1.1)
1.2 Instructions in LC-3
LC-3 has available these ALU instructions: ADD (arithmetic addition), AND (bitwise and), NOT
(bitwise not).
1.2.1 Addition
Adding two integers is done using the ADD instruction. In listing 1.1, the contents of registers R1
and R2 and added and the result is placed in R3. Note the values of integers can be negative as well,
since they are in two’s complement format. ADD also comes in immediate version, where the second
operand can be a constant integer. For example, we can use it to add 4 to register R1 and place the
result in register R3. See listing 1.1. The constant is limited to 5 bits two’s complement format.
Note, as with all other ALU instructions, the same register can serve both as a source operand and
the destination register.
1 ; Adding two r e g i s t e r s
2 ADD R3 , R1 , R2 ; R3 ← R1 + R2
3 ; Adding a r e g i s t e r and a c o n s t a n t
4 ADD R3 , R1 , #4 ; R3 ← R1 + 4
5 ; Adding a r e g i s t e r and a n e g a t i v e c o n s t a n t
6 ADD R3 , R1 , #?4 ; R3 ← R1 ? 4
7 ; Adding a r e g i s t e r to i t s e l f
8 ADD R1 , R1 , R1 ; R1 ← R1 + R1
Listing 1.1: The ADD instruction.
1.2.2 Bitwise AND
Two registers can be bitwise ANDed using the AND instruction, as in listing 1.2 on page 1–3. AND
also comes in the immediate version. Note that an immediate operand can be given in hexadecimal
form using x followed by the number.
1.2.3 Bitwise NOT
The bits of a register can be inverted (flipped) using the bitwise NOT instruction, as in listing 1.3 on
page 1–3.
1–2LAB 1 1.3. HOW TO DETERMINE WHETHER AN INTEGER IS EVEN OR ODD
1 ; Anding two r e g i s t e r s
2 AND R3 , R1 , R2 ; R3 ← R1 AND R2
3 ; Anding a r e g i s t e r and a c o n s t a n t
4 ADD R3 , R1 , xA ; R3 ← R1 AND 0000000000001010
Listing 1.2: The AND instruction.
1 ; I n v e r t i n g the b i t s of r e g i s t e r R1
2 NOT R2 , R1 ; R2 ← NOT(R1)
Listing 1.3: The NOT instruction.
1.2.4 Bitwise OR
LC-3 does not provide the bitwise OR instruction. We can use, however, AND and NOT to built it.
For this purpose, we make use of De Morgan’s rule: X OR Y = NOT(NOT(X) AND NOT(Y)). See
listing 1.4.
1 ; ORing two r e g i s t e r s
2 NOT R1 , R1 ; R1 ← NOT(R1)
3 NOT R2 , R2 ; R2 ← NOT(R2)
4 AND R3 , R1 , R2 ; R3 ← NOT(R1) AND NOT(R2)
5 NOT R3 , R3 ; R3 ← R1 OR R2
Listing 1.4: Implementing the OR operation.
1.2.5 Loading and storing with LDR and STR
The instruction LDR can be used to load the contents of a memory location into a register. Knowing
that X and Y are at locations x3100 and x3101, respectively, we can use the code in listing 1.5 on
page 1–4 to load them in registers R1 and R3, respectively. In the same figure one can see how
the instruction STR is used store the contents of a register to a memory location. The instruction
LEA R2, Offset loads register R2 with the address (PC + 1 + Offset), where PC is the address
of the instruction LEA and Offset is a numerical value, i.e. the immediate operand. Figure 1.2 on
page 1–5 shows the steps it takes to execute the LEA R2, xFF instruction.
If instead of a numerical value, a label is given, such as in instruction LEA R2, LABEL , then
the value of the immediate operand, i.e. the offset, is automatically computed so that R2 is loaded
with the address of the instruction with label LABEL.
1.3 How to determine whether an integer is even or odd
In binary, when a number is even it ends with a 0, and when it is odd, it ends with a 1. We can obtain
0 or 1, correspondingly, by using the AND instruction as in listing 1.6 on page 1–4. This method is
valid for numbers in two’s complement format, which includes negative numbers.
1.4 Testing
Test your program for several input pairs of X and Y. In figure 1.1 on page 1–4 an example is shown
of how memory should look after the program is run. The contents of memory are shown in decimal,
1–3LAB 1 1.5. WHAT TO TURN IN
1 ; Values X and Y are loaded i n t o r e g i s t e r s R1 and R3.
2 .ORIG x3000 ; Address where program code begins
3 ; R2 i s loaded with the beginning address of the data
4 LEA R2 , xFF ; R2 ← x3000 + x1 + xFF (= x3100 )
5 ; X, which i s l o c a t e d a t x3100 , i s loaded i n t o R1
6 LDR R1 , R2 , x0 ; R1 ← MEM[ x3100 ]
7 ; Y, which i s l o c a t e d a t x3101 , i s loaded i n t o R3
8 LDR R3 , R2 , x1 ; R3 ← MEM[ x3100 + x1 ]
9 . . .
10 ; S t o r i n g 5 in memory l o c a t i o n x3101
11 AND R4 , R4 , x0 ; Clear R4
12 ADD R4 , R4 , x5 ; R4 ← 5
13 STR R4 , R2 , x1 ; MEM[ x3100 + x1 ] ← R4
Listing 1.5: Loading and storing examples.
1 AND R2 , R1 , x0001 ; R2 has the value of the l e a s t
2 ; s i g n i f i c a n t b i t of R1.
Listing 1.6: Determining whether a number is even or odd.
hexadecimal, and binary format.
Address Decimal Hex Binary Contents
x3100 9 0009 0000 0000 0000 1001 X
x3101 -13 FFF3 1111 1111 1111 0011 Y
x3102 -4 FFFC 1111 1111 1111 1100 X +Y
x3103 1 0001 0000 0000 0000 0001 X AND Y
x3104 -5 FFFB 1111 1111 1111 1011 X OR Y
x3105 65526 FFF6 1111 1111 1111 0110 NOT(X)
x3106 12 000C 0000 0000 0000 1100 NOT(Y)
x3107 12 000C 0000 0000 0000 1100 X +3
x3108 -16 FFF0 1111 1111 1111 0000 Y ?3
x3108 1 0001 0000 0000 0000 0001 z
Figure 1.1: Example run.
1.5 What to turn in
? A hardcopy of the assembly source code.
? Electronic version of the assembly code.
? For each of the (X,Y) pairs (10,20),(?11,15),(11,?15),(9,12), screenshots that show the
contents of location x3100 through x3108.
1–4LAB 1 1.5. WHAT TO TURN IN
and storing the result into R2.

CS 2360 Programming Assignment 5

 

CS 2360 Programming Assignment 5

 

lab 10

 

Week 10 Laboratory

A comment about exercise 5 below:

Lab 8

We have created some scripts that can automatically run your program against some tests. To run these tests you can execute the dry run program with an argument that corresponds to the lab and week, i.e. lab08 for this week. It expects to find all the programs to be submitted as part of this lab in the current directory. You can use dry run as follows:

Laboratory7

 

We have created some scripts that can automatically run your program against some tests. To run these tests you can execute the dry run program with an argument that corresponds to the lab and week, i.e. lab07 for this week. It expects to find all the programs to be submitted as part of this lab in the current directory. You can use dry run as follows:

CITS1001 2048 Game

2048 is a recent online computer game. Play takes place on a 4x4 board of squares on which a
sequence of tiles appears, each holding a number. Players move tiles around by sliding rows and
columns, with the aim of combining identical tiles to make higher numbers. The player's score is
determined largely by the tiles on the final board.
You can play 2048 online to get familiar with the game. In this project you will construct a computer
player for a simplified version of 2048, and also an interface for a human player.
The rules of 2048
Tiles
2048 is played on a 4x4 grid of squares. Each square is either empty, or it holds a tile holding a number
in {2, 4, 8, 16, 32, 64, ...}, i.e. a power of two. At the start of the game the board holds between one and
sixteen 2&shy;tiles.
Moves
The player makes a sequence of moves, each of which is Left, Right, Up, or Down. The description below
is for Up moves &shy; probably you can translate for the other three possibilities, otherwise they are described
here.
An Up move causes all columns on the board to attempt to slide upwards.
If no column can legally slide, nothing happens.
Otherwise all legal slides are implemented, and then a new 2&shy;tile appears in the leftmost empty
square of the bottom row.
Testing slides
A column's attempt to slide upwards is deemed legal if either or both of the following apply.
A non&shy;empty square in that column has an empty square above it.
Two adjacent squares in that column hold identical tiles.
A column cannot slide upwards if it has X tiles at the top with no adjacent identical tiles, and 4&shy;X empty
squares at the bottom.
Implementing slides
When a slide is implemented, the following occurs.
U S E F U L L I N K S
Unit outline
Unit timetable 2016
help1001
csentry
cssubmit
csmarks
Compulsory online modules
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 2/5
All squares slide to the top of the column, then
where there are two adjacent squares holding identical tiles K, those tiles combine into a single tile 2K
on the higher square, and all lower tiles slide up again. A tile can participate in only one combination
in a given move.
Examples
The following examples should help.
Illegal slide Illegal slide No combinations, only
sliding
No combinations, only
sliding
One combination One combination
Two combinations Combination is not recursive Combination is not recursive
Game over
The game is over when no more successful (i.e. legal) moves are possible.
Scoring
Each successful move gets one point, and each unsuccessful move loses one point &shy; so the score can go
up or down as the game proceeds.
Representations
Squares
Each square on the board is represented by an object belonging to the class Square. The class records
what value the square currently holds, with 0 representing an empty square; it also provides methods to
interrogate this value, and to set or modify it safely. You are required to write the constructor for Square,
and one public method.
public void setSquare(int x) throws Exception
sets the square to the value x if it is 0 or a legal tile value, otherwise it throws a checked exception with
a suitable error message.
public Square(int x)
creates the square with the value x if it is 0 or a legal tile value, otherwise it creates an empty square.
The game state
The state of the game as it progresses is represented by an object belonging to the class GameState.
This records the current state of the board, and the current score. You are required to write two
constructors for GameState, and the following public methods.
public GameState(String file) throws Exception
sets up the board according to the contents of the file file, e.g. B1.txt. You may assume that the file
format is exactly the same as in the example. If all squares are set to empty, the constructor throws a
checked exception with a suitable error message.
public GameState(double p) throws Exception
sets up the board with each square independently set to either 2 (with probability p) or empty. If all
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 3/5
squares are set to empty, the constructor throws a checked exception with a suitable error message.
public boolean forward(Square[] row)
attempts to slide row towards the front of the array, in the manner described above. Based on the nine
pictured examples, it would do the following.
{0,0,0,0} is unchanged
{2,8,4,0} is unchanged
{0,2,0,4} turns into {2,4,0,0}
{4,2,0,4} turns into {4,2,4,0}
{2,2,0,0} turns into {4,0,0,0}
{0,2,0,2} turns into {4,0,0,0}
{2,2,4,4} turns into {4,8,0,0}
{2,0,2,4} turns into {4,4,0,0}
{2,2,2,2} turns into {4,4,0,0}
If the method makes any changes to row, it returns true; otherwise it returns false.
public void left()
attempts a Left move. Remember to include the placement of the new tile, if appropriate, and
remember to update the score.
public void clockwise()
rotates the board 90 degrees clockwise, e.g. it would turn {{2,4,8,16},{32,0,0,0},{64,0,0,0},{128,0,0,0}}
into {{128,64,32,2},{0,0,0,4},{0,0,0,8},{0,0,0,16}}. In pictures:
public void anticlockwise()
rotates the board 90 degrees anti&shy;clockwise, e.g. it would turn {{128,64,32,2},{0,0,0,4},{0,0,0,8},
{0,0,0,16}} into {{2,4,8,16},{32,0,0,0},{64,0,0,0},{128,0,0,0}}. (It does the inverse of clockwise.)
public void right()
attempts a Right move.
public void up()
attempts an Up move.
public void down()
attempts a Down move.
public boolean gameOver()
returns true iff there are no legal moves available on the current board.
The game
The class Play2048 defines the code for actually playing 2048. You are required to write three
constructors for 2048, and one public method.
public Play2048(String file)
sets up a game using the file file, and displays the initial board.
public Play2048(double p)
sets up a game using the probability p, and displays the initial board.
public Play2048()
sets up a game using the probability 0.3, and displays the initial board.
public void play2048()
makes the computer play a game of 2048, with each (attempted) move chosen uniformly randomly.
Display the score as you go along, and display a "Game Over" message when no legal moves are
available.
It will almost certainly help you to split up some of these methods, i.e. to write private helper methods.
Tasks
The software architecture you will use for 2048 thus comprises five classes.
Play2048
GameState
Square
SimpleCanvas &shy; note that this version is slightly simplified from previous versions
FileIO
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 4/5
Each link above gives you a skeleton of the required class, including instance variables, constructors,
and methods. You are required to complete the methods and constructors whose bodies are marked with
the comment TODO, in Play2048.java, GameState.java, and Square.java. Make sure you understand the
connections between the classes, and where each method fits into the scheme described above.
I suggest you tackle these tasks in roughly the order above, although it may be helpful to write a
constructor for Play2048 and a board display method early, to make testing easier. Here are some tips. If
I add to this list, I will update the document version number.
The move description on the main page is for an Up move; whereas the first move you are likely to
implement is a Left move. Make sure that this discrepancy doesn't cause you any problems!
When performing moves, you need to update the existing board. Creating new array(s) will not make
the tester happy.
You may add instance variables to Play2048, although make sure that the information being stored
really needs an instance variable. Do not add instance variables to the other classes.
Avoid repetitious code! There is much less work here than it may appear...
Submission
Submit your three completed files Play2048.java, GameState.java, and Square.java via cssubmit. Only
one submission per team is required, but make sure that all names are clearly marked on every
submitted class.
Your file names, class names, and method names and signatures must match the specifications
exactly. The marking process is partly automated and any deviation in the names or signatures will
cause problems, which will be penalised.
Assessment
Your submission will be assessed on
completeness: how many of the methods you have written;
correctness: whether your methods implement the specifications exactly;
clarity: whether your code is clear to read and well&shy;constructed;
display: how attractive your 2048 display is.
You can (theoretically) get 100% in this project by implementing completely
all game mechanics, and
a computer player that selects a random move to attempt at each turn, and
a basic screen display using SimpleCanvas that shows the progression of a game (something like the
example boards above).
However, if you lose marks in the basic phase of the project, you can regain some of those marks by
going further with some aspects of the game. Suggestions would include
implementing a version of 2048 that works for arbitrary (user&shy;defined) board&shy;sizes;
implementing a more&shy;intelligent computer player for 2048;
implementing a fancier interface for 2048, that allows humans to play the game.
If you extend your program in an attempt to get bonus marks, please make that clear in your submitted
files. Note that it is not possible to get more than 100% of the project mark.
Testing
Testing classes are provided for you to validate your program before submission.
SquareTest
GameStateTest
B1.txt
Note however that the correctness of your program is your responsibility. The testing classes are
(intentionally) quite brief, and a program that passes all of the tests is not guaranteed to be free of errors.
"Testing shows the presence, not the absence, of bugs." &shy;&shy; E.W. Dijkstra
Feel free to augment the testing classes with more tests of your own.
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 5/5
Prizes
There are two prizes** available for Project 2:
a prize for the best performing 2048 computer player;
a prize for the most attractive 2048 human player interface.
If you believe your submission is worthy of consideration for a prize, email lyndon.while@uwa.edu.au
with a brief description of what you have achieved. We will download your actual submission from
cssubmit in the usual way. You can apply for both prizes, but normally the prizes will be awarded to
different groups.
**All prizes are awarded or not solely at Lyndon's discretion. Late submissions will not be eligible for
prizes.

LC3 ASM

This assignment aims to give you some experience with C programming and to help you gain
better understanding of the addressing mode of LC-3.
Important Notes
? There are subtle differences between various C compilers. We will use the GNU compiler gcc
on login.cs.auckland.ac.nz for marking. Therefore, you MUST ensure that your submissions
compile and run on login.cs.auckland.ac.nz. Submissions that fail to compile or run on
login.cs.auckland.ac.nz will attract NO marks.
? Markers will compile your program using command “gcc –o name name.c” where name.c is
the name of the source code of your program, e.g. part1.c. That is, the markers will NOT use
any compiler switches to supress the warning messages.
? Markers will use machine code that is different from the examples given in the
specifications when testing your programs.
? The outputs of your programs will be checked by a program. Thus, your program’s outputs
MUST be in the same format as shown in the example given in each part. You must make
sure that the registers appear in the same order as shown in the example and there are no
extra lines.
In this assignment, you are required to write C programs to implement a LC-3 simulator. That is,
the programs will execute the binary code generated by LC-3 assembler.
Part 1 (28 marks)
LC3Edit is used to write LC-3 assembly programs. After a program is written, we use the LC-3
assembler (i.e. the “Translate ? Assemble” function in LC3Edit) to convert the assembly
program into binary executable. The binary executable being generated by LC3Edit is named
“file.obj” where “file” is the name of the assembly program (excluding the “.asm” suffix). In this
specification, a “word” refers to a word in LC-3. That is, a word consists of two bytes. The
structure of the “file.obj” is as below:
? The first word (i.e. the first two bytes) is the starting address of the program.
? The subsequent words correspond to the instructions in the assembly program and the
memory locations reserved for the program using various LC-3 directives.
? In LC-3, data are stored in Big-endian format (refer to
https://en.wikipedia.org/wiki/Endianness to learn more about Big-endian format). For
2
example, if byte 0x12 in word 0x1234 is stored at address 0x3000, byte 0x34 is stored at
address 0x3001. This means, when you read a sequence of bytes from the executable of
an LC-3 assembly program from a file, the most significant bit of each word is read first.
In this part of the assignment, you are required to write a C program to display each word in the
“.obj” file of a program in hexadecimal form.
? Name the C program as “part1.c”.
? The name of the “.obj” file (the name of the file INCLUDES the “.obj” suffix) must be
given as a command line argument.
? In the output, each line shows the contents of one word.
? The value of each word must have a “0x” prefix.
? The letter digits “a” to “f” must be shown as lowercase letters.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p1.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
LDI R2, C
AND R3, R0, R1
AND R3, R1, #0
NOT R4, R3
ADD R4, R4, #1
BRp F
ADD R3, R3, #1
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line argument is marked in red.
$ ./part1 p1.obj
0x4500
0x2009
0xe209
0xa409
0x5601
0x5660
0x98ff
0x1921
0x0201
0x16e1
0xf025
0x560a
0x4507
3
0x4501
Part 2 (46 marks)
In this part, you are required to write a C program to implement a LC-3 simulator that is capable
of executing instruction “LD”.
? Name the C program as “part2.c”.
? The name of the “.obj” file (the name of the file INCLUDES the “.obj” suffix) must be
given as a command line argument.
? The state of the simulator consists of the contents of the 8 general purpose registers (i.e.
R0 to R7), the value of the program counter (i.e. PC), the contents of the instruction
register (i.e. IR), and the value of the condition code (i.e. CC).
? The values in R0 to R7, PC and IR should be shown as hexadecimal value. The value of CC
is either N, Z or P.
? Before the simulator starts executing a program, it should first display the initial state of
the LC-3 machine. In the initial state, R0 to R7 and IR should all be 0; PC should be the
starting address of the program to be executed; and CC should be set to Z.
? When displaying the value of R0 to R7, PC, IR and CC, a tab character (denoted as “\t” in
C) is used to separate the name of the register and the value of the register.
? Each hexadecimal value must have a “0x” prefix. The letter digits “a” to “f” must be
shown as lowercase letters.
? After showing the initial state, the simulator should execute each instruction except the
“HALT” pseudo instruction in the “.obj” file. For this part, the simulator should display
the hexadecimal code of each LD instruction that has been executed and the state of the
LC-3 machine after each LD instruction is executed. The hexadecimal code of each LD
instruction should be preceded with “after executing instruction\t” (where \t denotes a
tab character) and “0x”.
? The simulator should output a line consisting of 18 “=” after displaying the state of the
LC-3 machine.
? When the execution reaches the “HALT” instruction, the simulator terminates.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p2.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line argument is marked in red.
4
$ ./part2 p2.obj
Initial state
R0 0x0000
R1 0x0000
R2 0x0000
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4500
IR 0x0000
CC Z
==================
after executing instruction 0x2001
R0 0x560a
R1 0x0000
R2 0x0000
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4501
IR 0x2001
CC P
==================
Part 3 (12 marks)
This part is based on Part 2.
? Name this program as part3.c
? Expand the functionality of the simulator in part 2 to allow the simulator to execute
instruction “LEA”.
? For this part, the simulator should display the hexadecimal code of each LEA instruction
that has been executed and the state of the LC-3 machine after each LEA instruction is
executed. The hexadecimal code of each LEA instruction should be preceded with “after
executing instruction\t” (where \t denotes a tab character) and “0x”.
? The simulator should output a line consisting of 18 “=” after displaying the state of the
LC-3 machine.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p3.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
5
The execution of the program is shown below. The command line argument is marked in red.
$ ./part3 p3.obj
after executing instruction 0xe202
R0 0x560a
R1 0x4504
R2 0x0000
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4502
IR 0xe202
CC P
==================
Part 4 (12 marks)
This part is based on Part 3.
? Name this program as part4.c
? Expand the functionality of the simulator in part 3 to allow the simulator to execute
instruction “LDI”.
? For this part, the simulator should display the hexadecimal code of each LDI instruction
that has been executed and the state of the LC-3 machine after each LDI instruction is
executed. The hexadecimal code of each LDI instruction should be preceded with “after
executing instruction\t” (where \t denotes a tab character) and “0x”.
? The simulator should output a line consisting of 18 “=” after displaying the state of the
LC-3 machine.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p4.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
LDI R2, C
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line arguments are marked in red.
$ ./part4 p4.obj
after executing instruction 0xa403
R0 0x560a
R1 0x4505
6
R2 0xe203
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4503
IR 0xa403
CC N
==================
Part 5 (24 marks)
This part is based on Part 4.
? Name this program as part5.c
? Expand the functionality of the simulator in part 4 to allow the simulator to execute
instruction “AND”.
? For this part, the simulator should display the hexadecimal code of each AND instruction
that has been executed and the state of the LC-3 machine after each AND instruction is
executed. The hexadecimal code of each AND instruction should be preceded with
“after executing instruction\t” (where \t denotes a tab character) and “0x”.
? The simulator should output a line consisting of 18 “=” after displaying the state of the
LC-3 machine.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p5.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
LDI R2, C
AND R3, R0, R1
AND R3, R1, #0
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line arguments are marked in red.
$ ./part5 p5.obj
after executing instruction 0x5601
R0 0x560a
R1 0x4507
R2 0xe205
R3 0x4402
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4504
7
IR 0x5601
CC P
==================
after executing instruction 0x5660
R0 0x560a
R1 0x4507
R2 0xe205
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4505
IR 0x5660
CC Z
==================
Part 6 (12 marks)
This part is based on Part 5.
? Name this program as part6.c
? Expand the functionality of the simulator in part 5 to allow the simulator to execute
instruction “NOT”.
? For this part, the simulator should display the hexadecimal code of each NOT instruction
that has been executed and the state of the LC-3 machine after each NOT instruction is
executed. The hexadecimal code of each NOT instruction should be preceded with
“after executing instruction\t” (where \t denotes a tab character) and “0x”.
? The simulator should output a line consisting of 18 “=” after displaying the state of the
LC-3 machine.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p6.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
LDI R2, C
AND R3, R0, R1
AND R3, R1, #0
NOT R4, R3
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line arguments are marked in red.
$ ./part6 p6.obj
after executing instruction 0x98ff
R0 0x560a
R1 0x4508
8
R2 0xe206
R3 0x0000
R4 0xffff
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4506
IR 0x98ff
CC N
==================
Part 7 (12 marks)
This part is based on Part 6.
? Name this program as part7.c
? Expand the functionality of the simulator in part 7 to allow the simulator to execute
instruction “ADD”.
? For this part, the simulator should display the hexadecimal code of each ADD instruction
that has been executed and the state of the LC-3 machine after each ADD instruction is
executed. The hexadecimal code of each ADD instruction should be preceded with
“after executing instruction\t” (where \t denotes a tab character) and “0x”.
? The simulator should output a line consisting of 18 “=” after displaying the state of the
LC-3 machine.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p7.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
LDI R2, C
AND R3, R0, R1
AND R3, R1, #0
NOT R4, R3
ADD R4, R4, #1
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line arguments are marked in red.
$ ./part7 p7.obj
after executing instruction 0x1921
R0 0x560a
R1 0x4509
R2 0xe207
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
9
R7 0x0000
PC 0x4507
IR 0x1921
CC Z
==================
Part 8 (12 marks)
This part is based on Part 7.
? Name this program as part8.c
? Expand the functionality of the simulator in part 7 to allow the simulator to execute
instruction “BR”.
? For this part, the simulator should display the hexadecimal code of each BR instruction
that has been executed and the state of the LC-3 machine after each BR instruction is
executed. The hexadecimal code of each BR instruction should be preceded with “after
executing instruction\t” (where \t denotes a tab character) and “0x”.
? The simulator should output a line consisting of 18 “=” after displaying the state of the
LC-3 machine.
Here is an example of the execution of the program. In this example, the LC-3 assembly program
is as below. The name of the executable of the assembly program is “p8a.obj” (markers will
probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
LDI R2, C
AND R3, R0, R1
AND R3, R1, #0
NOT R4, R3
ADD R4, R4, #1
BRp F
ADD R3, R3, #1
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line arguments are marked in red.
$ ./part8 p8a.obj
after executing instruction 0x0201
R0 0x560a
R1 0x450b
R2 0xe209
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
10
PC 0x4508
IR 0x0201
CC Z
==================
Here is another example of the execution of the program. In this example, the LC-3 assembly
program is as below. The name of the executable of the assembly program is “p8b.obj” (markers
will probably use a file with a different name and different contents).
.ORIG X4500
LD R0, A
LEA R1, B
LDI R2, C
AND R3, R0, R1
AND R3, R1, #0
NOT R4, R3
ADD R4, R4, #1
BRzp F
ADD R3, R3, #1
F HALT
A .FILL X560A
B .FILL X4507
C .FILL X4501
.END
The execution of the program is shown below. The command line arguments are marked in red.
$ ./part8 p8b.obj
after executing instruction 0x0601
R0 0x560a
R1 0x450b
R2 0xe209
R3 0x0000
R4 0x0000
R5 0x0000
R6 0x0000
R7 0x0000
PC 0x4509
IR 0x0601
CC Z
==================
Part 9 [5 marks]
The answer to this part should be saved in a PDF file named part9.pdf.
Which part of this assignment is the most difficult one for you? Briefly describe your
reasons.
Submission
1. You MUST thoroughly test your program on login.cs.auckland.ac.nz before submission.
Programs that cannot be compiled or run on login.cs.auckland.ac.nz will NOT get any
mark.
11
2. Use command “tar cvzf A2.tar.gz part1.c part2.c part3.c part4.c part5.c part6.c part7.c
part8.c” to pack the eight C programs to file A2.tar.gz. [Note: You MUST use the tar
command on login.cs.auckland.ac.nz to pack the files as files packed using tools on PC
cannot be unpacked on login.cs.auckland.ac.nz. You will NOT get any mark if your file
cannot be unpacked on login.cs.auckland.ac.nz.]
3. Submit A2.tar.gz and part9.pdf through Canvas. The markers will only mark your latest
submission. So, if you submit multiple times, the two files MUST be submitted together
as one submission even if you only make changes to one of the files in your later
submissions.
4. NO email submission will be accepted.
Resource
? The binary files used in the examples of the specifications are packed in file
A2Examples.tar.gz.
? The scripts used by the markers to check your programs’ outputs are also packed in
A2Examples.tar.gz. To ensure that the outputs of your programs conform to the required
output format, I STRONGLY suggest you use the scripts to check the outputs of your
programs when you use the examples in the specification to test your programs. If the
outputs and the format of the outputs are correct, you should see a “part X passes the test”
message. WHEN YOUR PROGRAMS ARE MARKED, OUTPUTS THAT DO NOT CONFORM TO
THE REQUIRED FORMAT WILL FAIL THE TEST AND WILL GET 0 FOR THE FAILED CASES.
? Follow the steps below to extract and to use the files in A2Examples.tar.gz
o Put A2Examples.tar.gz in the directory in which your programs are stored.
o Use command “tar xvf A2Examples.tar.gz” to unpack A2Examples.tar.gz. After
unpacking the file, the “.obj” files and the marking scripts should be extracted to the
same directory as your programs.
o Once you are satisfied with the outputs of your program, you can run the marking
scripts to check the outputs and the formats of the outputs of your programs using
the marking scripts. There is one marking script for each part. The marking script for
part 1 is “m1.bash”; the script for part 2 is “m2.bash”; and so on.
o To run a script, use command “./mX.bash” where X is a digit. For example, to run
the marking script for part 1, use command “./m1.bash”.
o The marking scripts only check the outputs of the programs for the examples given
in the specification.
? You should create more test cases to manually test your programs. The easiest way is to use
LC-3 assembler to generate the binary “.obj” file and upload the file to
login.cs.auckland.ac.nz for testing. You can use the official LC-3 simulator to check whether
the outputs of your programs are correct.

pencil game

Part A: MinMax Search and Alpha-Beta Pruning (10 points) [Must be handed in individually]

These are problems to work out on paper and hand it as a document HW10.txt. When you are asked to insert values into the tree, you may draw a diagram using "ASCII Art", or you may simply list the values in a breadth-first (level by level) transversal of the nodes in the diagram.

«12345678910»

Powered By Z-Blog 2.2 Prism Build 140101

QQ 2365427650