Question: For this program, you will use the wo tables given at the end of description (Table 1 and Table 2). Write a program according to

  1. For this program, you will use the wo tables given at the end of description (Table 1 and Table 2). Write a program according to the following specifications(To be done in Python). [4.0 marks]

In the main function of the program, ask the user to enter a string, pass that string to a function called TrimSpacesAndComments. This function removes the comments and all the leading and trailing white spaces and returns back the pure code string.

For example if user enters M=M+1 // comments then it should return M=M+1

Next pass this pure code string to a function called ConvertToMachineCode, this function should:

  • Print the type of the instruction A or C (an instruction starting with @ is A instruction, otherwise it is a C instruction)
  • If the instruction is one of the instructions from Table 2 then this function should also print its binary value. For Example:

A=D+1: C Instruction: 1100110011001100

The Program should accept the stings in a loop and should only exit if user enters string Exit (ignoring the case).

Use if-else statements (nested/elif etc) to do the conversion to binary code. You have to handle only the five strings given in the table below.

Table 1

@20 \\ memory value

A=D+1 \\ next memory value

D+1; JGT

M=D+1;JLT \\ do the jump

@240 \\ stack pointer

Table 2

@20

0000000000010100

A=D+1

1100110011001100

D+1; JGT

1010101010101010

M=D+1;JLT

1001001001001000

@240

0000000011110000

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!