【问题标题】:MIPS random numbers not outputting to consoleMIPS 随机数不输出到控制台
【发布时间】:2011-03-10 02:17:04
【问题描述】:

我有这个 MIPS 分配,每次按下键时它都会生成一个随机数,数字范围从 0 到 99。按 Enter 键退出。

但是,按键盘上的任何内容都不会在控制台上输出数字。事实上,它不输出任何东西。有谁知道为什么?

.data           # Data declaration section
nl: .asciiz "\n"
msg:    .asciiz "\nHow Lucky Can You Get?"
bye:    .asciiz "\n** Come Back Again **"
    .text
main:
    li  $a3, 0xffff0000  # Base address of I/O
    li  $s1, 2
    sw  $s1, 0($a3) # Enable Keyboard Interrupt
    li  $s1, 0x0000ffff     # Mask to enable all interrupts
    mtc0    $s1, $12        # Store enable bits in Status register
    li  $v0, 4      # Print message
    la  $a0, msg 
    syscall 
    li  $t0, 211        # Seed values
    li  $t1, 3021377 
clear:
    li  $v1, 0      # Clear the flag
ranloop:
    mult    $t0, $t1
    mflo    $t0
    addiu   $t0, $t0, 5923
    beqz    $v1, ranloop    # Keystroke will change $v1
                # to ASCII value for the key
    addiu   $v1, $v1, -10
    beqz    $v1, quit       # Quit if Enter Key
    li  $v0, 4      # Print newline
    la  $a0, nl 
    syscall 
    li  $v1, 100        # Controls Range (0 – 99)
    divu    $t0, $v1
    mfhi    $a0     # Get Remainder
    li  $v0, 1      
    syscall         
    b   clear
quit:
    li  $v0, 4      # Print newline
    la  $a0, bye
    syscall 
    li  $v0, 10
    syscall 

【问题讨论】:

    标签: assembly input console mips


    【解决方案1】:

    我在 beqz 之前添加了一个调用以打印出$v1 的值,如下所示:

    li      $v0, 1      #print value of $v1
    move    $a0, $v1
    syscall
    beqz    $v1, ranloop    # Keystroke will change $v1
    

    无论我在该代码运行之前按了多少键,它始终为 0。我怀疑键盘中断没有像您期望的那样出现。看看它的那一部分。

    如果您还没有尝试过,MARS 是在 MIPS 中工作的好工具。它有一些有用的调试工具(单步调试代码、查看寄存器和内存等)。看看吧here.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 2013-03-18
      • 2011-05-22
      • 1970-01-01
      相关资源
      最近更新 更多