Question: Submit assignments using MyLearningSpace following the assignment and coding specifications . You are given the following code. ORG $1000 move.l #$FF00,A6 jsr one stop #$2700

Submit assignments using MyLearningSpace following the assignment and coding specifications .

You are given the following code.

ORG $1000

move.l #$FF00,A6

jsr one

stop #$2700

one LINK A6,#-6 ; reserve space for x, y, z

MOVE.W #1,-2(A6) ; initialize x

MOVE.L #6,D1 ; y = x * 6

MULU -2(A6),D1

MOVE.W D1,-4(A6)

PEA.L -6(A6) ; pass parameters

PEA.L -4(A6)

PEA.L -2(A6)

JSR two ; and call the routine <==== contents of z at this point in the code

UNLK A6

RTS

two LINK A6,#-4 ; reserve space for m, n

MOVEA.L 8(A6),A4 ; initialize m

MOVE.W (A4),-2(A6) <==== draw stack contents

MOVEA.L 12(A6),A0 ; initialize n

MOVE.W (A0),-4(A6)

MOVE.W -2(A6),D1 ; calculate m + n

ADD.W -4(A6),D1

MOVEA.L 16(A6),A4 ; and return the sum

MOVE.W D1,(A4)

UNLK A6

RTS

For the above code (a) Draw the stack contents when the line of code indicated by the arrow and shown in bold has completed execution. Be sure to label entries, provide contents (if any) and indicate their width. (b) What is in z after the return from subroutine two? Submit answer as a text file.

The file test_red.X68 contains a portion of the code required to draw a red rectangle into the screen buffer. The program requires the following include files: red_rectangle.bin , buffer_util2.X68 and graphic_util.X68 . We have provided the subroutine red_rectangle which will draw a red rectangle into the screen buffer. (You cannot see the source code for red_rectangle - it is stored in the binary file red_rectangle.bin.) The red_rectangle subroutine has a C equivalent call as follows:

void red_rectangle( bufferType *sb, rectangleType *r );

with bufferType defined in buffer_util2.X68 and rectangleType defined in test_red.X68. Remember, a C structure is essentially a parameter block.

Provide the necessary code to call red_rectangle from within test_red.X68. Modify the comments at the top of the program and place your code in the section marked *** INSERT YOUR CODE HERE. Other than these two sections, do NOT modify any other portion of the program; do not modify the code in the include files.

The program should draw 2 red rectangles on a 600 x 400 640 x 640 screen: (a) a red rectangle with width 60 and height 400 at position x,y = (450,30) (b) a red rectangle with width 350 and height 200 at position x,y = (50, 100) You are drawing both rectangles to the same screen buffer so you should have two calls to red_rectangle.

A subroutine to draw a rectangle into the screen buffer has a C equivalent call as follows: void fill_rectangle( bufferType *sb, rectangleType *r, int32 colour, bool8 fill ); Where:

bufferType (buffer_util2.X68) and rectangleType (test_red.X68) are as defined in the previous question

colour defines the colour of the rectangle and the fill colour (if any)

fill is an 8 bit boolean argument that indicates if the rectangle is to be filled or not filled.

Use buffer_util2.X68 and graphic_util.X68 from the previous question. You will:

Write the fill_rectangle subroutine using standard C calling conventions to the specification stated above.

Write a subprogram subroutine to prompt the user for the size of the screen.

Check that the data provided is within the 640 x 480 bounds. within the range 640 x 480 to 1000 x 1000.

If the data is not correct, ask the user for more input.

The subprogram subroutine should populate bufferType appropriately.

Write a subprogram subroutine to prompt the user for the position and size of a rectangle, its colour, and whether it should be filled.

To simplify the colour entry, give the user a choice of at least 6 colours and have them specify only one letter or number. For example, Select a colour: red (r), blue (b) .... or red (1), blue (2). **

Assume that the data entered for this subprogram subroutine will be correct; no error checking required.

The subprogram subroutine should populate rectangleType appropriately.

The subprogram subroutine should return the colour in the $00BBGGRR format in a register.

The subprogram subroutine should return the fill selection as an 8-bit boolean in a register.

**BONUS: Write a subprogram subroutine to let the user specify the colour exactly by providing the decimal values for the red, green and blue components. For example, if the user specified R = 0, G = 0 and B = 255, the colour would be a dark blue; while R = 255, G = 248, and B = 220 would be off-white.

Your main program should draw at least four rectangles of different colours and sizes at various locations on the screen. At least two of the rectangles should be filled and two should not be filled rectangles.

For the following C code, assume all integers are 16 bits in length.

main()

{

int x,y,z;

*!! insert call to an assembly routine to prompt for and read x and y (positive integers greater than 0) from the keyboard using I/O tasks

z = percent_diff(x,y);

*!! insert call to an assembly routine to output z to console using I/O tasks

}

int difference (int e, int f)

{

int diff;

diff = e - f;

if (diff < 0)

diff = -diff

return(diff);

)

int percent_diff(int a, int b)

{

int c,d,pd;

d = difference(a,b);

c = (a+b)/2;

c = (a+b)

pd = d/c * 100;

pd = (d * 100 * 2)/c<== return the integer portion only

return (pd);

}

Write the equivalent code in assembly language using standard C calling conventions. Remember that C code always generates a stack frame. Assume that returned data will be in either D0 (by value) or A0 (by reference).

Test the program with at least three test cases, include x < y and x>y. NOTES:

C programs only have a single point of entry which is the function main. Because main is a function, it has a local area for variables and is therefore coded in assembly language like a standard subroutine. We have not yet covered how this main function is called. For the purposes of this exercise, you will have an assembly routine whose sole function is to call main (acts like the operating system passing control to this application).

Since I would like you to be able to run this code with various inputs, I have noted points where you will call assembly routines to handle input/output. You will code these routines using standard EASy68k I/O tasks. (Normally, the C code would use scanf/printf which would then do operating system calls to handle the I/O at the lowest level. We will bypass the scanf/printf and directly handle the I/O ourselves.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!