Computer Architecture

COMP 2213X2 Assignment #2 Parts A and B Due February 3 in class PLEASE HAND IN PARTS A AND B SEPARATELY!!!!

For “written” questions, please typeyour answers, use your very best English , and carefully consider the material from the chapters. I am usually only looking for a few sentences for each question, not an essay that goes on for pages. So choose your words carefully and thoughtfully.

PART A [1] Does a computer need data registers (like D0–D7 in an M68K)? Defend your answer!

[2] Textbook question 5.35. If your student number is even, do parts (a), (c), (e) and (g). Otherwise do parts (b), (d), (f) and (h). Note that (b) should read “ [[[4]]]”, (c) should read “ [[[0]]]” and (h) should start with “ [0]”.

[3] Explain why the following assembly language and RTL constructs are incorrect. a. MOVE D3,#4 b. MOVE [D3],D2 c. MOVE (D3),D2 d. [D3] A0 + 3 e. [D3] #3 f. 3 [D3] [4] Create a simple M68K program called ADDER. Your program should add together the numbers: 6, 4, 12, 16, 17, and 50. The program should leave the answer in register D0when it terminates.

The program is to be assembled with the M68K cross­assembler and then run on the M68K simu­ lator. You can either install the cross­assembler and simulator given with the textbook (windows) or you can use the Linux one available on the course web site. Doing a trace (to hand in) with the windows version is much more painful than the Linux version, so make your choice carefully (and you have to gure out the windows one without my help).

To use the Linux assembler (“ 68kasm”) and simulator (“ bsvc”), follow the instructions in my mail message of January 26, if you have not already done so.

IMPORTANT NOTE: if you are using the Linux simulator, the instructions for creating a program are slightly different than those in the book. You should have the following at the start of each program: ORG $0 DC.L $8000 This is the stack pointer value after a "reset" DC.L START This is the first instruction to execute You can then follow that with something like 1 ORG $1000 START MOVE ...

You should still have a STOPinstruction and ENDassembler directive, as described in the book, but also use a BREAKinstruction right before your STOPinstruction.

Create your program ( ADDER.s) in your (for example) comp2213/bsvc-master directory using your favourite text editor and assemble it with the command 68kasm -l ADDER.s. If you had no assembly errors you should now have a le called ADDER.h68(which is your executable program) and ADDER.lis (your program listing). Then start up the simulator by typing bsvc. Select File/Open Setup , drill down tosamples/m68000 , selectserial.setup and clickOpen; a new window should pop up on your screen. Now choose File/Load Program, come back up to your bsvc-master directory, and open your ADDER.h68program. Now click the GUI's Reset button and then the Runbutton. (Alternatively, instead of Runclick Single Step and watch the result of each instruction.) After you get your program working, create something to hand in by single­stepping through your program until it nishes, and then use the Tracemenu to insert the register values into the trace window, and then save that window (again from the Tracemenu). Hand that le andyour program listing in. If you are using the windows software, do whatever it takes to hand the same information in. The tutors have looked at the Linux software and should be able to help you with it, but you are really on your own with the windows software.

There are some sample programs in the samples/m68000directory. To learn how to use bsvc, you might nd it instructive to run the MatrixMultiply.h68program using theserialsetup.

PART B [5] What is wrong with each of the following M68K assembly language operations? a. MOVE Temp,#4 b. ADD.B #1,A3 c. CMP.L D0,#9 d. MOVE.B #500,D5 [6] Translate the following fragment of high­level language into M68K assembly language. Then create a complete M68K program containing your code, and use a M68K simulator to test your program.

IF T = 5THEN X = 4 ELSE Y = 6 END_IF Hand in the program listing and program trace as in Question 4.

2 [7] A sequence (string) of one­byte ASCII characters is stored at memory location $600 onward. A second sequence of equal length is stored at memory location $700 onward. Each sequence ends with the character $0 (i.e., the ASCII NUL character). Write a M68K assembly language program to determine whether or not these two strings are identical. If they are identical, place the value $00 in data register D0. If they are not, place the value $FF in D0.

Use the M68K cross­assembler and simulator to test your program (make up a couple of your own strings, using the DC.Bassembler directive). Hand in the program listing and program trace as in Question 4.

[8] Write a subroutine ADDABCthat performs the operation C = A + B. VariablesA,B , and Care all word (i.e., 16­bit) values. Test your program on the M68K simulator by writing a main program which sets up values in Aand Band then calls your main program.

Your calling code and subroutine should have the following features:

Parameters Aand Bshould be passed on the stack to the procedure by reference (i.e., by address). Parameter Cshould be passed back to the calling program on the stack by value.

Before you call the subroutine, make room on the stack for the returned parameter (i.e., parameter C). After calling the subroutine, read the parameter off the stack into data register D0 (i.e., D0should end up containing the value of A + B).

The subroutine ADDABCmust not corrupt any registers. Save all working registers on the stack on entry to the subroutine and restore them before returning from the subroutine.

When you write your code, preset the stack pointer to a value like $1500 (by using either MOVEA.L #$1500,A7 orLEA $1500,A7 ). Doing this will make it easier to follow the movement of the stack while your program is running.

Make certain that you are operating with the correct operand sizes! Use .Wfor data values and .Lfor addresses/pointers.

Some of the important instructions you might need are provided below. Make sure you understand exactly what they do.

MOVEM.L RegList,-(A7) Push a group of registers on stack MOVEM.L (A7)+,RegList Pop a group of registers off stack LEA X(Ai),Aj Load Aj with the contents of Ai + X MOVEA.L (Ai),Aj Load Aj with longword pointed at by Ai Your program should be of the general form: ORG $0 DC.L $8000 Initial value of stack pointer DC.L START First instruction here ORG $400 START LEA $1500,A7 Set up the stack pointer with an easy value ... Pass the parameters BSR ADDABC Call the subroutine ... Get the result, C, in D0 ... Clean up the stack STOP #$2700 Halt execution 3 * ADDABC ... ...

RTS * ORG $1200 Put the test data here A DC.W $1234 This is the first parameter B DC.W $ABAB This is the second parameter END START This is not an easy or trivial problem. You will need to draw a map of the stack at every stage and take very great care not to confuse pointers (addresses) and actual parameters.

Hand in a listing and trace of your program as descried in question 4. NOTE: a lot of the other questions in Chapters 5 and 6 look like good midterm and/or nal exam questions to me.

4