Suppose we have a 64-bit word-addressable computer and we want to program it to output a 5x7 character stored as a binary image bitmap (such as the one below) to a memory-mapped display.
Since we have 5 x 7 = 35 pixels per character, we could store a character using 35 bits in a single word. With the least significant bit starting on the left side of the word and with each pixel in the image being represented by the nth bit as shown above, the number "3" above would be stored in memory as: 01110100010000100110000011000101110, followed by 29 unused bits set to 0.
Is this how characters were/are stored in old/modern computers? Or do they use a single byte/word per pixel instead?
If they are stored in this manner, what would the routine in assembly/machine-code (using nothing more than elementary instructions such as bitwise, arithmetic and data transport operations from the computer's Instruction Set Architecture) used to convert this data into an image on the display look like? Would it be something like:
- Store the x and y display coordinate for the current pixel to be updated in a certain register.
- Store the two chosen RGB values (in this case 0,255,0 for green and 0,0,0 for black) in two other separate registers.
- Have two further registers act as counters initialized to 5 and 7 to keep track of the current row and column of the image being rendered.
- Test if the column register is not 0. If it isn't, test if the LSB of the bitmap is set to 1, then AND the respective RGB value register with the x and y coordinate register depending on the result, then MOV that result to the display output register.
- Decrement the row counter register by 1, test to see if it is 0. If it is, then set it back to 5 and increment the y coordinate by 1 and decrement the column counter by 1.
- Shift the register holding the bitmap 1 bit to the left.
- JMP to instruction 4.
Is there a simpler or more efficient way to do this? It seems as though even something as simple as rendering a single small text character takes quite a large number of operations and would take around 200 CPU cycles.
Finally, are there any good books or resources on machine-level code for displaying images from scratch, because I haven't been able to find any as they either gloss over this particular subject or the code is written in a high level language or an assembler using macros, all of which are "cheating" and don't explain what is fundamentally going on at the lowest level.