Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question asks you to write programs in assembly language and Python. You are recommended to use no more than 350 words in your answer

image text in transcribed

image text in transcribed

This question asks you to write programs in assembly language and Python. You are recommended to use no more than 350 words in your answer to this question. Taxi fares are usually composed of two components, base fare (B) and a prevailing rate fare (P), which is multiplied by the total distance (D) travelled. The base fare is fixed at 3, while the prevailing rate varies depending on the time of the day. a. You are required to write a microprocessor program, which will take as inputs the prevailing rate (P) and the distance travelled (D), and output the total fare (T) for a given trip. The total fare (T) is given by, T = B + P* D. After calculating the total fare (T), the program should store the result in location 32 in memory and output it to a single output port. Write a program that would do this. You should use memory address 30 for temporary storage. You should use the assembly language instructions IN, MOV, ADD and OUT introduced in Book 3. You can assume that a first IN instruction will input the prevailing rate (P) and a further application of IN will input the distance travelled. You should also use the assembly language instruction for multiplication, which is MUL. For example, the instruction 'MUL 4', multiplies the content of the accumulator by 4 and stores the resulting value back in the accumulator, and 'MUL [30]' multiplies the contents of the accumulator by the contents of memory address 30. You should only use the IN, MOV, ADD, OUT and MUL instructions. Your answer should include your reasoning for the program you have written. (7 marks) b. In practice, the base fare (B) covers the first mile or less, and only the distance travelled after one mile is charged. For example, if the distance travelled is D = 6.5 miles, then the total fare is given as T = B + P* (6.5 - 1). Use Python to write a program to take as input the prevailing rate P and the distance travelled D, and output the total fare (T) for the given trip. For this program you should assume that the base fare (B) is 4.70. The program should check that the input value for the prevailing rate (P) is positive and, if not, give the error message 'The prevailing rate must be positive'. It should also check that the distance travelled (D) is positive and, if not, give the error message 'Distance travelled should be positive'. In both cases, the user should then be prompted to input the value again until it is positive. Create and test your program in the following Python environment. You may include comments in the program to make it clearer. Recall that you have to click the mouse in the right window before you can enter the numbers when the program is running. Remix main.py #!/bin/python3 1 3 4 # T212 TMAQ3 Question 11. # You can write your Python program here Interactive 3 The Python programming environment Run your program and paste a screenshot into your answer document. This should show the output beginning with you giving a non-positive value for the prevailing rate and a non-positive value for the distance travelled, to show that the input code is working correctly. The output should be the correct value of the fare in pounds, for a positive prevailing rate and a positive distance. (8 marks) This question asks you to write programs in assembly language and Python. You are recommended to use no more than 350 words in your answer to this question. Taxi fares are usually composed of two components, base fare (B) and a prevailing rate fare (P), which is multiplied by the total distance (D) travelled. The base fare is fixed at 3, while the prevailing rate varies depending on the time of the day. a. You are required to write a microprocessor program, which will take as inputs the prevailing rate (P) and the distance travelled (D), and output the total fare (T) for a given trip. The total fare (T) is given by, T = B + P* D. After calculating the total fare (T), the program should store the result in location 32 in memory and output it to a single output port. Write a program that would do this. You should use memory address 30 for temporary storage. You should use the assembly language instructions IN, MOV, ADD and OUT introduced in Book 3. You can assume that a first IN instruction will input the prevailing rate (P) and a further application of IN will input the distance travelled. You should also use the assembly language instruction for multiplication, which is MUL. For example, the instruction 'MUL 4', multiplies the content of the accumulator by 4 and stores the resulting value back in the accumulator, and 'MUL [30]' multiplies the contents of the accumulator by the contents of memory address 30. You should only use the IN, MOV, ADD, OUT and MUL instructions. Your answer should include your reasoning for the program you have written. (7 marks) b. In practice, the base fare (B) covers the first mile or less, and only the distance travelled after one mile is charged. For example, if the distance travelled is D = 6.5 miles, then the total fare is given as T = B + P* (6.5 - 1). Use Python to write a program to take as input the prevailing rate P and the distance travelled D, and output the total fare (T) for the given trip. For this program you should assume that the base fare (B) is 4.70. The program should check that the input value for the prevailing rate (P) is positive and, if not, give the error message 'The prevailing rate must be positive'. It should also check that the distance travelled (D) is positive and, if not, give the error message 'Distance travelled should be positive'. In both cases, the user should then be prompted to input the value again until it is positive. Create and test your program in the following Python environment. You may include comments in the program to make it clearer. Recall that you have to click the mouse in the right window before you can enter the numbers when the program is running. Remix main.py #!/bin/python3 1 3 4 # T212 TMAQ3 Question 11. # You can write your Python program here Interactive 3 The Python programming environment Run your program and paste a screenshot into your answer document. This should show the output beginning with you giving a non-positive value for the prevailing rate and a non-positive value for the distance travelled, to show that the input code is working correctly. The output should be the correct value of the fare in pounds, for a positive prevailing rate and a positive distance. (8 marks)

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

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

List situational factors that influence helping behavior.

Answered: 1 week ago