How To Print Out Value At Register In Mips
If you take but started Mips Assembly, after learning syntax first basic program you learn is either printer a "Hello world" or reading and print integer or character. In this department, we will learn how to print an integer from a annals and how to read an integer from the keyboard. So let's get started!
Contents
- 1 MIPS Impress Integer from Register
- i.1 Explanation
- 2 MIPS Read Integer from Keyboard/User
- 2.1 Caption
MIPS Print Integer from Register
Commencement, consider the post-obit MIPS program to print an integer from a register:
[lawmaking]
.data
.code
li $to,four
li $v0,i
move $a0,$t0
syscall
li $v0,10
syscall
[/code]
Explanation
In the above program, nosotros take taken a register $t0 to shop an integer. Then we used a syscall service to print that integer. To print that integer we have to move that integer to a register called $a0. The $a0 register is used to store a string, graphic symbol or integer output.
MIPS Read Integer from Keyboard/User
To read an integer in MIPS we have to use a syscall service for reading an integer. Consider the example to read an integer.
[lawmaking]
.information
msg1: .asciiz "Enter a number: "
.lawmaking
li $v0,4
la $a0,msg1
syscall
li $v0,5
syscall
li $v0,10
syscall
[/lawmaking]
Explanation
In the above program, we take used a syscall service "5" for reading an integer. Nosotros take used a label "msg1" to inquire a user to enter a number. In case you don't want to print the message and just want to read the number just remove the msg1 lin in .data department and in .lawmaking department remove the corresponding lawmaking for printing the msg.
Let me know it helped you or not. If you have any trouble feel costless to ask in the comment box. Comment to show me that you are alive!
Source: https://www.assemblylanguagetuts.com/mips-print-and-read-intergers-from-register/
Posted by: fitzgeraldshmed1969.blogspot.com
0 Response to "How To Print Out Value At Register In Mips"
Post a Comment