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

Write a program to send the following listed data stored at memory locations $21

ID: 3677905 • Letter: W

Question

Write a program to send the following listed data stored at memory locations $2100-$210F to a subroutine that adds them up. Store the result at memory location $21FF. Use “md” to see the result and include in your report. Data (numbers are in decimal): 10,15,34,4,5,6,9,23,38,2,11,14,15,9,7 Do not forget to include a screen shot of the program with zero compilation error and load to the board successfully. (Hint: When a subroutine is called the two-byte return address is pushed into stack. If you use stack in the subroutine you need to consider these two bytes. Read and store them somewhere before using stack, store return address into the stack right before RET instruction in the subroutine.)

Explanation / Answer

* * GLOBAL PARAMETERS FOR SUM SUBROUTINE * ARRAYADD ORIG *+1 LENGTH ORIG *+1

The calling sequence becomes

ENTA P ADDRESS OF P STA ARRAYADD(0:2) LDA N VALUE OF N STA LENGTH JMP SUM

The subroutine itself is then

SUM STJ SUMEXIT ST2 TEMP2(0:2) ENTA 0 LD2 LENGTH * 1H DEC2 1 ADD ARRAYADD,7:2 J2P 1B TEMP2 ENT2 * SUMEXIT JMP *

This version requires indirect addressing, and specifically post-indexed indirection. This could be eliminated, as the double indexing was above, by loading from ARRAYADD into I1 and then incrementing register I1 in the loop. Or the program can modify itself by substituting the actual parameter into the code before executing it. In this case, SUM would be written as

SUM STJ SUMEXIT ST2 TEMP2(0:2) LD2 ARRAYADD(0:2) ST2 2F(0:2) LD2 LENGTH ENTA 0 1H DEC2 1 2H ADD *,2 ADDRESS OF ARRAY SUBSTITUTED J2P 1B TEMP2 ENT2 * SUMEXIT JMP *

Substituting the parameter directly into the code may be acceptable if the parameter is used in only a few instructions in the subroutine, but generally indexing or indirection is a better method of accessing a parameter.

The use of global variables to pass parameters is similar to the use of registers to pass parameters, since registers are essentially just global variables with certain special properties and faster access times. However, use of global variables means that the number and size of parameters are not limited by the number and size of the registers. If a subroutine in MIX had 10 parameters, we could not pass the parameters in the registers, since there are only 8 registers. We would not be able to pass even three parameters if these parameters were each a full five bytes plus sign, since index registers are too small for such parameters. Only the A and X registers can be used to pass full-size parameters. Thus the use of global variables has certain advantages over the use of registers.

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