Port MARS MIPS code to work on eight bit CPU simulator ( sms32v50 )

谁都会走 提交于 2020-01-30 13:08:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!