【问题标题】:Instruction references undefined error in MIPS/QTSPIM jal 0x00000000 [main] ; 188: jal main指令引用 MIPS/QTSPIM jal 0x00000000 [main] 中的未定义错误; 188:日式主菜
【发布时间】:2016-08-31 12:25:41
【问题描述】:

我的代码中有以下错误。请帮忙。 指令在 0x00400014 [0x00400014] 0x0c000000 jal 0x00000000 [main] 处引用未定义符号; 188:日式主菜 此代码将华氏温度转换为摄氏温度,将摄氏温度转换为华氏温度

.data 0x10008000

.word 5,9,32

 message1: 
    .asciiz "Select the temparature scale:<C or F><ENTER"
 message2: .asciiz "Type the desired temperature <ENTER>"
 message3: asciiz  "Temparature= "

.text

.globl main

main:
   li $v0,4
   la $a0,message1
   syscall

  li $v0,12
  syscall

  move $t0,$v0

  li $t1,70
  li$t2,67
 beq $t0,$t1,Farenheit
 beq $t0,$t2,Celcius

li $v0,10
 syscall


Farenheit:

     li $v0,4
     la $a0,message2
     syscall


     li $v0,6
     syscall

     lui $gp, 0x1000   #I put in register $gp the number 0x10008000,which                
     ori $gp, $gp,0x8000 # shows in the middle of address of static data

     lwc1 $f16, 0($gp)   

     cvt.s.w $f16, $f16



      lwc1 $f18, 4($gp)

     cvt.s.w $f18, $f18


      div.s $f20 , $f16,f$18

      lwc1 $f14, 8($gp)

      cvt.s.w $f14 $f14

      lwc1 $f12,$v0

      sub.s $f12,$f12,$f14

      mul.s $f0,$f20,$f12


       la $a0,message3
       li $v0,4
       syscall

      mov.s $f12,$f0
      li $v0,2
      syscall


       jr $ra


Celcius: 

     li $v0,4
     la $a0,message2
     syscall


     li $v0,6
     syscall

     lui $gp, 0x100
     ori $gp, $gp,0x8000

     lwc1 $f16, 0($gp)

     cvt.s.w $f16, $f16



      lwc1 $f18, 4($gp)

     cvt.s.w $f18, $f18


      div.s $f20 , $f18,f$16

      lwc1 $f14, 8($gp)

      cvt.s.w $f14 $f14

      lwc1 $f12,$v0

      mul.s $f12,$f12,$f20
      add.s $f0,$f12,$f14

       la $a0,message3
       li $v0,4
       syscall

      mov.s $f12,$f0
      li $v0,2
      syscall


       jr $ra

【问题讨论】:

    标签: assembly mips qtspim


    【解决方案1】:

    @kintzo 嘿,Kintzo,我来自 auth。谢谢你的帮助。我已经完成了我的代码,它和你的很相似,但是我做了两个函数,检查我的代码并告诉我你是否想要你的意见。你也使用了 $ra (从函数返回)而没有实际调用通过 $jal 。这是 Craig 提到的一个问题。这是我的代码

    .data 0x10008000
         .word       5,9,32
    
    
    
    msg_scale:  .asciiz     "Select the temperature scale:<C or F><ENTER>"
    msg_temp:   .asciiz     "Type the desired temperature <ENTER>"
    msg_out:    .asciiz     "Temperature= "
    msg_nl:     .asciiz     "\n"
    
        .text
    
        .globl  main
    
    main:
        # prompt user for temp type/scale
        li      $v0,4
        la      $a0,msg_scale
        syscall
    
    
    
    
    
    
      # read in temp scale
        li      $v0,12
        syscall
        move    $t0,$v0
    
        # output a newline
        la      $a0,msg_nl
        li      $v0,4
        syscall
    
        # prompt for temperature
        li      $v0,4
        la      $a0,msg_temp
        syscall
    
        # read in temperature
        # NOTE: result comes back in $f0 and _not_ $v0
        li      $v0,6
        syscall
    
    
    
        li      $t1,'F'
        beq     $t0,$t1,F
    
    
        li      $t1,'C'
        beq     $t0,$t1,C
    
     F: 
            jal Farenheit
    
        la      $a0,msg_out
        li      $v0,4
        syscall
    
        mov.s   $f12,$f0
        li      $v0,2
        syscall
    
        la      $a0,msg_nl
        li      $v0,4
        syscall
    
    
       j       main_exit
    
    
     C:
            jal Celcius
    
    
        la      $a0,msg_out
        li      $v0,4
        syscall
    
        mov.s   $f12,$f0
        li      $v0,2
        syscall
    
        la      $a0,msg_nl
        li      $v0,4
        syscall
    
    
    j       main_exit
    
    
    
    main_exit:
        li      $v0,10
        syscall
    
    
    
    
    
      .globl Farenheit 
    
       Farenheit:
    
        lui $gp , 0x1000
        ori $gp , $gp, 0x8000
    
         lwc1 $f16 , 0($gp)
    
         cvt.s.w $f16,$f16
    
        lwc1 $f18, 4($gp)
    
        cvt.s.w $f18, $f18
    
        lwc1 $f14, 8($gp)
    
        cvt.s.w $f14 $f14
    
        div.s   $f20,$f16,$f18          # get 5/9
        mov.s   $f12,$f0
        sub.s   $f12,$f12,$f14          # subtract 32 from given temprerature
        mul.s   $f0,$f20,$f12           # multiply by 5/9
        jr      $ra
    
    
    
    
    
    
    
     .globl Celcius 
    
      Celcius:
    
        lui $gp , 0x1000
        ori $gp , $gp, 0x8000
    
         lwc1 $f16 , 0($gp)
    
         cvt.s.w $f16,$f16
    
        lwc1 $f18, 4($gp)
    
        cvt.s.w $f18, $f18
    
        lwc1 $f14, 8($gp)
    
        cvt.s.w $f14 $f14
    
    
        div.s   $f20,$f18,$f16          # get 9/5
        mov.s   $f12,$f0
        mul.s   $f12,$f12,$f20          # multiply by 9/5
        add.s   $f0,$f12,$f14           # add 32
        jr      $ra
    

    【讨论】:

    • 这似乎是对@Kinto's 的回复,但显然它也是对您自己问题的回答,因为您说此代码可以正常工作。最好将此作为适当的独立答案发布,并对 Kinto 的答案发表评论,让他知道您已发布此内容。 (在您的答案文本中进行讨论不是我们在 SO 上做事的方式)。
    【解决方案2】:

    我的大学也有同样的文章(也许你也来自 Auth,如果不是的话,这个括号没有意义:P)

    如果您没有回答您的 Craigs 回复问题,请查看我的代码,它可以正常工作。

    我认为经过研究(MIPS $gp register 和通过互联网)使用 gp 访问您存储在静态数据段中的数据不是一个好方法,但这就是程序被告知要完成的方式!

    此外,由于没有重新初始化您的模拟器,可能会出现许多错误!

    这是我的代码,希望我帮忙!

     .data 0x10008000  
     .word 5, 9, 32
          message1: .asciiz "Select the temparature scale:<C or F>:"
          message2: .asciiz "Type the desired temperature:"
          message3: .asciiz  "Temparature= "
          newline:  .asciiz "\n" 
    .text
    
    .globl main
    
    main:
    
    li $v0,4
    la $a0,message1
    syscall                             #prompt message
    
    #read the character
    li $v0,12
    syscall
    
    move $t0,$v0
    
    #check the character and branch                                     
    li $t1,'F'
    beq $t0,$t1,Fahrenheit             
    li $t1,'f'
    beq $t0,$t1,Fahrenheit             #fahrenheit to celsius
    
    li      $t1,'C'
    beq     $t0,$t1,Celsius
    li      $t1,'c'
    beq     $t0,$t1,Celsius            #celsius to fahrenheit
    
    li $v0,10
    syscall                            #end program
    
    Fahrenheit:
    
    li $v0,4
    la $a0,newline
    syscall                           #type new line
    
    
    li $v0,4                          #type message 2
    la $a0,message2
    syscall             
    
    li $v0,6
    syscall                          #read float from user
    
    #gp has 0x10008000 
    lui $gp, 0x1000
    ori $gp, $gp, 0x8000              #load to f16 number 5
    
    lwc1 $f16, 0($gp)                
    
    cvt.s.w $f16, $f16                #convert to float
    
    lwc1 $f18, 4($gp)                 #load number 9 to f18
    
    cvt.s.w $f18, $f18                #convert to float
    
    
    div.s $f20, $f16, $f18            #divide 5/9 and save it to f20
    
    lwc1 $f14, 8($gp)                 #load number 32
    
    cvt.s.w $f14, $f14                #convert to float
    
    
    li      $v0,6                     #read from user float
    mov.s   $f12,$f0                 
    
    sub.s $f12, $f12, $f14            #Fahrenheit - 32
    
    mul.s $f0, $f20, $f12             #(Fahrenheit-32)*5/9 ,the result
    
    li $v0,4
    la $a0,newline
    syscall                           #type new line
    
    li $v0,4
    la $a0,message3
    syscall                           #type message 3
    
    mov.s   $f12,$f0
    li      $v0,2
    syscall                           #type the result
    
    jr $ra
    
    Celsius: 
    li $v0,4
    la $a0,newline
    syscall                          #type new line
    
    
    li $v0,4                         #type message 2
    la $a0,message2
    syscall             
    
    li $v0,6
    syscall                          #read float from user
    
    lui $gp, 0x1000
    ori $gp, $gp,0x8000
    
    lwc1 $f16, 0($gp)                 #load number 5 to f16
    
    cvt.s.w $f16, $f16                #convert to float
    
    lwc1 $f18, 4($gp)                 #load number 9 to f18
    
    cvt.s.w $f18, $f18                #convert to float
    
    div.s $f20 , $f18,$f16            #save number 9/5( f18 / f16) to f20
    
    lwc1 $f14, 8($gp)                 #load number 32 to f14
    
    cvt.s.w $f14 $f14                 #convert to float
    
    li      $v0,6                     #read from user
    mov.s   $f12,$f0
    
    mul.s $f0,$f12,$f20               #Celsius * 9/5
    add.s $f0,$f0,$f14                #(Celsius*9/5)+32
    
    li $v0,4
    la $a0,message3
    syscall                           #Type the Result!
    
    mov.s   $f12,$f0
    li      $v0,2
    syscall
    
    jr $ra
    

    【讨论】:

    • 嘿,Kintzo,我来自 auth。谢谢你的帮助。我已经完成了我的代码,它和你的很相似,但是我做了两个函数,检查我的代码并告诉我你是否想要你的意见。你也使用了 $ra (从函数返回)而没有实际调用通过 $jal 。这是 Craig 提到的问题。这是我的代码
    【解决方案3】:

    首先感谢您的支持,它非常​​有帮助。对不起我的风格,我是汇编初学者,通常是编程初学者。我的代码有点混乱,因为我应该完成一个不完整的代码。让我解释一下you.这是发音:

       .data0x10008000
         .word 5,9,32,100
         .text 
          lui $gp, 0x100
         ori $gp, $gp,0x8000
    
         lwc1 $f16, 0($gp)
    
         cvt.s.w $f16, $f16
    
    
    
          lwc1 $f18, 4($gp)
    
         cvt.s.w $f18, $f18
    
    
          div.s $f20 , $f16,f$18
    
          lwc1 $f14, 8($gp)
    
          cvt.s.w $f14 $f14
    
          lwc1 $f12,12($gp)
          cvt.s.w $f12,$f12
    
          sub.s $f12,$f12,$f14
    
          mul.s $f0,$f20,$f12
    
          jr $ra
    

    你应该完成这段代码并添加用户界面(就像我在我的代码中所做的那样),并且还应该编写一个代码来完成从 farheneit 到摄氏度的转换。这就是我感到困惑的原因:(

    【讨论】:

    • 这应该是对问题的编辑,或者其他什么。我不认为这是一个实际的答案,所以请不要将它作为一个发布。
    【解决方案4】:

    您的代码甚至无法干净地组装。

    使用$gp [带有硬编码偏移] 访问.word 5,9,32 是多余的。为.data 部分设置显式地址也可能不好。

    “读取浮点数”系统调用返回 $f0not $v0 中的值

    在摄氏和华氏部分之间有很多可以合并的重复代码。

    您使用jr $ra [从函数返回] 没有通过jal 实际调用计算部分

    应该有更多的 cmets 来解释你的逻辑流程。您可能想在这里看到我的回答:MIPS linked list,因为它提供了一些关于 asm 样式和简洁编码的提示。

    无论如何,这里是清理、注释和工作的代码:

        .data
    
    temp5:      .word       5
    temp9:      .word       9
    temp32:     .word       32
    
    msg_scale:  .asciiz     "Select the temperature scale:<C or F><ENTER>"
    msg_temp:   .asciiz     "Type the desired temperature <ENTER>"
    msg_out:    .asciiz     "Temperature= "
    msg_nl:     .asciiz     "\n"
    
        .text
    
        .globl  main
    
    main:
        # prompt user for temp type/scale
        li      $v0,4
        la      $a0,msg_scale
        syscall
    
        # read in temp scale
        li      $v0,12
        syscall
        move    $t0,$v0
    
        # output a newline
        la      $a0,msg_nl
        li      $v0,4
        syscall
    
        # prompt for temperature
        li      $v0,4
        la      $a0,msg_temp
        syscall
    
        # read in temperature
        # NOTE: result comes back in $f0 and _not_ $v0
        li      $v0,6
        syscall
        ###lwc1 $f12,$v0
        mov.s   $f12,$f0
    
        lwc1    $f16,temp5              # get 5
        cvt.s.w $f16,$f16
    
        lwc1    $f18,temp9              # get 9
        cvt.s.w $f18,$f18
    
        lwc1    $f14,temp32             # get 32
        cvt.s.w $f14,$f14
    
        # do fahrenheit to celcius
        li      $t1,'F'
        beq     $t0,$t1,Farenheit
        li      $t1,'f'
        beq     $t0,$t1,Farenheit
    
        # do celcius to fahrenheit
        li      $t1,'C'
        beq     $t0,$t1,Celcius
        li      $t1,'c'
        beq     $t0,$t1,Celcius
    
        j       main_exit
    
        # print results
    main_print:
        la      $a0,msg_out
        li      $v0,4
        syscall
    
        mov.s   $f12,$f0
        li      $v0,2
        syscall
    
        la      $a0,msg_nl
        li      $v0,4
        syscall
    
        j       main
    
    main_exit:
        li      $v0,10
        syscall
    
    Farenheit:
        div.s   $f20,$f16,$f18          # get 5/9
        sub.s   $f12,$f12,$f14          # subtract 32 from temp
        mul.s   $f0,$f20,$f12           # multiply by 5/9
        j       main_print
    
    Celcius:
        div.s   $f20,$f18,$f16          # get 9/5
        mul.s   $f12,$f12,$f20          # multiply by 9/5
        add.s   $f0,$f12,$f14           # add 32
        j       main_print
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多