Advertisement
Guest User

Untitled

a guest
May 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. .data                               # data section
  3.  
  4. prompt1: .asciiz "Summand eingeben: "
  5. prompt2: .asciiz "Summe: "
  6. prompt3: .asciiz "Wie viele Summanden moechten Sie eingeben? "
  7.  
  8.  
  9. .text                            # text section
  10. .globl main                      # call main by SPIM
  11.  
  12. main:  
  13.         li $t0,0                 # initialize t0 - offset
  14.         li $s0,0                 # initialize s0 (result)
  15.         li $s1,4                 # 4
  16.        
  17.         li  $v0,4                # print string service
  18.         la  $a0,prompt1          # write("Wie viele Summanden moechten Sie eingeben?")
  19.         syscall
  20.        
  21.         li  $v0,5                # read integer service
  22.         syscall
  23.        
  24.         move $s2,$v0             # Summand in $s2 schieben
  25.         mulo $s3,$s1,$s2         # Array-Ende
  26.        
  27.         move $a0,$s3             # gewuenschte Groesse in $a0 schieben
  28.         li $v0,9                 # Speicher anfordern
  29.         syscall
  30.        
  31.        
  32. loop1:
  33.         bgt $t0, $s3, filled      # jump if t0>12  
  34.  
  35.         li  $v0,4                # print string service
  36.         la  $a0,prompt1          # write("Summand eingeben: ")
  37.         syscall
  38.        
  39.         li  $v0,5                # read integer service
  40.         syscall
  41.        
  42.         sw $v0, dataarray($t0)   # store word v0 into A($t0)
  43.        
  44.         addi $t0,4               # adjust offset
  45.         j loop1                  # jump to loop1
  46.  
  47. filled:        
  48.         li $t0,0                 # initialize t0 - offset
  49.        
  50. loop2:  
  51.         bgt $t0, $s3, done        # jump if t0>12
  52.        
  53.         lw $t2, dataarray($t0)   # load a value from the array to t2
  54.         add $s0, $s0, $t2        # add t2 to the result
  55.        
  56.         addi $t0,4               # adjust offset
  57.         j loop2                  # jump to loop2
  58.  
  59. done:        
  60.         li  $v0,4                # print string service
  61.         la  $a0,prompt2          # write("Summe ausgeben: ")
  62.         syscall
  63.        
  64.         li  $v0,1                # print integer service
  65.         move $a0, $s0            # print result
  66.         syscall
  67.        
  68.         li $v0, 10               # Exit program
  69.         syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement