Homework 4 - Working with a 2D array

As you are aware, we have lab assignments due every week. We also will have several homework assignments this semester, and this is one of them. While the labs are directed, the homework assignments present larger problems that you should break down into smaller problems. You should spend some time thinking about and planning your homework solutions before coding them.

Program Description

You are to create an assembly language program for RISC-V. We have seen how to work with arrays as well as input and output in assembly. Refer to the recent labs as needed.

In this assignment, we will work with 2D data. Higher level programming languages store 2D data as 1D data, with the added convenience of allowing the programmer to select a value using 2 indices. Thus, an 8x8 array of values in C could be accessed as array[r][c] with index r for the row and c for the column. But it's also possible to access the value as array[r*MAXCOL + c], where MAXCOL is the maximum column, as the name implies. In assembly language, we do not have the option of accessing an array the first way (unless you create way to do this, such as with a macro). We will use the second way of accessing array data for this homework.

For this assignment, the data will be an 8x8 array of characters (bytes). This is an example array that we will use.


    chess_board: .byte 
      'R',  'N',  'B',  'Q',  'K',  'B',  'N',  'R',
      'P',  'P',  'P',  'P',  'P',  'P',  'P',  'P',
      '-',  '-',  '-',  '-',  '-',  '-',  '-',  '-',
      '-',  '-',  '-',  '-',  '-',  '-',  '-',  '-',
      '-',  '-',  '-',  '-',  '-',  '-',  '-',  '-',
      '-',  '-',  '-',  '-',  '-',  '-',  '-',  '-',
      'p',  'p',  'p',  'p',  'p',  'p',  'p',  'p',
      'r',  'n',  'b',  'q',  'k',  'b',  'n',  'r'
As you might guess, this is a representation of a chess board, with the pieces in their starting positions.

Part 1 - Print the chess board

Create a function (subroutine) to print the data at "chess_board". Use a loop to do this, print one character at a time, and print a new-line character after each row.

Part 2 - Convert a string to an offset

Given a string such as "a1", compute the offset into the array. (You can hard-code the string into the data section.) Print the string, then a space. Next, print the offset into the array, followed by a space. Then print the character of the piece that is there, followed by a new-line character.

Bonus Part 3 - Make a move

Given a string such as "a1b2", move the piece from square "a1" and put it on square "b2". On the first square, put a symbol indicating that it is empty. Show the initial board, and display it again after the move.

Bonus Part 4 - Make moves based on input

Read the input from the command line, and make the corresponding move. First, get this to work with one move only. Then scale your solution to work for as many inputs as there are in the input stream. This should work using input redirection and piping. Show the initial board, and display it again after each move.

Assumptions

Notes

Here is an example input file.

    e2e4
    e7e5
    g1f3
    d7d5

Make sure that your program works for other inputs, that is, use different inputs to test your program.



More Notes:

You do not have to do all 4 parts

You might find that this assignment is more difficult than you expect. Here is how we will grade this.