问题
How can i change my code to make it work on sms32v50?
.data #storing data
startmsg: .asciiz "Pick a number between 1 and 100.\n\n"
guessmsg: .asciiz "Enter your guess\n"
tooHigh: .asciiz "Your guess is too high.\n\n"
tooLow: .asciiz "Your guess is too low.\n\n"
wingame: .asciiz "You have guessed the number. Well done!\n\n"
.text #start of program
start:
jal random
add $t0, $zero, $a0 # store random number $a0 in $t0
li $v0, 4 # print string
la $a0, startmsg
syscall
#######################################
# Main game loop for guessing
guessing:
la $a0, guessmsg
li $v0, 4 # print string guessmsg
syscall
li $v0, 5 #read int from user
syscall
move $t1, $v0 # store input in t1
#addi $t2, $zero, 1 #t2 = 1 (guess min)
beq $t0, $t1, win # if stored int = user input, user won
addi $s0, $s0, -1 # guess used, subtract
blt $t0, $t1, goLower # if stored int < user input, guess is too high
# otherwise, guess is too low
la $a0, tooLow
li $v0, 4 # print string tooLow
syscall
# loop guessing
j guessing
#######################################
# goLower: Procedure if the user guess too high
goLower:
la $a0, tooHigh
li $v0, 4 # print tooHigh
syscall
# loop back to get another guess
j guessing
#######################################
# User won, print win and restart
win:
la $a0, wingame
li $v0, 4 #print string wingame
syscall
j start
#############################################
# LEAF PROCEDURE
# random: generate a rand number between 0 - 100
random:
li $v0, 42 # SERVICE 41 for a rand int
#addi $a0, $zero, 0 # random number >= 0
addi $a1, $zero, 100 #random number < 100
#xor $a0, $a0, $a0 # Select random generator 0
syscall # Generate random int (returns in $a0)
jr $ra
From comments on my previous question: sms32v50 does not speak MIPS. From the manual: "This simulator emulates an eight bit CPU that is similar to the low eight bits of the 80x86 family of chips."
Where do I start? Or if there is any easy way to do it?
来源:https://stackoverflow.com/questions/59962748/port-mars-mips-code-to-work-on-eight-bit-cpu-simulator-sms32v50