Homework # 7, Part 1 - Due before class on Wednesday, February 11 Note that the entire pre-lab (including the factoral subroutine) is due before your lab session on Thursday) Modify your triple-precision multiplication program by turning it into a reentrant subroutine. It should be passed its (two) 3-byte arguments via the stack (exactly as shown in the left-hand figure below) and return its (6-byte) result via the stack (exactly as shown below). It should create any local variables that it needs on the stack (see below). Your subroutine should clean up the stack when it is done (e.g., the subroutine, not the calling program, has this responsibility). Your subroutine should be well- behaved in that it should save and restore any register values that it modifies. Make these modifications, debug and test your program using the Sim68 program. Include a calling program with your subroutine, and have the calling program begin at location 2000. Do not forget the issues we discussed in class: load your stack pointer (I would suggest LDS #$7FFF to allow plenty of room for your stack to grow when you later run this on the real chip), end your program with an infinite loop (BRA *, you'll replace this with a "JMP BUFFALO" in lab), comment your code, etc. When you are done, name your program XXXhw07.asm where XXX are your three initials, then mail your (debugged and tested) asm program to: ee347Lsdsu@gmail.com BEFORE 1 pm on Wednesday, February 11th This is also a large part of your pre-lab for this week, so do a good job on this. Get started early, so you have plenty of time to ask questions before the deadline. Shown below is an idea of what my stack looked like at different times in my program. I needed 6 bytes of temporary space to build my product in (alternately, I could have created a 6-byte hole in my stack, copied M and N up into this hole and then built my product in place). My way I have to copy the product down once I'm done with M and N instead of copying M and N up before I start. It doesn't matter which way you do it. Notice that I have not shown my return address or any saved registers. Your stack will contain those bytes also. Either way I need to move my stack pointer "up" the paper, so it points to a lower memory address. This can be done by using DES six times, or (more efficiently) by subtracting 6 from the contents of the SP (see page 135 in your text). When you're done with this temporary space (and have copied the product "down", in my case), you want to clean up the stack. This can be done by 6 INS instructions, or more efficiently in the manner shown on page 135. I would strongly advise you to draw a few pictures (as I have below) and fully understand what is going on. Once you do that, it is a very simple matter to change your last simulation assignment to meet today's require- ments. Hint: after a TSX you will be addressing relative to IX. Before you were addressing relative to P, N, and M (or whatever). It should be a simple matter to figure out that "P+1" is the same as "X + whatever" and quickly change your code ONCE YOU UNDERSTAND the big picture. Stack frames at various times: (note the "little endian" convention that N_2 is the highest order byte of the 3 byte number N, and N_0 is the lowest) Just before at some point just after BSR or JST in the subroutine RTS (perhaps, or maybe something is missing!) SP-> | | SP-> | | SP-> | | |__________| |___________| |___________| | | | | | | MSB of | N_2 | | temp | | P_5 | Product |__________| |___________| six |___________| | | | | bytes | | | N_1 | | temp | of | P_4 | |__________| |___________| local |___________| | | | | stuff | | | N_0 | | temp | | P_3 | |__________| |___________| |___________| | | | | | | | M_2 | | temp | | P_2 | |__________| |___________| |___________| | | | | | | | M_1 | | temp | | P_1 | |__________| |___________| |___________| | | | | | | | M_0 | | temp | | P_0 | LSB of |__________| |___________| |___________| product | | | | | | | old stuff| | N_2 | | old stuff | |__________| |___________| |___________| | | | | | | | N_1 | |___________| | | | N_0 | |___________| | | | M_2 | |___________| | | | M_1 | |___________| | | | M_0 | |___________| | | | old stuff | |___________| Part II -- Prelab assignemnt -- Due before your lab session on Thursday, February 12st. It is basically a requirement to mail in your pre-lab assignment to show that you are coming to lab prepared. I have added some minor requirements to make it easier to grade. Write a recursive factoral routine in our assembly language. Follow the stipulations in this week's lab. You should: 1) comment your code 2) start your calling routine at $2000 3) call your subroutine FCTRL, and start it at $3000 so that I can JSR to it (I plan to invoke it using: JSR FCTRL 4) your subroutine should take the argument in the A accumulator, and return its (six byte) result on the stack 5) It needs to be an honest recursive subroutine, no fair taking advantage of our small word size and looping to get the answer 6) End your calling program in an infinite loop so that I don't run off the end while grading, 7) Set your stack pointer to $7FFF (you'll need stack space!) 8) Your subroutine needs to "do all the work". I will stick a number in acc A, and JSR FCTRL. I'm not going to set up any other stuff first. You should allow my calling program to use all of the space between $2000 and $2FFF (no, I won't use most of it, but it is reserved for ME!) 9) Your subroutine should be fairly well behaved, saving the contents of all user registers except Acc A. 10) After testing and debugging, name your program ABCFCTRL.ASM (where ABC are your initials) and mail the .asm file to: ee347Lsdsu@gmail.com 11) Do this prior to your lab session on Thursday.