Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. --------Min funktion----------
  2.  
  3. loop:
  4. beq $a2,$zero,done
  5. lb $t0, 0($a0)
  6. sb $t0, 0($a1)
  7.  
  8. addi $a0,$a0,1
  9. addi $a1,$a1, 1
  10. addi $a2,$a2, -1
  11.  
  12. j loop
  13.  
  14. ------ Facit ------
  15. .data
  16. .align 2
  17. # Test buffers
  18. src: .ascii "0123456789abcdef"
  19. .space 16
  20. dst1: .space 32
  21. dst2: .space 32
  22. .text
  23. main:
  24. # TEST 1
  25. # Copy from an aligned position to an aligned position,
  26. # using an aligned number of bytes.
  27. la $a0,src
  28. la $a1,dst1
  29. li $a2,14 # copy 14 bytes
  30. jal memcpy
  31. # TEST 2
  32. # Copy from as well as to unaligned positions.
  33. la $a0,src
  34. addi $a0,$a0,5 # make the destination address unaligned
  35. la $a1,dst2
  36. li $a2,7 # copy 7 bytes
  37. jal memcpy
  38. stop: j stop
  39. # Simple memory copy function. One byte at a time is
  40. # copied.
  41. # Input: $a0 = source address
  42. # $a1 = destination address
  43. # $a2 = number of bytes to copy
  44. memcpy:
  45. loop:
  46. beq $a2,$zero,done # branch if done
  47. lb $t0,0($a0) # load byte
  48. sb $t0,0($a1) # store byte
  49. addi $a0,$a0,1 # increment src pointer
  50. addi $a1,$a1,1 # increment dst pointer
  51. addi $a2,$a2,-1 # decrement counter
  52. j loop
  53. done:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement