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

Write a WinMIPS64 code to determine whether a given number is an Armstrong numbe

ID: 2080757 • Letter: W

Question

Write a WinMIPS64 code to determine whether a given number is an Armstrong number. The n-digit numbers equal to sum of nth powers of their digits (a finite sequence), called Armstrong numbers. They first few are given by 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748,….

For example, consider 371, 371 = 33 + 73+ 13 = 27 + 343 + 1 = 371. A sample C code for your assistance is given below:

#include <stdio.h>

#include <math.h>

int main(){

int num,i;

int digit,sum,capture;

sum = 0.0;

capture = 0.0;

printf( "Enter the total number of digits " );

scanf( "%d", &num );

for( i = 0; i < num; i++ ) {

        printf( "Enter the %d digit: ", i+1 );

        scanf( "%d", &digit );

        sum = sum + pow(digit,num);

        capture = capture * 10 + digit;

}

printf( "Entered Number: %d ", capture );

printf( "Sum of Product: %d ", sum );

if( capture == sum )

        printf( "Armstrong number" );

else

        printf( "Not an Armstrong number" );

}

All examples can be used for manipulation. Note that the numbers displayed are in floating point. Display the numbers using double format in WinMIPS64. You need to test the code only for 1-4 digit numbers from 0 to 9999. It is sufficient to follow the mentioned C logic that checks for 4-digit Armstrong numbers, even though more digits can be specified. Provide a complete report of your code i.e. stall count, code size, CPI.

Write a WinMIPS64 code to determine whether a given number is an Armstrong number. The digit numbers equal to sum of nth powers of their digits (a finite sequence), called Armstrong numbers. They first few are given by 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748,.... For example, consider 371, 371 33 73+ 13 27 343 1 371. A sample C code for your assistance is given below: include

Explanation / Answer

# inputs # r0 - number # # outputs # r0 - armstrong number # # local r4, r5, r6, r7, r8 .equ ten,10 .equ hundred,100 .equ thousand,1000 .equ ten_thousand,10000 number .req r4 width .req r5 digit .req r6 current .req r7 armstrong .req r8 .macro armstrong_digit a, b ldr current, = mov digit, #0 _start@: cmp number, current blt _end@ teq width, #0 @ and only set width if it is currently unset moveq width, # add current, current, # add digit, digit, #1 b _start@ _end@: add number, number, # sub number, number, current mov r0, digit mov r1, width bl _power add armstrong, r0, armstrong .endm .globl _armstrong .align 2 .text _armstrong: nop stmfd sp!, {r4, r5, r6, r7, r8, lr} @ save variables to stack mov number, r0 @ copy passed parameter to working number cmp number, #ten @ exit unless number > 10 blt _end ldr current, =ten_thousand @ exit unless number < 10000 cmp number, current bge _end mov width, #0 @ initialise mov armstrong, #0 armstrong_digit thousand 4 armstrong_digit hundred 3 armstrong_digit ten 2 mov r0, number @ then add in the trailing digits mov r1, width bl _power add armstrong, r0, armstrong mov r0, armstrong @ and copy the armstrong number back to r0 for return _end: ldmfd sp!, {r4, r5, r6, r7, r8, pc} @ restore state from stack and leave subroutine
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