Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MIPS assemly launguage programming ATTENTION!!!!USE MIPS not C!not C!thanks!!!!

ID: 3604573 • Letter: M

Question

MIPS assemly launguage programming

ATTENTION!!!!USE MIPS not C!not C!thanks!!!!

ATTENTION!!!!USE MIPS not C!not C!thanks!!!!

ATTENTION!!!!USE MIPS not C!not C!thanks!!!!

1.write a assemly program that outputs all the digits in a string(eg.164ad19,output is 16419) 1.write a assemly program that outputs all the odd digitsin a string (eg.164ad19,output is 119).The SID is requied to be declared as an array of word in the data segment.

2.write a assemly program that outputs all the odd digitsin a string (eg.164ad19,output is 119).The SID is requied to be declared as an array of word in the data segment.

Explanation / Answer

Given below is the MIPS code for the question. Hope it helps. If it did, please don't forget to rate it. Thank you.


.data
str: .asciiz "164ad19"
newline: .asciiz " "
.text
la $t0, str #get address of string str
#print only the digits in a loop
loop1:
lb $t1, ($t0) #get current char
beq $t1, '', end_loop1 #end of string
#check if char in t1 is out of range '0' - '9', if so goto next, otherwise print it
blt $t1, '0', next1 #if char in t1 is < '0'
bgt $t1, '9', next1 #if char in t1 is > '9'
#t1 is in range '0'-'9', print it
li $v0, 11
move $a0, $t1
syscall
next1:
#next location
add $t0, $t0, 1
b loop1
end_loop1:
#print newline
li $v0, 4
la $a0, newline
syscall
#------------------ Part 2 --------------------------------
#print the odd digits in a loop
la $t0, str #get address of string str
li $t2, 2 #load the constant 2 into t2
loop2:
lb $t1, ($t0) #get current char
beq $t1, '', end_loop2 #end of string
#check if char in t1 is out of range '0' - '9', if so goto next, otherwise print it
blt $t1, '0', next2 #if char in t1 is < '0'
bgt $t1, '9', next2 #if char in t1 is > '9'
#t1 is in range '0'-'9', get the numeric value by subtracting ascii value of '0'
sub $t1, $t1, '0' #now t1 is not holding the char's ascii value but numeric value
div $t1, $t2 #divide by 2 and get remainder from hi
mfhi $t3 #get remainder into t3
beqz $t3, next2 #if remainder equal to 0, then its even , skip, otherwise print
#its odd, print it
li $v0, 1
move $a0, $t1
syscall
next2:
#next location
add $t0, $t0, 1
b loop2
end_loop2:
#exit
li $v0, 10
syscall

output

16419
119
-- program is finished running --

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote