Question

Four Integer Stats Write an ARM Assembly Language (I will not accept Intel Assembly code) program...

Four Integer Stats

Write an ARM Assembly Language (I will not accept Intel Assembly code) program to prompt the user to enter four integers. Have your program output to the screen the four integers that were entered at the keyboard, along with the following: sum of the four integers, smallest value, largest value, and the average of the four values. You must utilize the scanf function for reading in the user input and the printf function for outputting the results to the screen.

Your Assembly Language Source File (.s extension)

Some example program executions:


Example 1:


Enter four integer values: 43 12 98 65

You entered 43, 12, 98, 65.

The smallest value is 12

The largest value is 98

The sum of all values is: 218

The average of the four values is: 54

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question:

Four Integer Stats

Write an ARM Assembly Language (I will not accept Intel Assembly code) program to prompt the user to enter four integers. Have your program output to the screen the four integers that were entered at the keyboard, along with the following: sum of the four integers, smallest value, largest value, and the average of the four values. You must utilize the scanf function for reading in the user input and the printf function for outputting the results to the screen.

Your Assembly Language Source File (.s extension)

Some example program executions:

Example 1:

Enter four integer values: 43 12 98 65

You entered 43, 12, 98, 65.

The smallest value is 12

The largest value is 98

The sum of all values is: 218

The average of the four values is: 54

Answer:

For the above problem Statement below is the C Code

=========================================

#include <stdio.h>

int main(void)
{
int num[4],max, min, j, sum=0, avg;
printf ("Enter four integer values: ");
for (j = 0; j < 4; j++)
scanf ("%d", &num[j]);

//print entered Elements
printf("You entered ");
for (j = 0; j < 4; j++)
{
printf("%d ", num[j]);

//find the sum of digits entered
sum += num[j];
}
printf("\n");

max = min = num[0];

for (j = 1; j < 4; j++)
{

//find minimum element using below formula
if (num[j] < min){
min = num[j];
}

//find maximum element using below formula
if (max < num[j]){
max = num[j];
}
}
//find average using below formula
avg = sum / 4;

printf("The smallest value is %d \n",min);
printf("The largest value is %d \n",max);
printf("The sum of all values is: %d \n",sum);
printf("The sum of all values is: %d \n",avg);
return 0;
}

=========================================

Compile and Execute the above C Code in g++/gcc compatible operating systems.

Validate and Verify the output results with different input values.

Sample Executed Output Result Could be like this as follows:

======================== Sample Output Start ================

Enter four integer values: 43 12 98 65                                                                                        

You entered 43 12 98 65                                                                                                       

The smallest value is 12                                                                                                      

The largest value is 98                                                                                                       

The sum of all values is: 218                                                                                                 

The sum of all values is: 54

======================== Sample Output End ================

Convert the above C Code to ARM Assembly Code with .s extension using gcc command

$ gcc -S filename.c

Above Command will generate filename.s , means C Code is converted into assembly code successfully.

Below is the ARM Assembly Language Code :

$ cat filename.s

.LC0:

.ascii "Enter four integer values: \000"

.LC1:

.ascii "%d\000"

.LC2:

.ascii "You entered \000"

.LC3:

.ascii "%d \000"

.LC4:

.ascii "The smallest value is %d \012\000"

.LC5:

.ascii "The largest value is %d \012\000"

.LC6:

.ascii "The sum of all values is: %d \012\000"

main:

push {fp, lr}

add fp, sp, #4

sub sp, sp, #40

mov r3, #0

str r3, [fp, #-20]

ldr r0, .L11

bl printf

mov r3, #0

str r3, [fp, #-16]

.L3:

ldr r3, [fp, #-16]

cmp r3, #3

bgt .L2

sub r2, fp, #40

ldr r3, [fp, #-16]

lsl r3, r3, #2

add r3, r2, r3

mov r1, r3

ldr r0, .L11+4

bl scanf

ldr r3, [fp, #-16]

add r3, r3, #1

str r3, [fp, #-16]

b .L3

.L2:

ldr r0, .L11+8

bl printf

mov r3, #0

str r3, [fp, #-16]

.L5:

ldr r3, [fp, #-16]

cmp r3, #3

bgt .L4

ldr r3, [fp, #-16]

lsl r3, r3, #2

sub r2, fp, #4

add r3, r2, r3

ldr r3, [r3, #-36]

mov r1, r3

ldr r0, .L11+12

bl printf

ldr r3, [fp, #-16]

lsl r3, r3, #2

sub r2, fp, #4

add r3, r2, r3

ldr r3, [r3, #-36]

ldr r2, [fp, #-20]

add r3, r2, r3

str r3, [fp, #-20]

ldr r3, [fp, #-16]

add r3, r3, #1

str r3, [fp, #-16]

b .L5

.L4:

mov r0, #10

bl putchar

ldr r3, [fp, #-40]

str r3, [fp, #-12]

ldr r3, [fp, #-12]

str r3, [fp, #-8]

mov r3, #1

str r3, [fp, #-16]

.L9:

ldr r3, [fp, #-16]

cmp r3, #3

bgt .L6

ldr r3, [fp, #-16]

lsl r3, r3, #2

sub r2, fp, #4

add r3, r2, r3

ldr r2, [r3, #-36]

ldr r3, [fp, #-12]

cmp r2, r3

bge .L7

ldr r3, [fp, #-16]

lsl r3, r3, #2

sub r2, fp, #4

add r3, r2, r3

ldr r3, [r3, #-36]

str r3, [fp, #-12]

.L7:

ldr r3, [fp, #-16]

lsl r3, r3, #2

sub r2, fp, #4

add r3, r2, r3

ldr r2, [r3, #-36]

ldr r3, [fp, #-8]

cmp r2, r3

ble .L8

ldr r3, [fp, #-16]

lsl r3, r3, #2

sub r2, fp, #4

add r3, r2, r3

ldr r3, [r3, #-36]

str r3, [fp, #-8]

.L8:

ldr r3, [fp, #-16]

add r3, r3, #1

str r3, [fp, #-16]

b .L9

.L6:

ldr r3, [fp, #-20]

add r2, r3, #3

cmp r3, #0

movlt r3, r2

movge r3, r3

asr r3, r3, #2

str r3, [fp, #-24]

ldr r1, [fp, #-12]

ldr r0, .L11+16

bl printf

ldr r1, [fp, #-8]

ldr r0, .L11+20

bl printf

ldr r1, [fp, #-20]

ldr r0, .L11+24

bl printf

ldr r1, [fp, #-24]

ldr r0, .L11+24

bl printf

mov r3, #0

mov r0, r3

sub sp, fp, #4

pop {fp, lr}

bx lr

.L11:

.word .LC0

.word .LC1

.word .LC2

.word .LC3

.word .LC4

.word .LC5

.word .LC6

==========================

Compile and execute the above ARM Code in proper compatible operating system, verify and validate the output results with different input values.

Add a comment
Know the answer?
Add Answer to:
Four Integer Stats Write an ARM Assembly Language (I will not accept Intel Assembly code) program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Finish the MARIE assembly language code below to determine the largest integer, the smallest integer, and...

    Finish the MARIE assembly language code below to determine the largest integer, the smallest integer, and the sum of integers for a sequence of 5 signed integers. The program already calculates the largest integer, just need it to calculate the smallest integer and the sum of the integers. The 5 integers should first be entered by the user via the input device. Your program is then assembled and run to determine the largest integer, the smallest integer, and the sum...

  • INTEL 80x86 ASSEMBLY LANGUAGE CODE Write a windows32 assembly language program that utilizes a recursive procedure....

    INTEL 80x86 ASSEMBLY LANGUAGE CODE Write a windows32 assembly language program that utilizes a recursive procedure. The main (_MainProc) procedure should: accept, from the user, a positive integer. Guard against non-positive integers being entered using a loop. call the sumseries sub-procedure using the cdecl protocol, receive the results of the sub-procedure, and display the results. The sumseries sub-procedure should: recursively find the sum of the series: 1*2 + 2*3 + 3*4 + ... + i*(i+1) (This is an iterative definition....

  • Write MARIE assembly language programs that do the following: I. Write a program that inputs thre...

    Write MARIE assembly language programs that do the following: I. Write a program that inputs three integers, a, b, and c, in that order. It computes the following ia-bi-fc+ c The result should be written to output 2. Write a program that inputs integers, s. y, and z. It outputs the difference of the langest and first element entered. You may assume x. y, and z all have different values. So if 8, 12, and 9 are input, the output...

  • Intel 80x86 microprocessors 1. (%25) Write an assembly language program which asks the user to enter...

    Intel 80x86 microprocessors 1. (%25) Write an assembly language program which asks the user to enter his/her name and surname through the keyboard. After the entry: The program clears the left top quarter of the screen and displays the name at the center of that quarter. Similarly the program clears the right bottom quarter of the screen and displays the surname at the center of that quarter. For example: If your name and surname are "Al and "Velir, the following...

  • Write a program that finds the largest and smallest of four integers entered by user. Enter...

    Write a program that finds the largest and smallest of four integers entered by user. Enter four integers: 21 43 10 35 Largest: 43 Smallest: 10 (Must be done in Code::Blocks C++)

  • Complete this task4.s ARM assembly code to produce an assembly program that: • Waits for the...

    Complete this task4.s ARM assembly code to produce an assembly program that: • Waits for the user to enter two integers (this part is already coded in). • Places the first integer at r5, and the second integer at r6 (this part is already coded in). • (This is what you need to code in) Adds the two integers together. If the result is between 0 and 9 (including 0 and 9) the program should print the result. If not,...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • Easy 68k code - assembly language Write a 68K program that reads two integers (>10 and...

    Easy 68k code - assembly language Write a 68K program that reads two integers (>10 and <225) of the keyboard, adds them together and multiplies them, writes the numbers and the results of addition and multiplication on the screen. If the numbers are not on the range, writes an error message and requests a new number. Example of the execution: Insert the first number: 10 Insert the second number:15 The sum is: 25 The product is: 150 Please take a...

  • C++ coding answer 5. Write a program that asks the user for a positive integer value....

    C++ coding answer 5. Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. Input Validation: Do not accept a negative starting number.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT