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

Bubble sort c program, Bubble sort C program: Write a program to defin...

Bubble sort C program: Write a program to define a bubble sort. void main()  {   clrscr();   int a[100],ch,n;   cout   cin>>n;   for (int i=0;i

System programing, #quesdifferentiate betweenrelocatable and self relocatin...

#quesdifferentiate betweenrelocatable and self relocating program with exampletion..

Palindrome, string S convert it to a palindrome by doing chara, C/C++ Progr...

string S convert it to a palindrome by doing chara, C/C++ Programming

Described the differences among a c++ struct & c++ class?, Described the di...

Described the differences among a C++ struct & C++ class? A: The default member & base class access specifies are distinct. It is one of the commonly misunderstood aspects of C+

Please help to solve a c program, Padovan String Problem Description A P...

Padovan String Problem Description A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes s

C program for function of merge , C Program for FUNCTION OF MERGE #inc...

C Program for FUNCTION OF MERGE #include conio.h> #include stdio.h> char cot(char a[],char b[]); void main() {           char a[50],b[50];           clrscr()

Compiler Design - Limit the methods, Rahul is a newbie to the programming a...

Rahul is a newbie to the programming and while learning the programming language he came to know the following rules: ???• Each program must start with ''{'' and end with '

What is the difference among a pointer and a reference?, A: A reference has...

A: A reference has to always refer to some object and, so, must always be initialized; pointers do not have such limits. A pointer may be reassigned to point to distinct objects wh

Program to sort a range of numbers with insertion, Program to sort a range ...

Program to sort a range of numbers with Insertion: /* define variable */ const int max=29000; int list[max]; FILE *fp; clock_t start,end; char any1[8];

Program to define an array in c, Program to define an array in c: Writ...

Program to define an array in c: Write a program to define an array and print the value of array. void main() { int a[10]={0,11,21,34,44,75,46,57,88,89},i,j,k; clr

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