Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.    
  3. ask: .asciiz "Please enter a string:\n"
  4. debug: .asciiz "\nentering loop first letter\n"
  5. debug1: .asciiz "\nentering loop 2 letter\n"
  6. debug2: .asciiz "\nOutput address: \n"
  7. tell: .asciiz "You wrote: "
  8. first: .asciiz "\nFirst letter is: "
  9. storedCounter: .word 0
  10. string: .space 256
  11. output: .space 1000
  12.    
  13. .text
  14.      .globl __start
  15.      
  16. __start:
  17.  
  18.     la $a0, ask
  19.     li $v0, 4
  20.     syscall
  21.      
  22.     la $a0, string
  23.     li $a1, 255
  24.     li $v0, 8
  25.     syscall
  26.  
  27.     la $a0, tell
  28.     li $v0, 4
  29.     syscall
  30.      
  31.     la $a0, string
  32.     li $v0, 4
  33.     syscall
  34.     j CharacterLoop
  35.  
  36.    
  37.     move $s1, $zero
  38.    
  39.     move $s2, $zero
  40.    
  41. CharacterLoop:     
  42.     #################
  43.     #               #
  44.     # First letter  #
  45.     #               #
  46.     #################
  47.     la $a0, debug
  48.     li $v0, 4
  49.     #syscall
  50.     lb $a2, string($s1)
  51.    
  52.     beq $a2, 10, EXIT
  53.    
  54.     lb $t1, string($s1) #load the first letter into $t1
  55.     add $s1, $s1, 1
  56.     srl $t9, $t1, 2      # shift right $t1 by 2, into $t2
  57.     sll $t8, $t1, 6
  58.     srl $t8, $t8, 8     #t8 will now hold the last 2 letters of the first word zero'd!!!!
  59.     move $t9, $t8           #t9 is final holder for first letter, after it has been shifted
  60.    
  61.     #################
  62.     #               #
  63.     # Second letter #
  64.     #               #
  65.     #################
  66.     la $a0, debug1
  67.     li $v0, 4
  68.     #syscall
  69.     lb $t2, string($s1) #load the second letter into $t2   
  70.     beq $t2, 10, EXIT
  71.     add $s1, $s1, 1
  72.     srl $t3, $t2, 4      # shift right $t1 by 2, into $t2
  73.     sll $t4, $t2, 28
  74.     srl $t4, $t4, 26
  75.     or $t8, $t9, $t3 #T8 holding the 2nd segment of the 3 chars
  76.      
  77.     #################
  78.     #               #
  79.     # Third letter  #
  80.     #               #
  81.     #################
  82.    
  83.    
  84.     move $t3, $zero
  85.     lb $t3, string($s1) #load the third letter into $t3
  86.     beq $t3, 10, EXIT
  87.     add $s1, $s1, 1
  88.    
  89.     srl $t5, $t3, 6
  90.     or $t6, $t4, $t5
  91.    
  92.     ###Get rid of the first 2 numbers from the third letter!
  93.     sll $t7, $t3, 26
  94.     srl $t7, $t7, 26
  95.    
  96.  
  97.     ########################################################
  98.     ##     Move the "four" new letters into T1 through 4  ##
  99.     ########################################################
  100.    
  101.     ##Output address
  102.     la $a0, debug2
  103.     li $v0, 4
  104.     syscall
  105.    
  106.     la $a0, output
  107.     li $v0, 1
  108.     syscall
  109.    
  110.     move $t1, $t9
  111.     move $t2, $t8
  112.     move $t3, $t6
  113.     move $t4, $t7
  114.    
  115.    
  116.    
  117.     sb $t1, output($s2)
  118.     add $s2, $s2, 4
  119.    
  120.     sb $t2, output($s2)
  121.     add $s2, $s2, 4
  122.     sb $t3, output($s2)
  123.     add $s2, $s2, 4
  124.    
  125.     sb $t4, output($s2)
  126.     add $s2, $s2, 4
  127.    
  128.     la $a0, output+4
  129.    
  130.     li $v0, 4
  131.     syscall
  132.     j CharacterLoop
  133.  
  134. EXIT:
  135.      
  136.     li $v0, 10
  137.     syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement