Write a program that draws an 8 x 8 chessboard, with alternating gray and white
ID: 3539028 • Letter: W
Question
Write a program that draws an 8 x 8 chessboard, with alternating gray and white squares. You can use the SetTextColor and Gotoxy procedures from the Irvine32 library. Avoid the use of global variables, and use declared parameters in all procedures. Use short procedures that are focused on a single task.Explanation / Answer
// Generates chessboard pattern in the bitmap display // R1 contains the address at which the next byte of data // is to be stored, and is also the loop counter. It is // incremented at the start of the loop so is initialised // to the location just before the start of display memory. // As there are 4 bytes per row of the display, and 4 rows of // display per row of the chessboard pattern, there are 16 // bytes per chessboard row. This means that bit 4 of R1 // (bits numbered 76543210) indicates whether an even or odd row // of the chessboard is being generated. // R3 and R4 contain the two patterns to store in the display, // depending on whether an odd or even row is being drawn. MOV [dispmem] -> R1 MOV 1 -> R2 // constant 1 MOV [bwpatt] -> R3 MOV [wbpatt] -> R4 startloop: ADDI R1, R2 -> R1 // increment loop counter MOV R1 -> RA // copy it ROT RA, 4 // shift bit 4 to end AND RA, R2 -> RA // and mask it out MOV 1 -> R0 // compare it with 1 JMPEQ oddrow, RA // jump if on an odd row MOV R3 -> [R1] // store even row pattern JMP endloop oddrow: MOV R4 -> [R1] // store odd row pattern endloop: MOV [endmem] -> R0 // last address to fill JMPEQ end_, R1 // reached it? JMP startloop // no, so loop end_: HALT dispmem: DATA 7F // initial address endmem: DATA FF // end of memory bwpatt: DATA 00001111 // display pattern 1 wbpatt: DATA 11110000 // display pattern 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.