Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 6.00 KB | None | 0 0
  1. .global isNumber
  2. .data
  3. .text
  4. isNumber:
  5. mov   r12,r13           // save stack pointer into register r12
  6. sub   sp,#32            // reserve 32 bytes of space for local variables
  7. push  {lr}              // push link register onto stack -- make sure you pop it out before you return
  8.  
  9.                         // char c is stored in R2
  10.                         // ASCII digits are stored in decimal values 48-57
  11.  
  12.                         // We will first check to see if R2 is equal to or greater than 48
  13.                         // If the first check is passed, we will then check to see if R0 is
  14.                         // less than or equal to 57
  15. checkOne:               // If both checks are passed, c is a digit
  16. CMP R2, #48             // Compare R2 and 48
  17. BGE checkTwo            // If R2 is greater than or equal to 48, continue to check two
  18. B isNotDigit            // Else c is not a digit
  19.  
  20. checkTwo:
  21. CMP R2, #57             // Compare R2 and 57
  22. BLE isDigit             // If R2 is less than or equal to 57, c is a digit
  23. B isNotDigit            // Else c is not a digit
  24.  
  25. isDigit:
  26. mov R0, #1              // Sets return value to 1 because c is a digit
  27. b isNumberExit          // Jumps to end of function
  28.  
  29. isNotDigit:
  30. mov R0, #0              // Sets return value to 0 because c is not a digit
  31. b isNumberExit          // Jumps to end of function
  32.  
  33. isNumberExit:
  34. pop {lr}                // pop link register from stack
  35. mov sp,r12              // restore the stack pointer -- Please note stack pointer should be equal to the
  36.                         // value it had when you entered the function .  
  37. mov pc,lr               // return from the function by copying link register into  program counter
  38.  
  39.  
  40.  
  41. .global compare
  42. .data
  43. .text
  44. compare:
  45. mov   r12,r13           // save stack pointer into register r12
  46. sub   sp,#32            // reserve 32 bytes of space for local variables
  47. push  {lr}              // push link register onto stack -- make sure you pop it out before you return
  48.  
  49.                         // int a stored in R0
  50.                         // int b stored in R1
  51. CMP R0, R1              // Compares a and b
  52.  
  53. BGT greaterThan         // Jumps to greaterThan branch if R0>R1
  54. BEQ equalTo             // Jumps to equalTo branch if R0=R1
  55. BLT lessThan            // Jumps to lessThan branch if R0<R1
  56.  
  57.  
  58. greaterThan:
  59. MOV R0, #1              // Sets return value to 1 if R0>R1
  60. b compareExit           // Jumps to end of function
  61.  
  62. equalTo:
  63. MOV R0, #0              // Sets return value to 0 if R0=R1
  64. b compareExit           // Jumps to end of function
  65.  
  66. lessThan:
  67. MOV R0, #-1             // Sets return value to -1 if R0<R1
  68. b compareExit           // Jumps to end of function
  69.  
  70. compareExit:
  71. pop {lr}                // pop link register from stack
  72. mov sp,r12              // restore the stack pointer -- Please note stack pointer should be equal to the
  73.                         // value it had when you entered the function .  
  74. mov pc,lr               // return from the function by copying link register into  program counter
  75.  
  76.  
  77. .global countOnes
  78. .data
  79. .text
  80. countOnes:
  81. mov   r12,r13           // save stack pointer into register r12
  82. sub   sp,#32            // reserve 32 bytes of space for local variables
  83. push  {lr}              // push link register onto stack -- make sure you pop it out before you return
  84.  
  85.                         // int number stored in R0
  86. MOV R1, #0              // loopCount stored in R1
  87. MOV R2, #0              // onesCount stored in R2
  88. MOV R3, #0              // tempVal stored in R3
  89.  
  90. countOnesLoop:
  91. CMP R1, #32             // Compare R1 and 32
  92. BGE exitCountOnes       // Exit if loopCount>32
  93.  
  94. MOV R3, R0              // Copy R0 into R3 so we can AND it
  95. AND R3, #1              // And R3 with 1 to see if bit is 1 or 0
  96. ADD R2, R3              // Add bit, either one or zero, to onesCount
  97. LSR R0, #1              // Shift R0 right 1
  98.  
  99. ADD R1, #1              // Increment loopCount by 1
  100. b countOnesLoop         // Continue looping
  101.  
  102. exitCountOnes:
  103. MOV R0, R2              // Set return value to onesCount
  104. pop {lr}                // pop link register from stack
  105. mov sp,r12              // restore the stack pointer -- Please note stack pointer should be equal to the
  106.                         // value it had when you entered the function .  
  107. mov pc,lr               // return from the function by copying link register into  program counter
  108.  
  109.  
  110. .global returnHammingDistance
  111. .data
  112. .text
  113. returnHammingDistance:
  114. mov   r12,r13           // save stack pointer into register r12
  115. sub   sp,#32            // reserve 32 bytes of space for local variables
  116. push  {lr}              // push link register onto stack -- make sure you pop it out before you return
  117.  
  118.                         // char firstparameter stored in R0
  119.                         // char secondparameter stored in R1
  120. MOV R2, #0              // loopCount stored in R2
  121. MOV R3, #0              // hammingDistance stored in R3
  122. MOV R4, #0              // tempValOne stored in R4
  123. MOV R5, #0              // tempValTwo stored in R4
  124.  
  125. hammingDistanceLoop:
  126. CMP R2, #32             // Compare R2 and 32
  127. BGE exitHammingDistance // Exit if loopCount>32
  128.  
  129. MOV R4, R0              // Copy R0 into R4 so we can AND it
  130. MOV R5, R1              // Copy R1 into R5 so we can AND it
  131.  
  132. AND R4, #1              // And R4 with 1 to see if bit is 1 or 0
  133. AND R5, #1              // And R5 with 1 to see if bit is 1 or 0
  134.  
  135. CMP R4, R5
  136. ADDNE R3, R3, #1        //Increment hammingDistance by 1 if bits are not equal
  137.  
  138.  
  139. LSR R0, #1              // Shift R0 right 1
  140. LSR R1, #1              // Shift R0 right 1
  141.  
  142. ADD R2, #1              // Increment loopCount by 1
  143. b hammingDistanceLoop   // Continue looping
  144.  
  145.  
  146. exitHammingDistance:
  147. MOV R0, R3              // Set return value to hammingDistance
  148. pop {lr}                // pop link register from stack
  149. mov sp,r12              // restore the stack pointer -- Please note stack pointer should be equal to the
  150.                         // value it had when you entered the function .  
  151. mov pc,lr               // return from the function by copying link register into  program counter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement