Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MIPS assembly language program, 3x+1problem.asm, to input apositive inte

ID: 671006 • Letter: W

Question

Write a MIPS assembly language program, 3x+1problem.asm, to input apositive integer from the keyboard and compute and print all theelements in the 3x+1 sequence through the first occurrence of thenumber 1.

Sample I/O.

Input positive integer: 3

3x+1 sequence: 3, 10, 5, 16, 8, 4, 2, 1

Input positive integer: 1

3x+1 sequence: 1

Input positive integer: 32

3x+1 sequence: 32, 16, 8, 4, 2, 1

Input positive integer:9

3x+1 sequence: 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1

USING MARS IED to write the code

Explanation / Answer

% ECLiPSe SAMPLE CODE % % A Magic Sequence of length n is a sequence of integers x0 .. xn-1 % such that for all i=0 .. n-1: % % * xi is an integer between 0 and n-1 % * the number i occurs exactly xi times in the sequence. % :- lib(ic). :- lib(ic_global). solve(N, Sequence) :- length(Sequence, N), % model from definition Sequence :: 0..N-1, ( for(I,0,N-1), foreach(Xi, Sequence), foreach(I, Integers), param(Sequence) do occurrences(I, Sequence, Xi) ), N #= sum(Sequence), % two redundant constraints N #= Sequence*Integers, search(Sequence, 0, first_fail, indomain, complete, [])

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote