-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_1_4.s
35 lines (28 loc) · 1.34 KB
/
lab_1_4.s
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
.data
buffer: .space 256 # Space to store the string
prompt: .asciiz "Enter a string: "
output_prompt: .asciiz "First five characters: "
.text
.globl main
main:
# Print input prompt
li $v0, 4 # System call code for printing a string
la $a0, prompt # Load the address of the prompt into $a0
syscall # Invoke the syscall to print the prompt
# Read string from console
li $v0, 8 # System call code for reading a string
la $a0, buffer # Load the address of the buffer into $a0
li $a1, 256 # Load the maximum number of characters to read into $a1
syscall # Invoke the syscall to read the string
# Print output prompt
li $v0, 4 # System call code for printing a string
la $a0, output_prompt # Load the address of the output prompt into $a0
syscall # Invoke the syscall to print the output prompt
# Load address of the buffer to $a0
la $a0, buffer # Load the address of the buffer into $a0
# Print first five characters of the string
li $v0, 4 # System call code for printing a string
syscall # Invoke the syscall to print the string
# Exit
li $v0, 10 # System call code for exit
syscall # Invoke the syscall to exit