Advertisement
Guest User

Untitled

a guest
May 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. .data                               # data section
  3. dataarray:      .word 0, 0, 0, 0    # data space for addition
  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                 # initialize counter variable
  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.         multu $s3,$s1,$s2       # Array-Ende
  26.        
  27.        
  28. loop1:
  29.         bgt $t0, $s3, filled      # jump if t0>12  
  30.  
  31.         li  $v0,4                # print string service
  32.         la  $a0,prompt1          # write("Summand eingeben: ")
  33.         syscall
  34.        
  35.         li  $v0,5                # read integer service
  36.         syscall
  37.        
  38.         sw $v0, dataarray($t0)   # store word v0 into A($t0)
  39.        
  40.         addi $t0,4               # adjust offset
  41.         j loop1                  # jump to loop1
  42.  
  43. filled:        
  44.         li $t0,0                 # initialize t0 - offset
  45.        
  46. loop2:  
  47.         bgt $t0, $s3, done        # jump if t0>12
  48.        
  49.         lw $t2, dataarray($t0)   # load a value from the array to t2
  50.         add $s0, $s0, $t2        # add t2 to the result
  51.        
  52.         addi $t0,4               # adjust offset
  53.         j loop2                  # jump to loop2
  54.  
  55. done:        
  56.         li  $v0,4                # print string service
  57.         la  $a0,prompt2          # write("Summe ausgeben: ")
  58.         syscall
  59.        
  60.         li  $v0,1                # print integer service
  61.         move $a0, $s0            # print result
  62.         syscall
  63.        
  64.         li $v0, 10               # Exit program
  65.         syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement