Advertisement
tsester

hello.asm

Mar 27th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###################################################
  2. #
  3.  #
  4. # lab1_1.s
  5.  #
  6. # Pseudoinstruction examples - System calls
  7. # t0 - holds each byte from string in turn
  8. # t1 - contains count of characters
  9.  #
  10. # t2 - points to the string
  11.  #
  12. #
  13.  #
  14. #
  15. #
  16. ###################################################
  17. ###################################################
  18. #
  19.  #
  20. # text segment
  21.  #
  22. #
  23.  #
  24. ###################################################
  25. .text
  26. .globl __start
  27.     __start:
  28.         la $t2,str   # t2 points to the string
  29.         li $t1,0     # t1 holds the count
  30.     nextCh:
  31.         lb $t0,($t2)    # get a byte from string
  32.         beqz $t0,strEnd  # zero means end of string
  33.         add $t1,$t1,1    # increment count
  34.         add $t2,1    # move pointer one character
  35.         j nextCh     # go round the loop again
  36.     strEnd:
  37.         li $v0,4     # out a message
  38.         la $a0, str
  39.         syscall
  40.         la $a0, endl
  41.         syscall
  42.         la $a0,ans   # system call to print
  43.         syscall
  44.  
  45.         move $a0,$t1     # system call to print
  46.  
  47.         li $v0,1     # out the length worked out
  48.         syscall
  49.  
  50.         la $a0,endl  # system call to print
  51.  
  52.         li $v0,4     # out a newline
  53.         syscall
  54.  
  55.         li $v0,10
  56.         syscall  # au revoir...
  57. #################################################
  58. #
  59.  #
  60. # data segment
  61.  #
  62. #
  63.  #
  64. #################################################
  65. .data
  66.     str: .asciiz "Hello World!"
  67.     ans: .asciiz "Length is "
  68.     endl: .asciiz "\n"
  69. #################################################
  70. #
  71.  #
  72. # End of File
  73.  #
  74. #
  75.  #
  76. #################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement