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

Webcam driver static library or dll required for windows, Webcam Driver sta...

Webcam Driver static library or DLL required for Windows I want a .dll or .lib file using which i will take a snapshot from the webcam and it can't turn on the webcam LED while

Abstract class Employee , I have to add virtual void calculatePay and virtu...

I have to add virtual void calculatePay and virtual void displayEmployee. How to I implement that in Salaried and Hourly Employee?

Working with files in cpp, Operation Files 2.1. Your program should open an...

Operation Files 2.1. Your program should open and read the file specified by the first command line argument of the program. 2.2. The first line of the file contains an integer

Described the scope resolution operator?, A: It allows a program to referen...

A: It allows a program to reference an identifier in global scope which has been hidden by another identifier along with the same name in the local scope.

A palindrome is a string that reads the same from both the e, submitting so...

submitting solutions in C language should not use functions from / as these files do not exist in gcc

What is threaded binary tree, Threaded binary tree: Consider the linked il...

Threaded binary tree: Consider the linked illustration of a binary tree 'T.  Approximately half of the entries is the pointer fields 'LEFT' and 'RIGHT' will have null elements. Th

Print the sorted output on the console, Question 1 Describe the theory beh...

Question 1 Describe the theory behind class templates and function templates along with relevant programming examples Question 2 With the help of suitable programming example

Structures, how to define the structures

how to define the structures

Radix, a popular joke among computer is to say............

a popular joke among computer is to say............

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