Advertisement
Guest User

four integer stats

a guest
Oct 17th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. .global main
  2.  
  3. .align 4
  4. .section .rodata
  5. prompt: .asciz "Enter four integer values\n"
  6. input_str: .asciz "You entered %d %d %d $d\n"
  7. smallest_value_str: .asciz "The smallest value is %d\n"
  8. largest_value_str: .asciz "The largest value is %d\n"
  9. sum_str: .asciz "The sum of all values is: %d\n"
  10. average_str: .asciz "THe average of all four values is: %d\n"
  11. format: .string "%d"
  12.  
  13. .align 4
  14. .data
  15. a: .word 1
  16. b: .word 1
  17. c: .word 1
  18. d: .word 1
  19.  
  20.  
  21. .align 4
  22. .text
  23. main: push {lr}
  24.  
  25. ldr r0, =prompt //output prompt message
  26. bl printf
  27.  
  28. // Inputting numbers
  29. ldr r0, =format
  30. ldr r1, =a
  31. bl scanf
  32. mov r5, r1
  33.  
  34. ldr r0, =format
  35. ldr r1, =b
  36. bl scanf
  37. mov r6, r1
  38.  
  39. ldr r0, =format
  40. ldr r1, =b
  41. bl scanf
  42. mov r7, r1
  43.  
  44. ldr r0, =format
  45. ldr r1, =c
  46. bl scanf
  47. mov r8. r1
  48.  
  49. // print message for entered numbers
  50. ldr r0, =input_str
  51. mov r1, r5
  52. mov r2, r6
  53. mov r3, r7
  54. mov r4, r8
  55.  
  56. // Finding the smallest value
  57.  
  58. mov r9, r5
  59. cmp r9, r6
  60. bgt first_small
  61. b second_small
  62. first_small:
  63. mov r9, r6
  64. second_small:
  65. cmp r9. r7
  66. bgt third_small
  67. b fourth_small
  68. third_small:
  69. mov r9. r7
  70. fourth_small:
  71. cmp r9, r8
  72. bgt fifth_small
  73. b smallest_output
  74. fifth_small:
  75. mov r9, r8
  76. smallest_output:
  77. ldr r0, =smallest_value_str
  78. mov r1, r9
  79. bl printf
  80.  
  81. // Finding the largest value
  82. mov r10, r5
  83. cmp r10, r6
  84. blt first_large
  85. b second_large
  86.  
  87. first_large:
  88. mov r10, r6
  89. second_large:
  90. cmp r10, r7
  91. blt third_large
  92. b fourth_large
  93. third_large:
  94. mov r10, r7
  95. fourth_large:
  96. cmp r10, r8
  97. blt fifth_large
  98. b largest_output
  99. fifth_large:
  100. mov r10, r8
  101. largest_output:
  102. ldr r0, =largest_value_str
  103. mov r1, r10
  104. bl printf
  105.  
  106. // Finding the sum of all values
  107. mov r11, r5
  108. add r11, r11, r6
  109. add r11, r11, r7
  110. add r11, r11, r8
  111.  
  112. ldr r0, =sum_str
  113. mov r1, r11
  114. bl printf
  115.  
  116. // Finding the average of all values
  117. ldr r12, [r11]
  118. lsl r12, r12, #2
  119.  
  120. ldr r0, =average_str
  121. mov r1, r12
  122. bl printf
  123.  
  124. mov r0, #0
  125. pop {pc}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement