copy_string.s 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ; Copyright (C) 2016 Jeremiah Orians
  2. ; This file is part of stage0.
  3. ;
  4. ; stage0 is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation, either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; stage0 is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. # We will be using R0 and R1 to pass values to the function
  17. # R15 will be used as the stack pointer
  18. :start
  19. LOADUI R0 @string
  20. LOADUI R1 0x100
  21. LOADUI R2 33
  22. LOADUI R3 44
  23. LOADUI R4 55
  24. LOADUI R15 0x600
  25. CALLI R15 @copy_string
  26. HALT
  27. :string
  28. HALT
  29. HALT
  30. NOP
  31. ;; Our simple string copy function
  32. :copy_string
  33. ;; Preserve registers
  34. PUSHR R0 R15
  35. PUSHR R1 R15
  36. PUSHR R2 R15
  37. PUSHR R3 R15
  38. ;; Setup registers
  39. MOVE R2 R1
  40. MOVE R1 R0
  41. LOADUI R3 0
  42. :copy_byte
  43. LOADXU8 R0 R1 R3 ; Get the byte
  44. STOREX8 R0 R2 R3 ; Store the byte
  45. ADDUI R3 R3 1 ; Prep for next loop
  46. JUMP.NZ R0 @copy_byte ; Stop if byte is NULL
  47. ;; Done
  48. ;; Restore registers
  49. POPR R3 R15
  50. POPR R2 R15
  51. POPR R1 R15
  52. POPR R0 R15
  53. RET R15