This is a variation of the program shown in Figure 6.12. The change from the original is noted below. Translate this C++ program to assembly language and upload your .pep file here. Include comments and format and symbol trace tags as appropriate in your program.
#include <iostream>
using namespace std;
int main() {
int cop = 0; // Local rather than global variables
int driver = 40;
do{
cop += 25;
driver += 20;
}
while (cop < driver);
cout << cop;
return 0;
}
.text # assembler directive to indicate start of program
main:
addi $t1,$zero,0 # alternative -> li $t1, 0
addi $t2,$zero,40 # alternative -> li $t2, 40
# j overtake
do: bge $t1, $t2, exit # if the contents of register $t1 is greater than or equal to register $t2, exit
addi $t1,$t1,25
addi $t2,$t2,20
b do
exit:
move $a0, $t1 # copy contents of register $t1 to register $a0 for printing
li $v0, 1 # service code to print a number
syscall
li $v0, 10 # service code to exit the program
syscall
Note you use addi to add constants to contents of registers, add is used to add contents of registers to each other. This is true for any other command that has the i appended to the end of it