├── FizzBuzz ├── fizzBuzz.html ├── FizzBuzz.md ├── fizzBuzz.js └── fizzBuzz.asm ├── Misc └── AddLoop.asm └── README.md /FizzBuzz/fizzBuzz.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Misc/AddLoop.asm: -------------------------------------------------------------------------------- 1 | .text 2 | .globl main 3 | 4 | main: 5 | add $t0, 10 # number of iterations 6 | add $t1, 0 # t1 is our counter (i) 7 | add $t2, 17 # t2 holds value to modify 8 | loop: 9 | beq $t1, $t0, end # if t1 == t0 end loop 10 | add $t2, $t2, $t1 # body 11 | addi $t1, $t1, 1 # add 1 to t1 12 | j loop # jump back to the top 13 | end: 14 | add $v0, 10 15 | syscall -------------------------------------------------------------------------------- /FizzBuzz/FizzBuzz.md: -------------------------------------------------------------------------------- 1 | # FizzBuzz 2 | 3 | ## Instructions 4 | 5 | Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "Fizz Buzz". 6 | 7 | Write Fizz Buzz in the language of your choice. 8 | 9 | Then write Fizz Buzz in MIPS32 assembly. 10 | -------------------------------------------------------------------------------- /FizzBuzz/fizzBuzz.js: -------------------------------------------------------------------------------- 1 | let result = ''; 2 | for (let i = 1; i <= 100; i++) { 3 | if (i == 1) { 4 | if (i % 3 == 0 && i % 5 == 0) { 5 | result += 'Fizz Buzz'; 6 | } else if (i % 3 == 0) { 7 | result += 'Fizz'; 8 | } else if (i % 5 == 0) { 9 | result += 'Buzz'; 10 | } else { 11 | result += i; 12 | } 13 | } else if (i % 3 == 0 && i % 5 == 0) { 14 | result += ', Fizz Buzz'; 15 | } else if (i % 3 == 0) { 16 | result += ', Fizz'; 17 | } else if (i % 5 == 0) { 18 | result += ', Buzz'; 19 | } else { 20 | result += ', ' + i; 21 | } 22 | } 23 | 24 | console.log(result); 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MIPS32 Assembly Beginner Programs 2 | 3 | Programs I'm working on to learn MIPS32 Assembly. 4 | 5 | ## How to Start 6 | 7 | 1. Launch QtSpim 8 | 2. Load program file 9 | 3. Step through program with F10 key 10 | 11 | Tip: After running a program, you need to do a few things to reset for running it again (or running a new program). 12 | 13 | 1. Simulator --> Clear Registers 14 | 2. Simulator --> Reinitialize Simulator 15 | 3. File --> Load File 16 | 17 | If you encounter errors, open Simulator --> Settings. Make sure that the MIPS tab shows Bare Machine as being unchecked and Accept Pseudo Instructions as checked. 18 | 19 | ## Programs 20 | 21 | - FizzBuzz: Classic FizzBuzz problem 22 | - Miscellaneous Programs 23 | - AddLoop: Use a loop to increment a value 24 | -------------------------------------------------------------------------------- /FizzBuzz/fizzBuzz.asm: -------------------------------------------------------------------------------- 1 | .data 2 | fizz_string: .asciiz ", Fizz" 3 | buzz_string: .asciiz ", Buzz" 4 | fizzbuzz_string: .asciiz ", Fizz Buzz" 5 | comma_string: .asciiz ", " 6 | 7 | .text 8 | .globl main 9 | 10 | main: 11 | li $v0, 4 12 | li $t0, 100 # total number of iterations 13 | li $t1, 0 # current number (start at 1, will end at 100) 14 | li $t2, 15 # for checking $t1 % $t3 AND $t1 % $t5 15 | li $t3, 3 # for checking $t1 % $t3 16 | li $t5, 5 # for checking $t1 % $t5 17 | loop: 18 | beq $t1, $t0, end # if t1 == t0 then end loop 19 | addi $t1, $t1, 1 # add 1 to t1 20 | 21 | beq $t1, 1, firstPrint # if t1 == 1 then print without comma 22 | 23 | div $t1, $t2 24 | mfhi $s0 25 | beq $s0 $0 fizzbuzz # if $t1 % $t2 == 0, go to fizzbuzz 26 | 27 | div $t1, $t3 28 | mfhi $s0 29 | beq $s0 $0 fizz # if $t1 % $t3 == 0, go to fizz 30 | 31 | div $t1, $t5 32 | mfhi $s0 33 | beq $s0 $0 buzz # if $t1 % $t5 == 0, go to buzz 34 | 35 | la $a0, comma_string # print comma 36 | li $v0, 4 37 | syscall 38 | la $a0, ($t1) # print current number 39 | li $v0, 1 40 | syscall 41 | 42 | j loop 43 | fizz: 44 | la $a0, fizz_string # print fizz 45 | li $v0, 4 46 | syscall 47 | j loop 48 | buzz: 49 | la $a0, buzz_string # print buzz 50 | li $v0, 4 51 | syscall 52 | j loop 53 | fizzbuzz: 54 | la $a0, fizzbuzz_string # print fizzbuzz 55 | li $v0, 4 56 | syscall 57 | j loop 58 | firstPrint: 59 | la $a0, ($t1) # to print first value without a comma appearing before it 60 | li $v0, 1 61 | syscall 62 | j loop 63 | end: 64 | li $v0, 10 65 | syscall --------------------------------------------------------------------------------