Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. .global main
  2.  
  3. main: @start of program
  4. ldr r0, =welcome
  5. bl printf
  6. b prompt
  7.  
  8. prompt: @prints message that asks user to input a number (1-5)
  9.  
  10. ldr r0, =decisionstring
  11. bl printf
  12.  
  13. ldr r0, =intInputPattern
  14. ldr r1, =decisionNum
  15. bl scanf
  16. ldr r2, =decisionNum
  17. ldr r5, [r2]
  18. push {r5} @pushes decision integer onto stack
  19. b decision
  20.  
  21.  
  22.  
  23.  
  24. decision: @subroutine that inputs numbers and branches to AND, ORR, EOR, or BIC based on user input
  25. pop {r10} @pops decision integer off of stack
  26. mov r1, r10
  27. ldr r0, =InputNumbers
  28. bl printf
  29.  
  30.  
  31. cmp r10, #1
  32. bleq inputHexNums
  33. temp5:bleq bitwiseAND
  34.  
  35. cmp r10, #2
  36. bleq inputHexNums
  37. bleq bitwiseORR
  38.  
  39. cmp r10, #3
  40. bleq inputHexNums
  41. bleq bitwiseEOR
  42.  
  43. cmp r10, #4
  44. bleq inputHexNums
  45. bleq bitwiseBIC
  46.  
  47. cmp r10, #5
  48. beq exit
  49.  
  50. b prompt @else, exit
  51.  
  52. errorSubroutine:
  53. ldr r0, =error
  54. bl printf
  55. b inputNumber
  56.  
  57. inputNumber:
  58. push {lr}
  59. ldr r0, =hexInputPattern
  60. ldr r1, =hexNum1
  61. bl scanf
  62. ldr r2, =hexNum1
  63. ldr r1, [r2]
  64. cmp r1, #0
  65. beq errorSubroutine
  66. pop {lr}
  67. push {r1}
  68. mov r7, #1
  69. cmp r7, #1
  70. mov pc, lr
  71.  
  72.  
  73. inputHexNums: @subroutine that inputs two hex numbers
  74. push {lr}
  75. bl inputNumber
  76. pop {r5}
  77. bl inputNumber
  78. pop {r6}
  79. pop {lr}
  80. temp1:push {r5}
  81. temp2:push {r6}
  82. mov pc, lr
  83.  
  84. bitwiseAND: @AND subroutine
  85. temp3:pop {r11}
  86. temp4:pop {r10}
  87. AND r12, r10, r11
  88. push {lr}
  89. ldr r0, =printnumber
  90. mov r1, r12
  91. bl printf
  92. pop {lr}
  93. mov pc, lr
  94.  
  95. bitwiseORR: @ORR subroutine
  96. pop {r11}
  97. pop {r10}
  98. ORR r12, r10, r11
  99. push {lr}
  100. ldr r0, =printnumber
  101. mov r1, r12
  102. bl printf
  103. pop {lr}
  104. mov pc, lr
  105.  
  106. bitwiseEOR: @EOR subroutine
  107. pop {r11}
  108. pop {r10}
  109. EOR r12, r10, r11
  110. push {lr}
  111. ldr r0, =printnumber
  112. mov r1, r12
  113. bl printf
  114. pop {lr}
  115. mov pc, lr
  116.  
  117. bitwiseBIC: @BIC subroutine
  118. pop {r11}
  119. pop {r10}
  120. BIC r12, r10, r11
  121. push {lr}
  122. ldr r0, =printnumber
  123. mov r1, r12
  124. bl printf
  125. pop {lr}
  126. mov pc, lr
  127.  
  128.  
  129. exit: @subroutine to exit program
  130. mov r7, #0x01
  131. SVC 0
  132.  
  133.  
  134. .data
  135.  
  136. .balign 4
  137. hexInputPattern: .asciz "%x"
  138.  
  139. .balign 4
  140. hexNum1: .word 0
  141.  
  142. .balign 4
  143. hexNum2: .word 0
  144.  
  145.  
  146. .balign 4
  147. intInputPattern: .asciz "%d"
  148.  
  149. .balign 4
  150. decisionNum: .word 0
  151.  
  152. .balign 4
  153. InputNumbers: .asciz "Now input two hex numbers\n"
  154.  
  155. .balign 4
  156. printnumber: .asciz "%x\n"
  157.  
  158. .balign 4
  159. decisionstring: .asciz "Enter (1) for AND, (2) for ORR, (3) for EOR, (4) for BIC, and (5) to exit\n"
  160.  
  161. .balign 4
  162. andstring: .asciz "You branched to AND\n"
  163.  
  164. .balign 4
  165. orrstring: .asciz "You branched to ORR\n"
  166.  
  167. .balign 4
  168. welcome: .asciz "Welcome to my binary calculator. This program can do 4 operations: AND, ORR, EOR, and BIC\n"
  169.  
  170. .balign 4
  171. error: .asciz "Invalid input.. please input 2 new hex numbers\n"
  172.  
  173. .global scanf
  174. .global printf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement