-2

I have an unknown output error after entering 2nd value which is after entering base number.

Hopefully,some of you could identify my error:

ERROR:Instruction references undefined symbol at 0x00400060 [0x00400060] 0x102a0000 beq $1, $10, 0 [hex-0x0040005c]

PROGRESS:Currently stucked at Step 2.

What i want to do is,

1)User enter a decimal value

2)User enter type of conversion

3)Go to desired subroutine depending on type of conversion chosen earlier

4)Display output

.data 
prompt: .asciiz "Enter the decimal number to convert: "
base: .asciiz "Select type of base (2 for binary,16 for hexadecimal or 8 for octal): " 
ans1: .asciiz "\nBinary Output is equivalent:"
ans2: .asciiz "\nOctal Output is equivalent:"
ans3: .asciiz "\nHexadecimal Output equivalent:0x" 
result1: .space 8 
.text 
.globl main 
main: 

la $a0, prompt #Display message
li $v0, 4 
syscall
li $v0, 5 
syscall
beq $v0, $zero, Exit #Exit if 0 decimal is entered 
move $t0, $v0   #Else copy value entered into temporaries

askbase:

li $v0, 4
la $a0, base #Display message
syscall
li $v0, 5
syscall
add $t1,$zero,$v0   #Add desired value/base entered into t1

beq $t2,16,hex #if base 16 is entered,goto hex subroutine
beq $t2,8,oct
beq $t2,2,bin

la $a0, ans3 
li $v0, 4 
syscall 
li $t0, 8   # counter 
la $t3, result1 # where answer will be stored 

Hex: 

beqz $t0, Exit  # branch to exit if counter is equal to zero 
rol $t2, $t2, 4 # rotate 4 bits to the left 
and $t4, $t2, 0xf   # mask with 1111 
ble $t4, 9, Sum # if less than or equal to nine, branch to sum 
addi $t4, $t4, 55   # if greater than nine, add 55 

b End 

Sum: 
addi $t4, $t4, 48   # add 48 to result 

End: 
sb $t4, 0($t3)  # store hex digit into result 
addi $t3, $t3, 1    # increment address counter 
addi $t0, $t0, -1   # decrement loop counter 
j Loop 

Exit: la $a0, result1 
li $v0, 4 
syscall 
la $v0, 10 
syscall
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
user3505324
  • 27
  • 2
  • 10
  • 1
    Welcome to StackOverflow. You may not be aware of this, but (after your edit) this is a completely different question than your first one. If you have a new question regarding your MIPS code then you should ask it as a new question. If my answer below solved your first question, you should revert your edit (so that your original question is displayed) and select my answer. Thanks! – embedded_guy Aug 07 '14 at 17:10
  • 1
    Indeed, -1 for drastically altering your question. Questions should not be moving targets; that's a waste of time for people trying to answer them. – Michael Aug 07 '14 at 17:12
  • I'll echo what was said above, to emphasize: Don't edit questions like this in the future, please. – Andrew Barber Aug 07 '14 at 21:32

2 Answers2

0

It looks like you have a typo at line 29 beq $t2,16,hex should be beq $t2,16,Hex. Note the capital letter on Hex. You also have a number of undefined labels: Loop, oct, bin... Without those labels you are going to have issues. It is a good idea to just set some up as place holders (until you have their subroutines defined). Maybe have them all branch to Exit:. The assembler cannot resolve your branch instructions without having the actual labels to go to.

embedded_guy
  • 1,939
  • 3
  • 24
  • 39
  • @user3505324, You're welcome. Are you going to change your question back to the original? – embedded_guy Aug 07 '14 at 17:22
  • I'm not really sure whether to open another new thread which basically will have the same code..but different issue. – user3505324 Aug 07 '14 at 18:05
  • @user3505324, The question is different... so, you should open a new thread. SO is setup so that a single question is asked and answered. If you change the question after it has been answered, then the whole thread becomes a mess - because there will be different answers and some of them will not answer what you have changed the question to. – embedded_guy Aug 07 '14 at 19:34
0

You haven't stored anything in $t7, so there's no particular reason to expect that $t7 would equal 16.

What you probably wanted to write is:

beq $t1,16,hex

Since $t1 is the register that you stored the base in.

However, I really don't see why you would want that jump with the way the code currently is structured. The hex subroutine relies on a few registers (like $t0 and $t3) to have been initialized to certain values, and that initialization would be skipped if that beq is taken.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • well,the problem is..the line "beq $t1,16,hex" has totally been ignored during the code execution.. – user3505324 Aug 07 '14 at 17:14
  • did u try to type #beq $t1,16,hex where # is to comment out this line and re-run in MIPS. You will notice that the execution will still be successful without the above code "beq $t1,16,hex". – user3505324 Aug 07 '14 at 17:27
  • 1
    It's not clear exactly what you mean by _"execution will still be successful"_. If you set a breakpoint on the `beq` instruction in your simulator and single-step from there on you'll see that the `beq` works exactly as expected. It jumps if `$t1` equals 16, and doesn't jump otherwise. Whatever else happens in your program is a different matter. – Michael Aug 07 '14 at 17:45
  • Kindly try to input 1st value which is decimal. Then 2nd value which determines the base. Then you will notice whatever base you enter..you will still be getting the same output. – user3505324 Aug 07 '14 at 18:18
  • 1
    No. You either didn't change the `beq` to use `$t1` instead of `$t7`, or you've changed something else in your code that you haven't shown us. If I enter 16 as the base I get no further output. If I enter something other than 16 I get the "Hexadecimal Output equivalent:..." print. But that's not really relevant. If you step through your code like I said in my previous comment you'll see that the `beq` works just as expected. I suggest that you read your own code carefully and think about what each line does. It should become apparent why the program behaves the way it does. – Michael Aug 07 '14 at 18:57