XML

CO5570 Anonymous Questions and Answers

This page lists the various questions and answers. To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course.


Question 29:

Submission reference: IN3403

Not related to the assignment but when will we get any of our marks for the in class tests or A3?

Answer 29:

The A3 marks should be available within the next week. You will need to ask Mark about the ICTs.

Keywords: assign3


Question 28:

Submission reference: IN3394

my parser outputs this the n testing it with example.dsl: The first token is: KEYWORD INT ok ok is this compleatly incorrect? I have restarted multiple times and have always ended up with this output

Answer 28:

If you have completed the assignment, then it should just print "ok" as in the spec. Just delete the other output that I put in the starter code.

Keywords: assign4


Question 27:

Submission reference: IN3391

when I run the assignment4 code with the example.dsl the outputs are The first token is: KEYWORD INT OK. Is it the right output?

Answer 27:

It depends what you mean. If you are parsing the whole of the example.dsl file then the output should just be ok. There should not be any other debugging info printed. If you haven't implemented anything yet then the output will be

The first token is: KEYWORD INT
error

Keywords: assign4


Question 26:

Submission reference: IN3381

assignment ::=	IDENTIFIER ':=' expression ;
what exactly does this statement mean ? IDENTIFIER ':=' expression ; this is clear and is equivalent to N1 := 6; but i'm confused with assignment ::= IDENTIFIER

Answer 26:

The rule means that an assignment (statement) is defined as consisting of an IDENTIFIER (e.g., sum, price, x, etc.) followed by ':=' (an assignment symbol, like '=' in Java) followed by an expression, where expression is defined later in the grammar.

In terms of writing a parser for it, just follow the rules outlined in the parsing lecture/slides: check that the current token is an identifier, then check that the next token is the assignment symbol, then check that what follows is an expression (by calling the parseExpression) method.

Keywords: assign4


Question 25:

Submission reference: IN3379

What is the difference between these symbols := ::=

Answer 25:

The spec say, The notation ::= means 'is defined as'. It is part of the grammar notation. The spec also says:

In the grammar be careful to distinguish between those characters not enclosed between single-quote characters (e.g., ::= and ;) and those that look similar but are enclosed (e.g., ':=' and ';').
So, in the following:
assignment ::=	IDENTIFIER ':=' expression ;
:= is a symbol found in the input.

Keywords: assign4


Question 24:

Submission reference: IN3377

I'm following the suggested implementation steps in the spec.I was just wondering whether in step 4 we are meant to create a new method or should that be implemented in parsedeclaration as I'm confused

Answer 24:

In the parseDeclaration method, when you have IDENTIFIER as a token you should then access the symbol table. Check first whether there is already an entry for it. If there is, then that is an error. If there isn't then add it to the table.

Keywords: assign4


Question 23:

Submission reference: IN3375

how would i know if a symbol is a comma or semicolon and I cant use strings?

Answer 23:

I am not sure what, 'I cant use strings' means but if you know that a token is a SYMBOL you can call the getSymbol method of the Tokenizer and check whether the symbol is ";" or ",".

Keywords: assign4


Question 22:

Submission reference: IN3371

what should the output be to the example dsl file you have provided?

Answer 22:

It's a valid program, so the output should be:

ok

Keywords: assign4


Question 21:

Submission reference: IN3361

For A4 what java files provided do we actually need to modify? is it just the parser or do we need to modify the other java files

Answer 21:

You should only need to add code to the Parser class, but feel free to modify the others if you feel you need to, or add additional classes similarly.

Keywords: assign4


Question 20:

Submission reference: IN3360

When i translate instructions which include 3 parts(one opcode, one reg, one number), my reg translations occur at the end of the translation of the 8 bit string for some reason, while the padding is inbetween the opcode and reg. For example, JGT A,4 JLT D,39 translate to

>
01010001
00000100
01100010
00100111


code deleted

Answer 20:

You cannot assume that every instruction can be handled in the same way. Look at the encoding of each in the spec and group together the translations of those with similar structure.

The obvious conclusion is that you must be outputting the padding before the register encoding, which is clear from the order in which you do things in the method. So the solution is to print the register encoding before the padding for the instructions in which it is currently wrong.

Keywords: assign3


Question 19:

Submission reference: IN3358

when i run my program on raptor command line with java Main prog.mal it works fine, but when i use java -cp . Main prog.mal like it says on the brief, i get the error Unrecognized option: -cp. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Is this fine as my program still runs.

Answer 19:

If your program runs and gives the correct answers that's fine; I will figure it out when marking.


Question 18:

Submission reference: IN3357

Submission reference: IN3355 Im not entirely sure where to be moving/removing the output.println(). Ive tried removing them from

code deleted
and also adding output.println() to below this snippet like this.
code deleted
but neither works. Is it more than just moving the output.println(), or am i placing it in the wrong spots?

Answer 18:

It's about recognising that some instructions require two 8-bit outputs and so the 4-bits of opcode for the first of the pair need padding out with zeros to 8 bits. You have to do that for some instructions and not others. You can tell which you need to do it for from the assignment brief.

Keywords: assign3


Question 17:

Submission reference: IN3356

Cant find the MAL Spec, I had the MAL spec on my laptop however as im on another desktop right now i tried to retrieve the spec but couldnt

Answer 17:

It is on the Moodle page in the assignment brief.


Question 16:

Submission reference: IN3355

Ive got just one problem, my assembler correctly translates, except for ensuring that for instructions that include numbers, the opcodes and reg part of the translation doesnt correctly translate to 8 bit string. It only translates the opcode and reg but doesnt pad the rest of the string with 0s if it needs to. For example the instructions, JEQ A,125 and JMP 16, translate to

011101
01111101
0100
00010000
code deleted

Answer 16:

It's because you call output.println before adding the padding:

if (segment.length > 1) {
    if (isNumeric(segment[1])) {
	output.println();

Question 15:

Submission reference: IN3353

Apologies, here is the code:

code deleted
Could you tell me why the first line still produces a 16 character long line except for all other opcodes.

Answer 15:

It is simply that you have concatenated the binaryOpcode string and binaryOperand string together without a newline between them:

String binaryInstruction = binaryOpcode + binaryOperand;

Keywords: assign3


Question 14:

Submission reference: IN3352

When the program is ran, the translation of the first line is always 16 characters long but the other opcodes are translated in 8 characters, how can I fix the first line issue.

Answer 14:

Add some debugging information to your code. I have no way of knowing why this is without seeing your code, but you should be able to work the problem out by looking at what the first instruction is in the input file and then tracing how that is translated in your code.

Keywords: assign3


Question 13:

Submission reference: IN3351

my assembler can correctly translate numeric constants, but only if the constant is the fourth word in the instruction. How can I change my code so that it can also translate when the numeric constant is the second or third word in the instruction? For example, I can successfully translate instructions like ADD A D 5, and JLT D,A 39, but not LOADN 127 or JEQ A,125.

code deleted

Answer 13:

Don't try to translate all instructions in the same way. Have separate cases for the instructions that take either one or two operands.

Keywords: assign3


Question 12:

Submission reference: IN3350

Regarding Question 10 (2023), i have created the following code, but it is not working at all. For example when trying to translate LOADN 127, all it does it translate 0000

code deleted

Answer 12:

I suggest that you add some further debugging to your code to make sure that: a) that piece of code is being executed; and b) what the values of the number and numericConstant variables are. I suspect they are not what you think they are.


Question 11:

Submission reference: IN3349

Does the Main.java file need to be edited or is it just the Assembler.java. I'm not to sure if the Main.java has to call the Assembler.

Answer 11:

The Main class already calls the Assembler. You don't need to change anything in Main.

Keywords: assign3


Question 10:

Submission reference: IN3348

I have managed to get my assembler working for translating opcodes and regs, but I'm unsure of how to handle numeric constants for my code.

code deleted

Answer 10:

Try a Google search for 'java convert int to binary string with leading zeros'

Keywords: assign3

Referrers: Question 12 (2023)

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Tue Jan 23 16:52:10 2024
This document is maintained by David Barnes, to whom any comments and corrections should be addressed.