Input no showing in MARS - mips

it compiles but in the output, it does not show anywhere I can input numbers. Have any idea?
.data
msg1: .asciiz "array printing "
msg2: .asciiz "enter the number of rows: "
msg3: .asciiz "enter the number of cols: "
msg4: .asciiz "the value at the location is: "
EOL: .byte '\n'
SPACES: .asciiz " "
MATRIX: .word 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
.text
.globl main
main:
li $v0,4
la $a0,msg1
syscall
addiu $sp,$sp,-4
sw $ra,0($sp)
jal PRTMTX
lw $ra,0($sp)
addiu $sp,$sp,4
li $v0, 10
syscall
PRTMTX:
la $s0, MATRIX
li $s1,1
li $s2,1
li $s6,5
TOPPRT:
addiu $t1,$s1,-1
addiu $t2,$s2,-1
li $t4,20
li $t5,4
mul $t1,$t1,$t4
mul $t2,$t2,$t5
add $s4,$s0,$t1
add $s4,$s4,$t2
li $v0,1
lw $a0,0($s4)
syscall
li $v0,4
la $a0,SPACES
syscall
li $t6,5
div $s2,$t6
mfhi $t6
beqz $t6,ENDROW
addiu $s2,$s2,1
j TOPPRT
ENDROW: li $s2,1
li $v0, 11
lb $a0,EOL
syscall
li $t6,5
div $s1,$t6
mfhi $t6
beqz $t6,DONEPRT
addiu $s1,$s1,1
j TOPPRT
DONEPRT:
jr $ra
PRTNUM:
move $t1,$a0
move $t2,$a1
addiu $t1,$t1,-1
addiu $t2,$t2,-1
li $t3,20
mul $t1,$t1,$t3
li $t3,4
mul $t2,$t2,$t3
la $s0,MATRIX
add $s0,$s0,$t1
add $s0,$s0,$t2
li $v0,4
la $a0,msg4
syscall
lw $a0,0($s0)
li $v0,1
syscall
EXIT:
li $v0, 10
syscall

Related

mips : 1 t~ 100 odd sum (blank fill)

Find the sum of 1 to 100 odd pieces of mips.
Fill in the "#Fill in" section.
I'm hard. Help me.
.data
msg: .asciiz "Sum of odd number: "
number: .word 100
.text
.globl main
mian:
lw $s0,number
#Fill in.
loop:
#Fill in.
li $v0,4
la $a0, msg
syscall
li $v0,1
addi $a0,$t2,0
syscall
li $v0,10
syscall
Try this code :
.data
msg: .asciiz "Sum of odd number: "
#number: .word 100
.text
.globl main
main:
#lw $t0,number #Fill in.
xor $t0,$t0,$t0
addiu $t0,$t0,100
loop: #Fill in.
rem $t1,$t0,2
beq $t1,1,is_odd
j dec_number
is_odd:
addu $t2,$t2,$t0
dec_number:
subiu $t0,$t0,1
beq $t0,0,end_loop
j loop
end_loop:
li $v0,4
la $a0, msg
syscall
li $v0,1
addi $a0,$t2,0
syscall
li $v0,10
syscall

MIPS error:syntax error TT

Can someone help me see my code why is such an error?
I'm doing decimal conversion to binary and here is my code
.data
msg1: .asciiz "Please insert value (A > 0) : "
msg2: .asciiz "Please insert the number system B you want to
convert to (2<=B<=10): "
#Above sting must be in one line
msg3: .asciiz "\nResult : "
.text
.globl main
main:
addi $s0,$zero,2
addi $s1,$zero,10
getA:
li $v0,4
la $a0,msg1
syscall
li $v0,5
syscall
blt $v0,$zero,getA
move $t0,$v0
getB:
li $v0,4
la $a0,msg2
syscall
li $v0,5
syscall
blt $v0,$s0,getB
bgt $v0,$s1,getB
add $t1,$zero,$v0
li $v0,4
la $a0,msg3
syscall
add $a0,$zero,$t0
add $a1,$zero,$t1
jal convert
li $v0,10
syscall
convert:
#a0=A
#a1=B
addi $sp,$sp,-16
sw $s3,12($sp) #counter,used to know
#how many times we will pop from stack
sw $s0,8($sp) #A
sw $s1,4($sp) #B
sw $ra,0($sp)
add $s0,$zero,$a0
add $s1,$zero,$a1
beqz $s0,end
div $t4,$s0,$s1 #t4=A/B
rem $t3,$s0,$s1 #t3=A%B
add $sp,$sp,-4
sw $t3,0($sp) #save t3
add $a0,$zero,$t4 #pass A/B
add $a1,$zero,$s1 #pass B
addi $s3,$s3,1
jal convert #call convert
end:
lw $ra,0($sp)
lw $s1,4($sp)
lw $s0,8($sp)
lw $s3,12($sp)
beqz $s3,done
lw $a0,16($sp)
li $v0,1
syscall
done:
addi $sp,$sp,20
jr $ra #return
and when I run this code it said syntax error at line 13 which is li $v0,4
can someone tell me what is happening?

Masking an integer in MIPS (quick and easy)

I want to input an integer and have it be expressed in both binary and hex. Then I want to move bits 12, 13, 14, and 15 to the least significant bits of $a0, and have the output be expressed as a binary and hex. Here's my program:
.data
enter: .asciiz "Please enter your integer:\n"
binaryI: .asciiz "\nHere is the input in binary: "
hexI: .asciiz "\n\nHere is the input in hexadecimal: "
binaryO: .asciiz "\n\nHere is the output in binary: "
hexO: .asciiz "\n\nHere is the output in hexadecimal: "
.text
prompt:
li $v0, 4
la $a0, enter
syscall
li $v0, 5
syscall
add $s2, $0, $v0
li $v0, 4
la $a0, binaryI
syscall
li $v0, 35
move $a0, $s2
syscall
li $v0, 4
la $a0, hexI
syscall
li $v0, 34
move $a0, $s2
syscall
addi $t0, $0, 7
srl $s0, $s2, 12
and $s0, $s0, $t0
li $v0, 4
la $a0, hexO
syscall
li $v0, 35
move $a0, $s0
syscall
li $v0, 4
la $a0, binaryO
syscall
li $v0, 34
move $a0, $s0
syscall
li $v0, 1
add $a0, $0, $s0
syscall
li $v0, 10
syscall
For the integer 1006460, for example, the inputs and hex output work perfectly, but the binary output has an extra 5 at the end. The error I get is this:
Here is the output in binary: 0x000000055
What may have caused this extra 5 to be at the end of the output?
How silly of me. I should have deleted
li $v0, 1
add $a0, $0, $s0
syscall
from my code.

MIPS Floating Point Division Output

I am new in mips and i got this assignment that asks me to take 2 inputs from user and divide them and get a floating point output.
The problem is the output comes out like this 0.000000000, not the predicted output
this is my code
.data
str1: .asciiz "Enter a: "
str2: .asciiz "Enter b: "
str3: .asciiz " a/b = "
.text
main: li $v0, 4
la $a0, str1
syscall
li $v0, 6
syscall
add $s0, $v0, $zero
li $v0, 4
la $a0, str2
syscall
li $v0, 6
syscall
move $s1, $v0
div $s0, $s1
li $v0, 4
la $a0, str3
syscall
li $v0, 2
move $a0, $t0
syscall
li $v0, 10
syscall
what should i do?
This code works for me.
.data
str1: .asciiz "Enter a: "
str2: .asciiz "Enter b: "
str3: .asciiz " a/b = "
.text
.globl main
main:
#prompt for "a"
li $v0, 4
la $a0, str1
syscall
#User input for "a"
li $v0, 6 #The float value that is read is will be in $f0 register
syscall
mov.s $f3, $f0 #moving the value of "a" into f3 to reuse f0
#prompt for "b"
li $v0, 4
la $a0, str2
syscall
#user input for "b"
li $v0, 6 #The float value that is read is will be in $f0 register
syscall
mov.s $f4, $f0
#Dividing "a" and "b"
div.s $f12 $f3 $f4
#prompt for "a/b"
li $v0, 4
la $a0, str3
syscall
#Displaying contents of f12
li $v0, 2
syscall
li $v0, 10
syscall

find substring and indices in mips

im trying find out substring and first occurrence indices. but something wrong. im comparing each element of pattern array and each element of string array until pointer reach to '\0'. whats the problem. algorithm is totaly wrong ?
#Note: $v0 is a symbolic name used by the assember for $2.
# $a0 is a symbolic name used by the assember for $4.
.data
prompt_str: .asciiz "Please type a text string: "
prompt_ptr: .asciiz "Please type a pattern string: "
print_yes: .asciiz "Yes, there is a match."
print_no: .asciiz "No, there is no match."
text_str: .asciiz "Text string : "
pattern_str: .asciiz "Pattern string : "
print_out: .asciiz "Output to be produced :"
print_dash: .asciiz "----------------------"
print_index: .asciiz "Starting index :"
print_msg : .asciiz "Length of longest partial match = "
nl: .asciiz "\n"
print_outer: .asciiz "please enter string"
str : .space 81
ptr : .space 81
tmp : .space 81
.text
main: la $a0, prompt_str
li $v0, 4 #print_string command.
syscall
la $a0,str #read string
li $a1,81
li $v0,8
syscall
la $t0,str #move string to $t0
la $a0,prompt_ptr
li $v0,4 #print pattern command
syscall
la $a0,ptr #read pattern
li $a1,81
li $v0,8
syscall
la $t1,ptr #move pattern to $t1
lb $t2,0($t0) #pointer first element array of string
move $t4,$t2 #address pointer of $t2
lb $t3,0($t1) #pointer first element array of pattern
outer_loop : beq $t2,$0,end_outer_loop
j inner_loop
inner_loop : beq $t2,$0,end_inner_loop
beq $t3,$0,end_inner_loop
beq $t2,$t3,end_inner_loop
addiu $t2,$t2,1
addiu $t3,$t3,1
j inner_loop
end_inner_loop :bne $t3,$0,inc_ptr
j print_match
inc_ptr : add $t2,$t4,1
j outer_loop
end_outer_loop :la $a0,print_outer
li $v0,4
syscall
print_match : la $a0,text_str #print string
li $v0,4
syscall
move $a0,$t0
li $v0,4
syscall
la $a0,nl #print newline character
li $v0,4
syscall
la $a0,pattern_str #print pattern string
li $v0,4
syscall
move $a0,$t1
li $v0,4
syscall
la $a0,nl #print newline character
li $v0,4
syscall
la $a0,print_out #print output line and newline character
li $v0,4
syscall
la $a0,nl
li $v0,4
syscall
la $a0,print_dash
li $v0,4
syscall
la $a0,print_yes
li $v0,4
syscall
la $a0,print_index #print starting index
li $v0,4
syscall
li $v0,10
syscall
end_loop : li $v0,10
syscall
I used your code for a similar project, in inner_loop you don't have a proper bne
I just put one bne and now it print just the string whit the substring..
.text
.globl main
main:
li $v0, 4
la $a0, msg1
syscall
li $v0, 8
la $a0, strMain
li $a1, 99
syscall
li $v0, 4
la $a0, msg2
syscall
li $v0, 8
la $a0, strSub
li $a1, 99
syscall
la $a0,strMain
jal findLengthString
move $a2, $v0
la $a0, strSub
jal findLengthString
move $a3, $v0 # M
sub $a2, $a2, $a3 # N-M
la $a0, strMain
la $a1, strSub
jal subStringMatch
move $t1, $v0
li $v0, 1
move $a0, $t1
syscall
exit:
li $v0, 10
syscall
lb $t9, endline
findLengthString:
li $t0, -1
move $s0, $a0
loop_fls:
lb $t1, 0($s0)
beq $t1, $t9, foundLength
addi $t0, $t0, 1
addi $s0, $s0, 1
j loop_fls
foundLength:
move $v0, $t0
jr $ra
subStringMatch:
li $t0, 0 #i
loop1:
bgt $t0,$a2, loop1done
li $t1, 0 #j
loop2:
bge $t1, $a3, loop2done
add $t3, $t0, $t1
add $t4, $a0, $t3
lb $t3, 0($t4) # main[i+j]
add $t4, $a1, $t1
lb $t4, 0($t4) # sub[j]
# if a0[i + j] != a1[j]
bne $t3, $t4, break1
addi $t1, $t1, 1
j loop2
loop2done:
beq $t1, $a3, yesReturn
j break1
yesReturn:
move $v0, $t0
jr $ra
break1:
addi $t0, $t0, 1
j loop1
loop1done:
li $v0, -1
jr $ra
.data
msg1: .asciiz "Enter Main String: "
msg2: .asciiz "Enter String to Check SubString: "
strMain: .space 100
strSub: .space 100
endline: .asciiz "\n"