clear_string.s 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 to pass pointer to string
  17. # to cleared by the function
  18. # R15 will be used as the stack pointer
  19. :start
  20. LOADUI R0 @string
  21. LOADUI R1 22
  22. LOADUI R2 33
  23. LOADUI R3 44
  24. LOADUI R4 55
  25. LOADUI R15 0x600
  26. CALLI R15 @clear_string
  27. HALT
  28. :string
  29. HALT
  30. HALT
  31. NOP
  32. ;; Our simple string clear function
  33. :clear_string
  34. ;; Preserve registers
  35. PUSHR R0 R15
  36. PUSHR R1 R15
  37. PUSHR R2 R15
  38. PUSHR R3 R15
  39. ;; Setup registers
  40. MOVE R1 R0
  41. LOADUI R2 0
  42. LOADUI R3 0
  43. :clear_byte
  44. LOADXU8 R0 R1 R2 ; Get the byte
  45. STOREX8 R3 R1 R2 ; Overwrite with a Zero
  46. ADDUI R2 R2 1 ; Prep for next loop
  47. JUMP.NZ R0 @clear_byte ; Stop if byte is NULL
  48. ;; Done
  49. ;; Restore registers
  50. POPR R3 R15
  51. POPR R2 R15
  52. POPR R1 R15
  53. POPR R0 R15
  54. RET R15