Dear talent students, In this team project (at most 2 persons), you are tying to
ID: 3723887 • Letter: D
Question
Dear talent students,
In this team project (at most 2 persons), you are tying to "hack" a computer by looking for its password. However, the password is secretly nested in a long string. Please write a MIPS assembly code to retrieve the nested password.
To simplify the task, the string that contains the password is provided and is stored in the data segment.
The password is a 6-consecutive digits. For example:
a123456 is NOT a password
123456a is NOT a password
12345 is NOT a password
1234567 is NOT a password
123456 is a password.
Please use the provided MIPS code as a starter and comment your code.
If you work out the project alone, you will receive 20% extra points.
Provided:
.data
MemoryData:
.asciiz "this is not a password 1122^&*( this is password?987654hello world!!!!1234567"
.text
.globl main
main:
# Your code starts here
la $a0, MemoryData # load the head address of "MemoryData" into register $a0
li $v0, 4 # let computer know you about to print out a string
syscall # pring out the string
***Answer must be in MIPS***
Explanation / Answer
#variable declaration
.data
MemoryData: .asciiz "This is not a password 1122^&*(this is password?987654hello World!!!!!1234567 "
result: .asciiz " is a password ."
#main program
.text
li $t2,0 #counter for 6 digits
la $a0,MemoryData #load the given string
li $v0,4 #sytem call to print string
syscall
move $t0,$a0 #move string address into t0
#loop to take each character of the string
loop:lb $t1,0($t0) #each character into t1
move $t4,$t1 #move character into t4 for checking
lb $t3,1($t0) #next character into t3
#is digit check
blt $t4,48,exit1
bgt $t4,57,exit1
blt $t3,48,exit1
bgt $t3,57,exit1
#compare if the sequence is reverse consecutive
addi $t4,$t4,-1
beq $t3,$t4,next
#compare if the sequence is forward consecutive
addi $t4,$t4,2
bne $t3,$t4,exit1
next:add $t2,$t2,1 #increment counter to display 6 digits
bgt $t2,6,exit1 #greater than 6 then exit
move $a0,$t1 #print consecutive digits
li $v0,11
syscall
#increment $t0 to get next character ang continue loop
exit1:add $t0,$t0,1
beq $t1,10,exit #if the string end then exit
j loop
exit:la $a0,result #add is password at the end of the result
li $v0,4
syscall
li $v0,10 #program end
syscall
Output
This is not a password 1122^&*(this is password?987654hello World!!!!!1234567
987654 is a password .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.