In: Computer Science
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.
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