MIPS Assembly language trying to make a paddle using a random x coordinate. Hell
ID: 3585305 • Letter: M
Question
MIPS Assembly language trying to make a paddle using a random x coordinate.
Hello, I'm currently having trouble getting the value of a random int for my code. I guess I don't know how to get the value of syscall 42.
Here is what i have:
draw_paddle: #draws the paddle using a saved x coordinate: s0
li a1, 50 #set upper bound
li v0, 42 # 42 is system call code to generate random int
syscall # your generated number will be at $a0
move t1, a0
li a0, t1
li a1, 54
li a2, 10
li a3, 2
li v0, COLOR_YELLOW
jal Display_FillRect
syscall
please tell me what i'm doing wrong. Thanks in advance.
Explanation / Answer
The code which you wrote is right.But,there are two mistakes .Here,you have mentioned all the registers with their variables.But,in MIPS we can't access register a0 by directly writing a0 instead we have to use $a0 in order to access it.And,the second mistake is in li a0,t1 .We can't use two registers as operands in this command.One of the operand should be an immediate value.Instead you can use move $a0,$t1 which copy contents of $t1 into $a0.So,here is the random integer generator code :-
draw_paddle:
li $a0,50 #set upper bound
li $v0,42
syscall
move $t0,$a0
move $a0,$t1
li $a1,54
li $a2,10
li $a3,2
li $v0,COLOR_YELLOW
jal Display_FillRect
syscall
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.