Guest User

Untitled

a guest
Oct 17th, 2015
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##############################################
  2. # Program Name: String Length
  3. # Programmer: David Thornberg
  4. # Date: 10/14/2015
  5. #############################################
  6. #
  7. #
  8. #
  9. #############################################
  10. #
  11. ###########################################
  12.  
  13.         .data   # Data declaration section
  14. Prompt: .asciiz " \n Set1: "
  15. Prompt2: .asciiz " \n Set2: "
  16. Set1:   .space 80
  17. Set2:   .space 80
  18. Result: .asciiz ","
  19. Result2: .asciiz "\n The set is..."
  20. Bye:    .asciiz " \n Have a nice day."
  21.         .globl  main
  22.         .text
  23.        
  24. main:
  25.    
  26.     la $t0, printSet
  27.    
  28.     li  $v0, 4      #System call code for Print
  29.     la  $a0, Prompt #load add.dress of prompt into $a0
  30.     syscall
  31.     li  $v0, 8
  32.     la  $a0, Set1
  33.     la  $a1, 80
  34.     syscall         #print the prompt message
  35.    
  36.     li  $v0, 4      #System call code for Print
  37.     la  $a0, Prompt2    #load add.dress of prompt into $a0
  38.     syscall
  39.     li  $v0, 8
  40.     la  $a0, Set2
  41.     la  $a1, 80
  42.     syscall         #print the prompt message
  43.    
  44.     la $s0, Set1
  45.     la $s1, Set2
  46.    
  47.     move $s3, $s0
  48.     jalr $s6, $t0
  49.    
  50.     move $s3, $s1
  51.     jalr $s6, $t0
  52.    
  53.     j End
  54.    
  55.    
  56. printSet:
  57.  
  58.        li $t2, 0x0       # A one to test the results
  59.        li $t3, 0x0       # A zero to test the results
  60.        li $t4, 0x1       # The number of the set
  61.        lw $t6, ($s3)     # Load set from address $s3
  62.        li $t7, 0x32      # Max number of sets
  63.        
  64.        li   $v0, 4      #System call code for Print String
  65.        la   $a0, Result2     #load add.dress of msg into $a0
  66.        syscall          #print the string
  67.  
  68.     loop:
  69.         and $t5, $t6, $t2     # Test the lowest bit
  70.         beq $t5, $t3, check    # Result is non-zero only if the bit is set
  71.  
  72.         li $v0, 1         # system call code for integer print
  73.         move $a0, $t4    # set integer to be printed
  74.         syscall          # print the integer
  75.        
  76.         li  $v0, 4      #System call code for Print String
  77.         la  $a0, Result #load add.dress of msg into $a0
  78.         syscall         #print the string
  79.  
  80.     check: beq $t7, $t4, back  # check whether it was the last set
  81.        srl $t6, $t6, 1    # shift the bit one place right to test next bit
  82.        addi $t4, $t4, 1   # add 1 to the set number
  83.        b loop
  84.        
  85.        
  86.     back:
  87.    
  88.         jr $s6
  89.        
  90.        
  91.      
  92. End:   
  93.     li  $v0, 4      #System call code for Print String
  94.     la  $a0, Bye    #load add.dress of msg into $a0
  95.     syscall         #print the string
  96.     li  $v0, 10     #terminate program run and
  97.     syscall         #return control to the system
Advertisement
Add Comment
Please, Sign In to add comment