Advertisement
Terrys

lab1_1

Jun 4th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. ###################################################
  2. # #
  3. # lab1_1.s #
  4. # Pseudoinstruction examples - System calls #
  5. # t0 - holds each byte from string in turn #
  6. # t1 - contains count of characters #
  7. # t2 - points to the string #
  8. # #
  9. ###################################################
  10. ###################################################
  11. # #
  12. # text segment #
  13. # #
  14. ###################################################
  15. .text
  16. .globl __start
  17. __start:
  18. la $t2,str # t2 points to the string
  19. li $t1,0 # t1 holds the count
  20. nextCh: lb $t0,($t2) # get a byte from string
  21. beqz $t0,strEnd # zero means end of string
  22. add $t1,$t1,1 # increment count
  23. add $t2,1 # move pointer one character
  24. j nextCh # go round the loop again
  25. strEnd: la $a0,ans # system call to print
  26. li $v0,4 # out a message
  27. syscall
  28. move $a0,$t1 # system call to print
  29. li $v0,1 # out the length worked out
  30. syscall
  31. la $a0,endl # system call to print
  32. li $v0,4 # out a newline
  33. syscall
  34. li $v0,10
  35. syscall # au revoir...
  36. #################################################
  37. # #
  38. # data segment #
  39. # #
  40. #################################################
  41. .data
  42. str: .asciiz "hello world"
  43. ans: .asciiz "Length is "
  44. endl: .asciiz "\n"
  45. #################################################
  46. # #
  47. # End of File #
  48. # #
  49. #################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement