Question

In: Computer Science

Write a MARIE program that asks the user for a beginning and an ending address of...

Write a MARIE program that asks the user for a beginning and an ending address of an array in the memory and checks whether the sequence of integers in between these memory locations is a palindrome. Output 1 on the screen if you conclude it is a palindrome. Add comments to your program.

Solutions

Expert Solution

Input
Store X //input and store the beginning address of array in X
Input
Store Y //input and store the ending address of array in Y

Loop, LoadI X //Load the value at address X of array through indirect addressing mode in the accumulator(AC)
Store N   // store the value at address X in a variable N
LoadI Y       //Load the value at address Y of array through indirect addressing mode in the accumulator(AC)
Subt N       // subtract value at address X with value at address Y to check for palindrome
Skipcond 400   // if AC=0 then skip the next instruction else continue
Jump NegOP

Cond,  Load X //load Address X in AC
Add One       // increment the address by 1 for next index of array
Store X       // store in X after incrementing
Load Y       //load Address Y in AC
Subt One   // decrement the address by 1 for next index of array to check for palindrome
Store Y       //store in Y
Subt X       // checking the condition for arrray index out of bounds
Skipcond 800 // if AC>0 then skip next instruction and continue checking for the palindrome
Jump OP
Jump Loop

NegOP, Load Zero // loading zero in AC and printing to indicate that string is not a palindrome
Output
Halt
OP, Load One
Output
Halt
// local variable declarations
X, Dec 0
Y, Dec 0
N, Dec 0
One, Dec 1
Zero, Dec 0


Related Solutions

Write a program compare.cpp that asks the user to input two dates (the beginning and the...
Write a program compare.cpp that asks the user to input two dates (the beginning and the end of the interval). The program should check each day in the interval and report which basin had higher elevation on that day by printing “East” or “West”, or print “Equal” if both basins are at the same level. Example: $ ./compare Enter starting date: 09/13/2018 Enter ending date: 09/17/2018 09/13/2018 West 09/14/2018 West 09/15/2018 West 09/16/2018 West 09/17/2018 West Explanation: Date East (ft)...
Question 2. Write a MARIE program that accepts an integer from the user, and if it...
Question 2. Write a MARIE program that accepts an integer from the user, and if it is a prime number the program will output 1, otherwise, the program will output 0. Examples: If the user input is 17, the output would be 1 If the user input is 2, the output would be 1 If the user input is 15, the output would be 0 If the user input is -2, the output would be 0 You should write and...
Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write an Algorithm that asks the user to enter an address and print each part of...
Write an Algorithm that asks the user to enter an address and print each part of the address on a separate line. Example: Input 344 Rose Dr, Raeford, NC 28376 Output Street No.: 344 Street Name: Rose Dr City: Raeford State: North Carolina Zip Code: 28376 Hints: Deal with the address as a string. The address must contain two commas. The text before first comma contains the street number and street name separated by one or more white spaces. The...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a program that asks the user for the lengths of the sides of a rectangle....
Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem). This question should be...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a C ++ program that asks the user for the speed of a vehicle (in...
Write a C ++ program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled -------------------------------- 1           40 2           80...
IN PYTHON: Write a program that asks the user for a path to a directory, then...
IN PYTHON: Write a program that asks the user for a path to a directory, then updates the names of all the files in the directory that contain the word draft to instead say final      EX: "term paper (draft).txt" would be renamed "term paper (final).txt" BONUS (5pts): for any .txt file that your program changes the name of, have your program add a line of text that states "Edited on " followed by the current date to the end...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT