Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem: Write a Nios II program that converts an n-digit decimal integer into a binary Example B.12 number. The decimal number is given as n
Problem: Write a Nios II program that converts an n-digit decimal integer into a binary Example B.12 number. The decimal number is given as n ASCII-encoded characters, as would be the case if the number is entered by typing it on a keyboard Solution: Consider a four-digit decimal number, D-dzd2dido. The value of this number is ((d3 x 10+d2) x 10 + di) x 10 + do. This representation of the number is the basis for the conversion technique used in the program in Figure B.17. Note that each ASCII- encoded character is converted into a Binary Coded Decimal (BCD) digit before it is used in the computation. /* r2 is a counter, initialize movia ldw movia add r2, N r2, (r2) r3, DECIMAL r4, r0, r0 with s/ /* r3 points to the ASCII digits. /** r4 will hold the binary number. */ /* Get the next ASCII digit. /* Form the BCD digit. / Add to the intermediate result. */ /* Increment the digit pointer. /* Decrement the counter. LOOP: dbr5. (r3) andi add addi subi be muli br movia stw r5, r5, OxOF r4, r4, r5 r3. r3. 1 r2, r2. 1 r2, r0, DONE r4, r4, 10 LOOP r5, BINARY/* Store the result in r4. (r5) /* Multiply by 10 /* Loop back if not done. DONE: memory location BINARY. *
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