1)Write a subroutine in MARIE assembly that multiplies two values where the argu
ID: 3552421 • Letter: 1
Question
1)Write a subroutine in MARIE assembly that multiplies two values where the arguments for this subroutine are two pointers(each pointing to a value). The routine, multiply(a,b), performs *a x *b where a's value is the address storing the value being multiplied( *a uses a's contents to retrieve the value being multiplied), and b's value is the address storing the value being multiplied(*b uses b's contents to retrieve the value being multiplied). The program should compile and run as written.
Here are some requirements for submission:
Your program cannot use the following three MARIE instructions(you may use any other instruction other than these three): Load, Add, and store.
Comment on at least 80% of the code to show what the code is doing.
When submitting your code, you should hardcode a=2 and b=7, however your program should still work correctly if we change the value of a and b.
Explanation / Answer
The idea of subroutines is simple enough. A subroutine is just a sequence of instructions that performs some specific task. Whenever a program needs to perform that task, it can call the subroutine to do so. The subroutine only has to be written once, and once it is written, you can forget about the details of how it works. If the same task needs to be performed in another program, then it can simply be copied from one program to another using cut-and-paste . So the work done on writing the subroutine doesn't have to be repeated over and over. The subroutine can be reused. In fact, real computers have large librariesof subroutines that are available for use by programs. The complex programs that are used on modern computers would be extremely difficult to write, if these libraries of pre-written subroutines were not available.
In xComputer's assembly language, "calling" a subroutine means jumping to the first instruction in the subroutine, using a JMP instruction. The execution of the subroutine will end with a jump back to the same point in the program from which the subroutine was called, so that the program can pick up where it left off before calling the subroutine. This is known as returning from the subroutine. (Other computers provide special commands for calling and returning from subroutines.)
The main program in the "MultiplyTwoNumbers.txt" sample program is as follows:
Carefully explain each instruction in this program. Explain exactly what each of the first 8 instructions has to do with calling the subroutine.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.