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

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.


#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() {


  // For HW4-A use C

  // For HW4-B use GAS assembly.


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





  return 0;



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.


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]=...


% exit

Script done, file is typescript

% diff typescript typescript-a

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


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.

Posted Date: 3/4/2013 7:34:19 AM | Location : United States

Related Discussions:- Application for build a toy program, Assignment Help, Ask Question on Application for build a toy program, Get Answer, Expert's Help, Application for build a toy program Discussions

Write discussion on Application for build a toy program
Your posts are moderated
Related Questions
Explain procedural logic A procedure, or function, was explained as a set of specific instructions implemented in sequential manner. The data is kept separate from the procedur

What is default constructor? explain it.

how to make basics strong and best logic skills what are the best way to be a expert programmer ? what counts a lot knowledge or practice?

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

Programming Assignment # 1 C and UNIX   The purpose of this assignment is to get you more familiar with Unix/Linux and those constructs of C that are not part of C++. Write a C

I want to take 1.1 as input but when I am declaring it as float the output is given as 1.1000000

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

c program for padovan string   Padovan series are positive integers obtained by the following process: The Padovan series is the sequence of integers P(n) defined by the

Which one would you prefer - a macro or a function? Actually it depends on the purpose of program! - In case of macros, corresponding code is inserted directly into your sou

Define Passing Structure to a Function? A structure is able to be passed as a function argument identical to any other variable. If we are merely interested in one member of a