The program goes something like: 1. allocate space for board state 2. initialize
ID: 3664665 • Letter: T
Question
The program goes something like: 1. allocate space for board state
2. initialize board state with zeros
3. Begin loop
a. print board state b. ask for row c. ask for column d. ask for value e. set board (row,column) to value f. go to (3a)
The input parameter to this function is the board state. The function prototype would be defined as follows: void display_board(BoardObject board) { … }
The letter ‘r’ is used for red game pieces while the letter ‘w’ is used for white game pieces. The following list of characters can be used with the $print_char system call to denote pieces in individual squares (see appendix B of the textbook):
? ASCII 32 (spacebar): empty square.
? ASCII 114 (‘r’): regular red game piece.
? ASCII 82 (‘R’): red king.
? ASCII 119 (‘w’): regular white game piece.
? ASCII 87 (‘W’): white king.
? ASCII 219: an empty square of the opposite color
Each integer represents a square on the board. Given a row and column, the location on the board can be referenced to assign a value as follows: board[row*8+column]=;
You can multiply the row number “row” by 8 and add the column number “column” to get the information about the square located at (row,column).
If a board location has no game piece, its value is “0”. If the board value is non-zero, there is a game piece. The bits of each board location are defined as follows:
for example :
? board[2*8+6]=0x03 ? A white checker is located at (2,6) with bits 0000 0011
board[r*8+c]=0x01 ? A black checker is located at (r,c) with bits 0000 0001
Examples of how your board might look: MIP Row: Figure 2: Board with no pieces placed Row: Figure 3:board with two regular pieces and two kings placed.Explanation / Answer
HLA assembly code
program MyCheckerBoard;
#include("stdlib.hhf");
static
xC:int8; // Counts 8 squares in each of the row.
yC:int8; // Counts 4 pairs of squares in each of the column.
ColCount:int8; // Counts 4 rows in each of the square.
begin myCheckerBoard;
mov(0,yC);
while(yC< 4 ) do
// Show a row which begins with black color
mov(4,ColCount);
repeat
mov(0,xC);
while(xC< 4) do
stdout.put( "---- " );
add(1,xC);
endwhile;
stdout.newln();
sub(1,ColCount);
until(ColCount=0);
// Show a row which begins with white color
mov(4,ColCount);
repeat
// Display a single row having spaces for this row consisting of squares:
mov(0,xC);
while(xC< 4) do
stdout.put( " ----" );
add(1,xC);
endwhile;
stdout.newln();
sub(1,ColCount);
until(ColCount=0);
add(1,yC);
endwhile;
end myCheckerBoard;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.