├── readingString.txt ├── 2.1.txt ├── 1.txt ├── 3.txt ├── 3.3.txt ├── 3.2.txt ├── 2.2.txt ├── 2.3.txt ├── occurences.txt ├── 3.1.asm ├── 2.txt ├── README.md └── CODE_OF_CONDUCT.md /readingString.txt: -------------------------------------------------------------------------------- 1 | .data 2 | stringinput: .space 20 3 | 4 | .text 5 | main: 6 | la $a0, stringinput #carries address 7 | li $a1, 12 #$a0 = address where string to be stored, $a1 = number of characters to read + 1 8 | 9 | li $v0, 8 #user input string 10 | syscall 11 | 12 | li $v0, 4 #printing output 13 | syscall 14 | 15 | li $v0, 10 #ending the program 16 | syscall -------------------------------------------------------------------------------- /2.1.txt: -------------------------------------------------------------------------------- 1 | .data 2 | num: .word 1, 2, 3 3 | .text 4 | main: 5 | la $t1, num 6 | lw $t2, 0($t1) 7 | add $t3, $zero, $zero 8 | loop: 9 | beq $t3, 3, end 10 | addi $t3, $t3, 1 11 | add $t1, $t1, 4 12 | lw $t4, 0($t1) 13 | slt $t5, $t2, $t4 14 | beq $t5, 1, change 15 | j end 16 | change: 17 | move $t2,$t4 18 | j loop 19 | end: 20 | 21 | -------------------------------------------------------------------------------- /1.txt: -------------------------------------------------------------------------------- 1 | .data 2 | names: .word 1, 2, 3, 4 3 | names2: 4 | .text 5 | main: 6 | addi $t5, $t5, 1 7 | addi $t4, $t4, 5 8 | add $t6, $t6, $zero 9 | add $t7, $t7, $zero 10 | la $t0, names 11 | la $t2, names2 12 | loop: 13 | add $s0, $t0, $t6 14 | add $s1, $t2, $t7 15 | lw $t3, 0($s0) 16 | sw $t3, 0($s1) 17 | addi $t6, $t6, 4 18 | addi $t7, $t7, 4 19 | li $v0, 1 20 | add $a0, $t3, $zero 21 | addi $t5, $t5, 1 22 | syscall 23 | beq $t4, $t5 end 24 | j loop 25 | end: 26 | 27 | -------------------------------------------------------------------------------- /3.txt: -------------------------------------------------------------------------------- 1 | .data 2 | prompt: .asciiz "Enter n" 3 | .text 4 | main: 5 | li $v0, 4 6 | la $a0, prompt 7 | syscall 8 | 9 | #getting the n value 10 | li $v0, 5 11 | syscall 12 | 13 | add $t0, $zero, $v0 # t0= user input 14 | addi $t1, $zero, 2 # counter variable 15 | add $t2, $zero, $zero 16 | addi $t3, $zero, 1 17 | loop: 18 | ## 19 | addi $t4, $t2, 0 20 | ## 21 | addi $t2, $t3, 0 22 | add $t3, $t3, $t4 23 | addi $t1, $t1, 1 24 | beq $t0, $t1 end 25 | j loop 26 | end: 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /3.3.txt: -------------------------------------------------------------------------------- 1 | .data 2 | num: .word 9, 7, 6, 5 3 | .text 4 | main: 5 | add $t0, $0, $0 #outerloop counter 6 | la $t1, num 7 | addi $t2, $0, 4 8 | outerloop: 9 | beq $t2, $t0, end 10 | add $t3, $zero, $zero #innerloop counter 11 | addi $t0, $t0, 1 #updating outerloop_counter 12 | la $t1, num 13 | j innerloop 14 | 15 | innerloop: 16 | beq $t3, 3, outerloop 17 | addi $t3, $t3, 1 #updating innerloop_counter 18 | lw $s1, 0($t1) 19 | lw $s2, 4($t1) 20 | 21 | slt $s3, $s2, $s1 22 | beq $s3, 1, swap 23 | add $t1, $t1, 4 #update t1 24 | j innerloop 25 | 26 | 27 | swap: 28 | sw $s2, 0($t1) 29 | sw $s1, 4($t1) 30 | add $t1, $t1, 4 #update t1 31 | j innerloop 32 | 33 | end: 34 | -------------------------------------------------------------------------------- /3.2.txt: -------------------------------------------------------------------------------- 1 | .data 2 | prompt: .asciiz "Enter the value1" 3 | pri: .asciiz "Enter the value2" 4 | check: .asciiz "correctly debugged till here" 5 | .text 6 | main: 7 | #User I/O 8 | li $v0, 4 9 | la $a0, prompt 10 | syscall 11 | li $v0, 5 12 | syscall 13 | add $s0, $v0, $zero 14 | 15 | li $v0, 4 16 | la $a0, pri 17 | syscall 18 | li $v0, 5 19 | syscall 20 | add $s1, $v0, $zero 21 | 22 | jal procedure 23 | j finish 24 | procedure: 25 | add $t1, $s0, $zero 26 | add $t2, $s1, $zero 27 | add $s0, $t2, $zero 28 | add $s1, $t1, $zero 29 | jr $ra 30 | finish: 31 | -------------------------------------------------------------------------------- /2.2.txt: -------------------------------------------------------------------------------- 1 | .data 2 | prompt: .asciiz "Enter n" 3 | .text 4 | main: 5 | li $v0, 4 6 | la $a0, prompt 7 | syscall 8 | 9 | #getting the n value 10 | li $v0, 5 11 | syscall 12 | jal procedure 13 | j finish 14 | 15 | procedure: 16 | add $t0, $zero, $v0 # t0= user input 17 | addi $t1, $zero, 2 # counter variable 18 | add $t2, $zero, $zero 19 | addi $t3, $zero, 1 20 | loop: 21 | ## 22 | addi $t4, $t2, 0 23 | ## 24 | addi $t2, $t3, 0 25 | add $t3, $t3, $t4 26 | addi $t1, $t1, 1 27 | beq $t0, $t1 end 28 | j loop 29 | end: 30 | jr $ra #returning back to the callee 31 | finish: 32 | -------------------------------------------------------------------------------- /2.3.txt: -------------------------------------------------------------------------------- 1 | .data 2 | num: .asciiz "0123456789ABCDEF" 3 | destination: .asciiz "0" 4 | prompt: .asciiz "Starting to copy 0123456789ABCDEF " 5 | pri: .asciiz "the value is :: " 6 | .text 7 | main: 8 | li $v0, 4 9 | la $a0, prompt 10 | syscall 11 | jal stringcpy 12 | j finish 13 | stringcpy: 14 | add $s0, $zero, $zero #i=0 15 | la $a1, num 16 | la $a0, destination 17 | loop: 18 | add $t1, $a1, $s0 #source indexing 19 | lb $t2, 0($t1) #loading source[i] to t2 20 | add $t3, $a0, $s0 #indexing destination 21 | sb $t2, 0($t3) 22 | 23 | beq $t2, $zero,loop2 24 | addi $s0, $s0, 1 25 | j loop 26 | loop2: 27 | jr $ra 28 | finish: 29 | #printing the copied string 30 | li $v0, 4 31 | la $a0, pri 32 | syscall 33 | la $a0, destination 34 | li $v0,4 35 | syscall 36 | -------------------------------------------------------------------------------- /occurences.txt: -------------------------------------------------------------------------------- 1 | .data 2 | arr: .word 1, 1, 1, 2, 3 3 | prompt: .asciiz "Count:" 4 | .text 5 | main: 6 | la $t0,arr #Array base address 7 | add $t1,$zero,$zero #i 8 | add $t2,$zero,$zero #j 9 | add $t3,$zero,5 #n 10 | j loop 11 | outloop: 12 | addi $v0,$zero,4 13 | la $a0,prompt 14 | syscall 15 | addi $v0,$zero,1 16 | add $a0,$s1,$zero # Print count 17 | syscall 18 | loop: 19 | beq $t1,$t3,exit #if ( i < n) 20 | sll $t4,$t1,2 21 | add $t2,$t1,$zero # j=i 22 | addi $t1,$t1,1 #i++ 23 | add $t4,$t0,$t4 24 | lw $t5,0($t4) #arr[i] 25 | add $s1,$zero,$zero #count = 0 26 | inloop: 27 | beq $t2,$t3,outloop # if(jfact 31 | 32 | lw $ra, 0($sp) 33 | addi $sp, $sp, 4 #deleting 1 elements 34 | 35 | jr $ra #until main ra 36 | 37 | finish: 38 | 39 | -------------------------------------------------------------------------------- /2.txt: -------------------------------------------------------------------------------- 1 | .data 2 | prompt: .asciiz "Enter n" 3 | pri: .asciiz "Enter integer" 4 | message: .asciiz "Largest is" 5 | num: .word 0, 0 6 | .text 7 | main: 8 | add $t2, $zero, $zero 9 | li $v0, 4 10 | la $a0, prompt 11 | syscall 12 | 13 | #getting the n value 14 | li $v0, 5 15 | syscall 16 | 17 | #storing the result 18 | add $t6, $v0, $zero 19 | move $t0, $zero 20 | 21 | la $s0, num 22 | ## 23 | add $t2, $zero, $zero 24 | ## 25 | loop: 26 | mul $t4, $t2, 4 27 | add $t1, $s0, $t4 28 | 29 | #getting the user's numbers 30 | li $v0, 4 31 | la $a0, pri 32 | syscall 33 | 34 | #getting the value 35 | li $v0, 5 36 | syscall 37 | add $t3, $v0, $zero 38 | sw $t3, 0($t1) 39 | addi $t2, $t2, 1 40 | beq $t2, $t6, big 41 | #printing 42 | li $v0, 1 43 | add $a0, $t3, $zero 44 | syscall 45 | j loop 46 | big: 47 | add $t2,$zero,$zero 48 | lw $s4,0($s0) 49 | add $t5, $zero, $s0 #Indexing 50 | loop2: 51 | beq $t2, $t6, end 52 | lw $s5,0($t5) 53 | slt $s6,$s5,$s4 54 | beq $s6,1,else 55 | add $s4,$s5,$zero 56 | else: 57 | addi $t2, $t2, 1 58 | mul $t5,$t2,4 59 | add $t5, $t5, $s0 60 | j loop2 61 | end: 62 | li $v0, 4 63 | la $a0, message 64 | syscall 65 | li $v0, 4 66 | add $a0, $s4, $zero 67 | syscall -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Computer Organization and Architecture 2 | 3 | [![N|Solid](https://cldup.com/dTxpPi9lDf.thumb.png)](https://nodesource.com/products/nsolid) 4 | 5 | This repository holds all the code I shall write for my course CSE381 on Computer Organization and Architecture. It is all in MIPS assembly. The objective of this course is to feel more at home to lower computer level code. This repository also holds the cheatsheets the author used to code as well as register information pretaining to all the registers in use. 6 | 7 | - MIPS cheatsheet 8 | - Detail on QtSpim 9 | 10 | ### Installation 11 | 12 | MIPS assembly requires [QtSpim](http://spimsimulator.sourceforge.net/) or other simulators to run. The author has maintained QtSpim for all testing and debugging. 13 | 14 | ### File Content 15 | 16 | 17 | 18 | | FileName | Content| 19 | | ------ | ------ | 20 | | 1.txt | [Transfering data from Memory] | 21 | | 2.txt | [largest number from list] 22 | | 3.txt | [Fibonnaci Numbers] | 23 | | 2.1.txt | [Procedure1: Max Number] 24 | | 2.2.txt | [Procedure2: Fibonnaci] | 25 | | 2.3.txt | [Procedure3: String copy] 26 | | 3.1.txt | [Recursive Factorial] | 27 | | 3.2.txt | [Procedure4: Swap] 28 | | 3.3.txt | [Sorting] | 29 | 30 | 31 | ### Cheatsheets 32 | 33 | 34 | 35 | | Cheatsheet | ReferenceLink| 36 | | ------ | ------ | 37 | | uidaho | [MIPS Instruction](http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html) | 38 | | General MIPS | [Reference](http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm) 39 | 40 | 41 | 42 | ### Development 43 | Want to contribute? Great! If you have any cool MIPS code that you want to share, be my guest, send in your valuable PR. 44 | 45 | License 46 | ---- 47 | 48 | NoRightsReserved :P 49 | 50 | ### Resolved Issues 51 | 52 | [StackOverflow](https://stackoverflow.com/questions/51924814/mips-bad-address-exception/51925013#51925013) 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at mrahul.krishnan@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | --------------------------------------------------------------------------------