Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In my computer architecure class we have begun learning MIPS assembly language.

ID: 672359 • Letter: I

Question

In my computer architecure class we have begun learning MIPS assembly language. For our next assignment, we have been instructed to build a program that can store dollar amounts as integers and then terminates the program and solves for the total dollar amount when a zero is entered.

EXAMPLE FROM CONSOLE:

Enter the amount: $100

Enter the amount or 0 to quit and solve: $500

Enter the amount or 0 to quit and solve: 0

TOTAL: $600

END OF PROGRAM

I know that: "li $v0,5 syscall" allows the user to enter an integer into the console.

Is there a way to write a MIPS code where a dollar amount (i.e $100) could be read by the console as just an integer (i.e. 100)? The issue that im having is that whenever a dollar amount is placed before the read integer, the program will not run as $100 is not an integer.

Explanation / Answer

Here is the code what I could make so far.It is an translated code on the editor online.The code is as below:-

0x004013ED   push %ebx
0x004013EE   push %ecx
0x004013EF   sub $0x20,%esp
0x004013F2   call 0x401df0 <__main>
0x004013F7   lea -0x14(%ebp),%eax
0x004013FA   mov %eax,%ecx
0x004013FC   call 0x401518 <std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()>
0x00401401   movl $0x0,-0xc(%ebp)
0x00401408   movl $0x40a064,0x4(%esp)
0x00401410   movl $0x6fcc43c0,(%esp)
0x00401417   call 0x401520 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x0040141C   lea -0x14(%ebp),%eax
0x0040141F   mov %eax,0x4(%esp)
0x00401423   movl $0x6fcc41e0,(%esp)
0x0040142A   call 0x401528 <std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)>
0x0040142F   lea -0x14(%ebp),%eax
0x00401432   movl $0x1,0x4(%esp)
0x0040143A   movl $0x1,(%esp)
0x00401441   mov %eax,%ecx
0x00401443   call 0x401530 <std::string::erase(unsigned int, unsigned int)>
0x00401448   sub $0x8,%esp
0x0040144B   lea -0x14(%ebp),%eax
0x0040144E   mov %eax,%ecx
0x00401450   call 0x401538 <std::string::c_str() const>
0x00401455   mov %eax,(%esp)
0x00401458   call 0x4080a0 <atoi>
0x0040145D   mov %eax,-0x10(%ebp)
0x00401460   cmpl $0x0,-0x10(%ebp)
0x00401464   jne 0x40148f <_fu1___ZSt4cout+30>
0x00401466   movl $0x40a075,0x4(%esp)
0x0040146E   movl $0x6fcc43c0,(%esp)
0x00401475   call 0x401520 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x0040147A   mov -0xc(%ebp),%edx
0x0040147D   mov %edx,(%esp)
0x00401480   mov %eax,%ecx
0x00401482   call 0x401540 <std::ostream::operator<<(int)>
0x00401487   sub $0x4,%esp
0x0040148A   jmp 0x401408 <main()+40>
0x0040148F   mov -0x10(%ebp),%eax
0x00401492   add %eax,-0xc(%ebp)
0x00401495   jmp 0x401408 <main()+40>
0x0040149A   mov %eax,%ebx
0x0040149C   lea -0x14(%ebp),%eax
0x0040149F   mov %eax,%ecx
0x004014A1   call 0x401548 <std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()>
0x004014A6   mov %ebx,%eax
0x004014A8   jmp 0x4014aa <_fu1___ZSt4cout+57>
0x004014AA   mov %eax,(%esp)
0x004014AD   call 0x402060 <_Unwind_Resume>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote