-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt_integer.asm
48 lines (38 loc) · 903 Bytes
/
prompt_integer.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# This file contains a function that prompts the user to enter an integer and returns the input
# Executing this file prompts the user for an integer then prints it back to them
.data
prompt: .asciiz "Enter a number: "
result: .asciiz "You entered: "
.text
# Call promptInteger using the prompt string
main:
# input = promptInteger("Enter a number: ")
la $a0 prompt
jal promptInteger
move $t0 $v0
# Print the result string
la $a0 result
li $v0 4
syscall
# Print the user's input
# printf("You entered: %d", input)
move $a0 $t0
li $v0 1
syscall
# Terminate the program
li $v0 10
syscall
# Prompt the user to enter an integer and return the input
# Arguments
# $a0 - the address of the prompt string
# Returns
# $v0 - the integer entered by the user
promptInteger:
# Print the prompt string
li $v0 4
syscall
# Get the user's input
li $v0 5
syscall
# Return
jr $ra