Search code examples
assemblymipspipelineprocessor

In Assembly language (LC 2200 MIPS), Coding Confusion


If I were to increment $a0 from 0 to 10 using a loop. Then, increment memory address 0 from 0 to 10 using a loop...

Would the code roughly look like

Loop:
addi $a0,1

Solution

  • this is how you implement loops in MIPS Assembly:

    .globl main
    
    main:
    # start of the loop
    loop:
        bgt $a0,10,exit # checks if $a0 is greater than 10 loop ending condition
        addi $a0,$a0,1  # adds one to the $a0 the loop variable
        j loop          # jumps to continue loop
    
    exit:
        li $v0,10       # sets the value of $v0 to 10 to terminate the program
        syscall         # terminate
    

    Kindly check this link if you want to learn more about loops in MIPS Assembly