Comp 2213x2- explain why the following assembly language


Assignment: Parts A and B

For "written" questions, please type your 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 D0 when 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 figure 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

ORG     $1000    START MOVE ...

You should still have a STOP instruction and END assembler directive, as described in the book, but also use a BREAK instruction right before your STOP instruction.

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 file 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 to samples/m68000, select serial.setup and click Open; 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.h68 program. Now click the GUI's Reset button and then the Run button. (Alternatively, instead of Run click 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 finishes, and then use the Trace menu to insert the register values into the trace window, and then save that window (again from the Trace menu). Hand that file and your 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/m68000 directory. To learn how to use bsvc, you might find it instructive to run the MatrixMultiply.h68 program using the serial setup.

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 = 5
       THEN X = 4
       ELSE Y = 6
END_IF
Hand in the program listing and program trace as in Question 4.

[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.B assembler directive). Hand in the program listing and program trace as in Question 4.

[8] Write a subroutine ADDABC that performs the operation C = A + B. Variables A, B, and C are all word (i.e., 16-bit) values. Test your program on the M68K simulator by writing a main program which sets up values in A and B and then calls your main program.

Your calling code and subroutine should have the following features:

? Parameters A and B should be passed on the stack to the procedure by reference (i.e., by address). Parameter C should 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., D0 should end up containing the value of A + B).

? The subroutine ADDABC must 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 or LEA $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 .W for data values and .L for 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

 




START

DC.L
DC.L
ORG
LEA
...
BSR
...
...
STOP

$8000
START
$400
$1500,A7

ADDABC


#$2700

Initial value of stack pointer
First instruction here

Set up the stack pointer with an easy value
Pass the parameters
Call the subroutine
Get the result, C, in D0
Clean up the stack
Halt execution

*
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 final exam questions to me.

Solution Preview :

Prepared by a verified Expert
Computer Engineering: Comp 2213x2- explain why the following assembly language
Reference No:- TGS02179790

Now Priced at $50 (50% Discount)

Recommended (98%)

Rated (4.3/5)