Firstly, you might want to check this quick MIPS reference. It really helped me.
Secondly, to explain jal
, jr
and $ra
. What jal <label>
does is jump to the label
label and store the program counter (think of it as the address of the current instruction) in the $ra
register. Now, when you want to return from label
to where you initially were, you just use jr $ra
.
Here’s an example:
.text main: li $t0, 1 jal procedure # call procedure li $v0, 10 syscall procedure: li $t0, 3 jr $ra # return
You will notice when running this in a SPIM emulator that the value left in $t0
is 3, the one loaded in the so-called procedure.
Hope this helps.
Related Posts:
- strdup() – what does it do in C?
- strdup() – what does it do in C?
- “Parameter” vs “Argument”
- What is the proper declaration of main in C++?
- ‘foo’ was not declared in this scope c++
- Help needed with Median If in Excel
- PHP Fatal error: Using $this when not in object context
- How do you pass a function as a parameter in C?
- How do you pass a function as a parameter in C?
- Using multiple .cpp files in c++ program?
- Optional arguments in C function
- How do I use the filter function in Haskell?
- C: How do I make a number always round up
- Define a global variable in a JavaScript function
- How to send an email with Python?
- Define a global variable in a JavaScript function
- Return array in a function
- What’s the difference between a method and a function?
- What is the naming convention in Python for variable and function names?
- How to create a jQuery function (a new jQuery method or plugin)?
- Why shift a bit using sll and such in MIPs Assembly?
- Understanding how `lw` and `sw` actually work in a MIPS program
- Passing parameters to a Bash function
- Deprecated: mysql_connect()
- C error: undefined reference to function, but it IS defined
- Call a function from another file?
- Python Calling Function from Another File
- MIPS: lw (load word) instruction
- MIPS fetch address not aligned on word boundary, used .align 4, still no go
- PLS-00201 – identifier must be declared
- IndexError: index 1 is out of bounds for axis 0 with size 1/ForwardEuler
- Return value in a Bash function
- Python return list from function
- What is the difference between call and apply?
- Python 3: UnboundLocalError: local variable referenced before assignment
- MIPS – Fetch address not aligned on word boundary
- MIPS assembly for a simple for loop
- mips .word function and differences between 2 codes
- Why doesn’t there exists a subi opcode for MIPS?
- error: “initializer expression list treated as compound expression”
- How would I call a javascript function in html?
- Mips how to store user input string
- What is the difference between la and li in opcodes in MIPS?
- Getting error: ISO C++ forbids declaration of with no type
- Pass a JavaScript function as parameter
- Bubble sort algorithm in MIPS
- How to stop a function
- How do I correctly use the mod operator in MIPS?
- includes() not working in all browsers
- Repeating a function in Python
- python3 TypeError: ‘function’ object is not iterable
- No function matches the given name and argument types
- Uncaught TypeError: .indexOf is not a function
- How to get a function name as a string?
- Anagrams finder in javascript
- what is the use of ori in this part of MIPS code?
- Storing a user’s input in MIPS
- Python: Can a function return an array and a variable?
- Function for C++ struct
- Call Python function from JavaScript code
- MIPS ‘nor’ usage in code
- Php include not working? function not being included
- c++ –
- Simple average function in Javascript
- What does it mean that “a declaration shadows a parameter”?
- function is not defined error in Python
- Calling a user defined function in jQuery
- How do I return a char array from a function?
- Uncaught Error: Call to undefined function mysql_escape_string()
- struct has no member named
- Reading and printing an integer in mips
- How to return a boolean method in java?
- What is define([ , function ]) in JavaScript?
- Why can’t we pass arrays to function by value?
- Multiplying a register value by a constant in MIPS?
- Arithmetic Overflow in mips
- Subtract two input numbers
- Stopping a JavaScript function when a certain condition is met
- Assembly language (MIPS) difference betweent addi and add
- MIPS Address out of range (MARS)
- Can I define a function inside a C structure?
- Difference between “addi” and “add” for pseudoinstruction “move” in MIPS?
- Printing newline in MIPS
- sorting array in mips (assembly)
- Passing string to a function in C – with or without pointers?
- What is the difference between ggplot and ggplot2?
- ERROR: Control may reach end of non-void function /
- anchor jumping by using javascript
- C++ correct way to return pointer to array from function
- Convert from Java to MIPS
- Understanding Assembly MIPS .ALIGN and Memory Addressing
- What is the use of a $zero register in MIPS?
- Is C++ Array passed by reference or by pointer?
- “cannot be used as a function error”
- How to run a PHP function from an HTML form?
- Javascript- Multiplying 2 numbers and return number
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- PHP Call to undefined function
- Multiplication function with recursion in Python
- How can you use php in a javascript function