Advertisement
Guest User

Untitled

a guest
May 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. .data ###
  2.  
  3. text1: .asciiz "Bitte geben Sie eine Zahl ein: "
  4.  
  5. .text ###
  6.  
  7. main:
  8. la $a0, text1 #Load text1 in a0
  9. li $v0, 4 #v0= 4, print string, a0
  10. syscall
  11. li $v0, 5 #v0= 5, read int, Eingabe
  12. syscall
  13. li $t3, 1 #t3=1
  14. li $t2, 1 #t2=1
  15. li $t0, 1 #t0 = 1
  16. li $t4, 0
  17. li $t5, 0
  18. beq $t4, $v0, null # If v0 == t0, Springe auf null
  19. nop
  20. move $t4, $v0 #t4=<-v0
  21. bltz $v0, negation #Brachend less than zero,falls $vo <0 negation ausführen
  22. nop
  23. j loop
  24. nop
  25.  
  26. negation:
  27. sub $t4, $t5, $v0 # t4 = 0 - (-3) = 3
  28. j loop #j=jump
  29. nop
  30.  
  31.  
  32. loop:
  33.  
  34. add $t5, $t5, $t2
  35. beq $t4, $t0, breyk #solange $t4 = $t0
  36. addi $t2, $t2, 2 #t2 = t2 + 2
  37.  
  38.  
  39. nop
  40. sub $t4, $t4, $t3 #t4= t4 - 1
  41. j loop
  42. nop
  43.  
  44.  
  45. breyk:
  46. move $a0, $t5 #ergebnis t2 nach a0 kopiert
  47. li $v0, 1 #Print int
  48. syscall
  49. li $v0, 10 #exit
  50. syscall
  51.  
  52.  
  53. null:
  54. li $a0, 0
  55. li $v0, 1 #v0=1, print int a0, Ausgabe 0
  56. syscall
  57. li $v0, 10 #Exit
  58. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement