+1 (315) 557-6473 

Find Average Of 3 Numbers And To Convert Numeric Score To Letter Grade, For Raspberry PI ARM Assembly Language Assignment Solution.


Instructions

Objective
Write an ARM program Convert miles to kilometres in ARM assembly language.

Requirements and Specifications

  1. Write and test a function to check if a user input value is a character or not. Implement it in two ways:
    • As a logical variable.
    • Any way that does not use logical values.
  2. Implement a grading program as follows. It should follow the proper style for assembly.
    • Prompt for a name and an average.
    • If the average is <0 or >100, print an error
    • Else calculate a grade as 90-100 as A, 80-90 as B, 70-80 as C, else F.
    • Print out the student's name and grade.
  3. Implement a function to find the largest of 3 values. The function signature is "findMaxOf3(int val1, int val2, int val3)". The function should compare the 3 values, and return the largest. Be sure to use the ABI standards for all arguments and return values. Write a program to prompt for 3 values, call this function to the find the maximum value, and print out the maximum value. Follow proper style for assembly.
  4. In ARM assembly, should work with raspberrypi.

Screenshots of output
find average of 3 numbers and convert numeric score to letter grade for Raspberry PI
find average of 3 numbers and convert numeric score to letter grade for Raspberry PI 1
find average of 3 numbers and convert numeric score to letter grade for Raspberry PI 2
Source Code
Program 1
       .cpu cortex-a53
        .data
prompt: .asciz "Input?: "
result1: .asciz "First Function result: "
result2: .asciz "Second Function result: "
chary: .asciz "It's a char\n"
charn: .asciz "It's not a char\n"
format: .asciz "%c"
input: .space 4 @ space to save input
        .text
        .global main
main:
        PUSH {fp, lr} @ save fp and lr on stack
        LDR r0, =prompt @ load address of prompt
        BL printf @ print prompt
        LDR r0, =format @ use format to read a char
        LDR r1, =input @ save in input variable
        BL scanf @ read input
        LDR r1, =input @ load input variable address
        LDRB r4, [r1] @ load input and save in R4
        LDR r0, =result1 @ load address of first result
        BL printf @ print message
        MOV r0, r4 @ call first function using input
        BL isChar1 @ see if it's char
        CMP r0, #0 @ check if return value was 0
        BEQ notChar1 @ if zero, go to is not char
        LDR r0, =chary @ else, load address of char
        BL printf @ print it's a char
        B test2 @ go to test second function
notChar1:
        LDR r0, =charn @ load address of not char
        BL printf @ print is not a char
test2:
        LDR r0, =result2 @ load address of second result
        BL printf @ print message
        MOV r0, r4 @ call second function using input
        BL isChar2 @ see if it's char
        CMP r0, #0 @ check if return value was < 0
        BLT notChar2 @ if <0, go to is not char
        LDR r0, =chary @ else, load address of char
        BL printf @ print it's a char
        B exit @ go to end
notChar2:
        LDR r0, =charn @ load address of not char
        BL printf @ print is not a char
exit:
        POP {fp, lr} @ restore registers from stack
        BX lr @ return to os
@ Function to check if the given input is a character
@ Receives R0 = input
@ returns R0 = 1 if true, 0 if false
isChar1:
        MOV r1, #0 @ by default assume not a char
        CMP r0, #'A' @ compare with 'A'
        BLT ret1 @ if < 'A', it's not a char, return
        CMP r0, #'Z' @ compare with 'Z'
        BLE char1 @ if <= 'Z', it's a char, return success
        CMP r0, #'a' @ compare with 'a'
        BLT ret1 @ if < 'a', it's not a char, return
        CMP r0, #'z' @ compare with 'z'
        BGT ret1 @ if > 'z', it's not a char, return
char1:
        MOV r1, #1 @ it's a char, return 1
ret1:
        MOV r0, r1 @ put return value in r0
        BX lr
@ Function to check if the given input is a character
@ Receives R0 = input
@ returns R0 >= 0 if is char, R0 < 0 if is not a char
isChar2:
        SUBS r0, r0, #'A' @ subtract A
        BLT ret2 @ if negative, end
        MOV r1, #25 @ load 25
        SUBS r0, r1, r0 @ subtract result from 25
        BGE ret2 @ if positive, it's a char
        MOV r1, #-7 @ load -7
        SUBS r0, r1, r0 @ subtract a
        BLT ret2 @ if negative, end
        MOV r1, #25 @ load 25
        SUB r0, r1, r0 @ subtract result from 25
                            @ if positive, it's a char
ret2:
        BX lr
Program 2
       .cpu cortex-a53
        .data
prompt_name: .asciz "Please enter a name: "
prompt_avg: .asciz "Please enter the average: "
avg_error: .asciz "Error, average must be between 0 and 100.\n"
result: .asciz "Student: %s, Grade: %c\n"
format_name: .asciz "%s"
format_avg: .asciz "%d"
avg: .space 4 @ space to save average
name: .space 32 @ space to save name
        .text
        .global main
main:
        PUSH {fp, lr} @ save fp and lr on stack
        LDR r0, =prompt_name @ load address of prompt
        BL printf @ print prompt for a name
        LDR r0, =format_name @ load format of name
        LDR r1, =name @ load address of name
        BL scanf @ read name
        LDR r0, =prompt_avg @ load address of prompt
        BL printf @ print prompt for a name
        LDR r0, =format_avg @ load format of average
        LDR r1, =avg @ load address of average
        BL scanf @ read average
        LDR r1, =avg @ load address of average
        LDR r0, [r1] @ load average
        CMP r0, #0 @ compare with average with zero
        BLT error @ if avg < 0, it's an error
        CMP r0, #100 @ compare with average with 100
        BGT error @ if avg > 100, it's an error
        CMP r0, #90 @ compare average with 90
        BGE is_A @ if >= 90, it's an A
        CMP r0, #80 @ compare average with 80
        BGE is_B @ if >= 80, it's a B
        CMP r0, #70 @ compare average with 70
        BGE is_C @ if >= 70, it's a C
is_F: @ otherwise it's a F
        MOV r2, #'F' @ save F to print it
        B print @ go to print result
is_A: @ otherwise it's a F
        MOV r2, #'A' @ save A to print it
        B print @ go to print result
is_B: @ otherwise it's a F
        MOV r2, #'B' @ save B to print it
        B print @ go to print result
is_C: @ otherwise it's a F
        MOV r2, #'C' @ save C to print it
print:
        LDR r0, =result @ load result message
        LDR r1, =name @ load address of name
        BL printf @ print name and grade
        B exit @ terminate program
error:
        LDR r0, =avg_error @ load address of error message
        BL printf @ print error message
exit:
        POP {fp, lr} @ restore registers from stack
        BX lr @ return to os
Program 3
       .cpu cortex-a53
        .data
prompt1: .asciz "Please enter first value: "
prompt2: .asciz "Please enter second value: "
prompt3: .asciz "Please enter third value: "
result: .asciz "Maximum value is: %d\n"
format: .asciz "%d"
val1: .word 0
val2: .word 0
val3: .word 0
        .text
        .global main
main:
        PUSH {fp, lr} @ save fp and lr on stack
        LDR r0, =prompt1 @ load address of prompt
        BL printf @ print prompt for first val
        LDR r0, =format @ load format of number
        LDR r1, =val1 @ load address of first value
        BL scanf @ read value
        LDR r0, =prompt2 @ load address of prompt
        BL printf @ print prompt for second val
        LDR r0, =format @ load format of number
        LDR r1, =val2 @ load address of second value
        BL scanf @ read value
        LDR r0, =prompt3 @ load address of prompt
        BL printf @ print prompt for third val
        LDR r0, =format @ load format of number
        LDR r1, =val3 @ load address of third value
        BL scanf @ read value
        LDR r0, =val1 @ load address of first value
        LDR r0, [r0] @ load value1
        LDR r1, =val2 @ load address of second value
        LDR r1, [r1] @ load value2
        LDR r2, =val3 @ load address of third value
        LDR r2, [r2] @ load value3
        BL findMaxOf3 @ find the maximum
        MOV r1, r0 @ copy result to r1 to print it
        LDR r0, =result @ load address of result
        BL printf @ print max result
exit:
        POP {fp, lr} @ restore registers from stack
        BX lr @ return to os
@ Function that determines the max of 3 values
@ Receives R0 = first value
@ R1 = second value
@ R2 = third value
@ returns R0 = max of the 3 values
findMaxOf3:
        CMP R0, R1 @ compare first with second
        BGT comp3 @ if first > second, compare with third
        MOV R0, R1 @ else, second is greater, save in R0 for next comparison
comp3:
        CMP R0, R2 @ compare value with third
        BGT retmax @ if value > third, it's the max
        MOV R0, R2 @ else, third is the max, save in R0 for returning it
retmax:
        BX lr @ return to caller