how to sum doubled value and another value in MIPS?

Viewed 26

I'm new to assembly language and I have a task I couldn't solve. the question is (Write a program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.), I've tried to make the user enter a value then make him enter another value, but the result will be doubled, now I want to sum these two values with the constant number using (addiu) but the thing is when I do assembly then run, I insert the values required then it gives me random numbers! I couldn't find what was wrong with my code. please help

my code :

.data 
str1: .asciiz "enter A value: "
str2: .asciiz "enter B value:"
str3: .asciiz "A+2B-5="

.globl main
.text
main:
  li $v0,4 
  la $a0,str1 
  syscall  

  li $v0,5 
  syscall 
  move $t0,$v0   

  li $v0,4 
  la $a0,str2 
  syscall  

  li $v0,5 
  syscall

  move $t1,$v0 
  add $t1,$t1,$t1  
  move $t1,$v0 

  syscall  

  add $t2,$t1,$t0
  move $t2,$v0 

  syscall

  li $v0,4 
  la $a0,str3 
  syscall

  addi $t3,$t2,-5
  syscall

  li $v0,1 
  syscall
0 Answers
Related