Question
Can you converty the C-style pseudocode into Assembly language please. Collatz Conjecture receives an 8-bit HEX number through command line parameter outputs a sequence of
Can you converty the C-style pseudocode into Assembly language please.
Collatz Conjecture receives an 8-bit HEX number through command line parameter outputs a sequence of numbers according to Collatz Conjecture
From https://en.wikipedia.org/wiki/Collatz_conjecture
The conjecture is that no matter what value of n, the sequence will always reach 1.
In modular arithmetic notation, define the function f as follows: f(n+1) = n/2, if n==0 (mod 2) f(n+1) = 3n+1, if n==1 (mod 2)
this corresponds to the following C style pseudocode: printf("number = %d ",number) while(number != 1) { step++ if(number % 2) number = 3*number + 1 else number /= 2 printf("number = %d ",number) } printf("Total Steps: %d ",steps)
where number = n and steps counts the number of steps for the sequence to converge to 1 ___________________________________________ Using the compilation command: nasm -f elf *.asm; ld -m elf_i386 -s -o demo *.o; demo 0x13
The following output should be produced BEGIN PROGRAM
number = 0x13
number = 0x3A
number = 0x1D
number = 0x58
number = 0x2C
number = 0x16
number = 0x0B
number = 0x22
number = 0x11
number = 0x34
number = 0x1A
number = 0x0D
number = 0x28
number = 0x14
number = 0x0A
number = 0x05
number = 0x10
number = 0x08
number = 0x04
number = 0x02
number = 0x01
Steps = 0x14
END PROGRAM
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started