-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw_1.asm
65 lines (54 loc) · 1.87 KB
/
cw_1.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
.data
buffer_for_input_string: .space 100
buffer_for_processed_string: .space 100
prompt_for_input: .asciiz "Please enter your string:\n"
prompt_for_output: .asciiz "Your processed string is as follows:\n"
.text
main:
# prompting the user with a message for a string input:
li $v0, 4
la $a0, prompt_for_input
syscall
# reading the input string and putting it in the memory:
# the starting address of the string is accessible as buffer_for_input_string
# 100 is the hard-coded maximum length of the null-terminated string that is
# going to be read from the input. So effectively, up to 99 ascii characters.
li $v0, 8
la $a0, buffer_for_input_string
li $a1, 100
syscall
# >>>> MAKE YOUR CHANGES BELOW HERE:
# Looping over characters of the string:
la $t0, buffer_for_input_string
la $t1, buffer_for_processed_string
Loop:
lb $t2, 0($t0)
beq $t2, ',', PUNC
beq $t2, '.', PUNC
beq $t2, '?', PUNC
beq $t2, ';', PUNC
beq $t2, ':', PUNC
beq $t2, '!', PUNC
j CONTINUE
PUNC:
addi, $t0, $t0, 1
lb $t2, 0($t0)
# potentially do some processing on the character loaded in t2
CONTINUE:
sb $t2, 0($t1)
addi $t0, $t0, 1
addi $t1, $t1, 1
bne $t2, $zero, Loop # keep going until you reach the end of the string,
# which is demarcated by the null character.
# <<<< MAKE YOUR CHANGES ABOVE HERE
# prompting the user with a message for the processed output:
li $v0, 4
la $a0, prompt_for_output
syscall
# printing the processed output
# note that v0 already holds 4, the syscall code for printing a string.
la $a0, buffer_for_processed_string
syscall
# Finish the programme:
li $v0, 10 # syscall code for exit
syscall # exit