Application for build a toy program, C/C++ Programming

Assignment Help:

With this assignment you will build a toy program that manipulates pointers to integers. You will develop the same main program fragment in both C and Assembler. Thus, you'll get two homeworks from this exercise, HW3-A and HW3-B.

The main ideas in these assigments are to understand the array-pointer duality in C and understand the relationship between pointers and addressing in assembly.

Getting Started

Here is a template C program to get you started. You'll need to fill in the blanks to complete.

#include

#define SZ 7

int* a[SZ];

int x, y, z;

void populate() {

  x = 1;

  y = 2;

  z = 3;

  a[0] = &x;

  a[1] = &y;

  a[2] = &z;

  a[3] = a[0];

  a[4] = a[1];

  a[5] = a[2];

  a[6] = a[3];

}

void printall() {

  int i;

  for (i = 0; i < SZ; i++) {

    printf("a[%1d]=%1d, ", i, *(a[i]));

  }

  printf("x=%1d, y=%1d, z=%1d\n", x, y, z);

}

void add1each() {

  // FILL THIS IN

  // For HW4-A use C

  // For HW4-B use GAS assembly.

}

int main(int argc, char* argv[]) {

  populate();

  printall();

  add1each();

  printall();

  return 0;

}

Running

When this program runs, main() calls populate() to initialize the values for global variables, x, y, z, and the pointers in the array, a. Here is a diagram (that you'll need to complete) of those global variables.

HW4-A Instructions

1. Complete the diagram by filling in the lines representing pointer values.

2. Implement the body of the function add1each() in C. The function should add one to each referenced element of the array. Note that some elements are shared so will be incremented more than once.

3. Compile and run your program using the following, ?% script

4. Script started, file is typescript

5. % ./hw4a

6. a[0]=1, a[1]=...

7. a[0]=...

8. % exit

9. Script done, file is typescript

10. ??When you are done, the file typescript will contain a transcript of everything you typed with computer's responses.

Submit

For HW4-A, submit three things:

  • Your diagram with pointers. This can be a PNG file--take a picture of your drawing, or an MS Word document or an SVG document from a drawing tool like Inkscape.
  • Your C program file.
  • Your typescript file.
  • Do not submit ".o" files, nor the executable file
  • Do not submit any other write-ups as MS word documents or any other write-ups, as the grader will just throw these away. If you need comments put them into your source code.

 

HW4-B Instructions

Implement the function add1each() using GAS in-line Assembly. You will want to pay particular attention to addressing modes used for operands.

The implementation of add1each() using GAS should perform exacly the same pointer dereferencing as your C program. Thus, when run, your GAS program should produce exactly the same results as with the C program. To verify this, save the session from the C program, run the GAS program and "diff" the results.

% cp typescript typescript-a

% script

Script started, file is typescript

% ./hw4b

a[0]=1, a[1]=...

a[0]=...

% exit

Script done, file is typescript

% diff typescript typescript-a

If no differences are reported then the output of the two programs exactly matches.

Submit

For HW4-B, One file containing:

  • Your C program file with in-line assembly implementation of add1each().
  • Do not submit ".o" files, nor the executable file
  • Do not submit any other MS word documents or any other write-ups, as the grader will just throw these away. If you need comments put them into your source code.



Related Discussions:- Application for build a toy program

Stack, Implement multiple stacks in a single dimensional array. Write algor...

Implement multiple stacks in a single dimensional array. Write algorithms for various stack operations for them.

M - algorithm corrections, Of course it is C[i] = A[i] + B[i].It was a typi...

Of course it is C[i] = A[i] + B[i].It was a typing mistake,never mind. You just understand the concept. 27-1 b. for grain-size=1 n=A.length grain-size=1 r=n for

C program to construct a structure , c program to construct a structure: ...

c program to construct a structure: struct sensus                 {                                 char name[30];                                 long int population;

Minimum shelves, Write a program that finds the minimum total number of she...

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

Decode the code, Smugglers are becoming very smart day by day. Now they hav...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Compass bearing, write a c program that converts compass bearings into dire...

write a c program that converts compass bearings into direction

Which constructor gets called while i create an array of , Which constructo...

Which constructor gets called while I create an array of Fred objects?

AREAS, Write a program to find the area under the curve y = f(x) between x ...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Creates and implements a class to represent the queue, Purpose This ass...

Purpose This assignment is an exercise in implementing the queue ADT using a singly-linked list. This assignment also introduces the concept of templates. Assignment Th

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd