Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

LO2 Distinguish among three types of performance information.

Answered: 1 week ago