$30
Programming Lab 6C
Sliding 15-Puzzle
Topics: Compare and branch instructions, nested loops, pointers.
Prerequisite Reading: Chapters 1-6
Revised: January 22, 2021
Click to download
Lab6C-Main.c
Background1
: A “sliding” puzzle is a combination puzzle that challenges
a player to move tiles on a two-dimensional array of cells so as to establish a certain end-configuration. Finding moves and the paths opened up
by each move within the two-dimensional confines of the array are important parts of solving sliding block puzzles.
Assignment: In this lab, the puzzle is displayed within a 4𝑥4 array of 16
cells. An image has been divided into 16 tiles of 60𝑥60 pixels each with
15 of the tiles placed into the array. Each pixel is stored as a 32-bit value
containing 8 bits each of its red, blue, green and intensity components.
The main program will compile and run without writing any assembly.
However, your task is to create equivalent replacements in assembly language for the following two functions found in the C main program.
void CopyCell(uint32_t *dst, uint32_t *src) ;
void FillCell(uint32_t *dst, uint32_t pixel) ;
Function CopyCell copies all the pixels of one cell to another and
FillCell fills a cell with white pixels. Parameters dst and src contain the address of the pixel in the top left
corner of a cell. The original C versions have been defined as “weak” so that the linker will automatically replace
them in the executable image by those you create in assembly; you do not need to remove the C versions. This
allows you to create and test your assembly language functions one at a time.
Test your code using the main program. Tiles may be moved only if they are moved to an adjacent empty cell.
When the program starts, it performs a sequence of random moves and then displays the scrambled image that
results. The objective is to use the fewest number of moves to unscramble the tiles so that the image is displayed
correctly. Touching a tile that is adjacent to an empty cell will move the tile into the empty cell. The program
records a history of up to 1000 such moves; touching the empty cell undoes the most recently recorded move.
Pressing the blue pushbutton will undo all moves to display the original (unscrambled) image.
1 https://en.wikipedia.org/wiki/Sliding_puzzle