I've embarked on first assembler project involving AVR assembly. I'm having fun so far, but have run into something I'd like some advice on if at all possible.
First a description of my project: I'm using an ATmega 328P to output a display in PAL in greyscale using composite video. That seems to be working fine in the sense that I can produce the 4us + 8us pulse and then the 52us of time where I can output different bars of grey scale. This is simply looped to output the same line infinitely.
I'm now progressing on to the next stage of trying to display a pattern on the screen based on a bit pattern in memory.
My first attempt will involve splitting the 52us into cpu cycles per line. So 614 cycles [52(us) x 8(MHz)] then figure out how many pixels can be displayed.
That is determined by how many cycles I use in machine code to process a given pixel/byte and dividing 614 by that.
It's this process that I'm trying to optimise.
The way I figure it, I need to:
Read a byte and process it. This means processing 8 pixels at a time (1 bit = 1 pixel i.e. monochrome output)
Do a bit-wise AND on the byte with 128 to determine the value of bit 7
Is result 0? If so then change output voltage so that black is selected
Otherwise, set the output voltage so that white is selected
Rinse and repeat for each bit field (i.e. 64, 32, 16, 8, 4, 2, 1)
My issue here is that the code I have written seems very inefficient and I was wondering if there is another, better, way? The more efficient I can make this code the more pixels I can display per line.
(read byte from memory to byteReg register) ANDI byteReg, 128 // AND data byte with 128 (bit 7) BREQ SetBack128 // If result is 0 then bit not set so we jump to make current colour black (bit 7) (current colour to white) // Otherwise we run the code to set current colour to white BackFromSetBlack128: // Label used by set colour to black (bit 7) routine to jump back ANDI byteReg, 64 // AND data byte with 64 (bit 6) BREQ SetBack128 // If result is 0 then bit not set so we jump to make current colour black (bit 6) (current colour to white) // Otherwise we run the code to set current colour to white BackFromSetBlack64: // Label used by set colour to black (bit 6) routine to jump back (rinse and repeat for each bit field) SetBack128: (code to set composite output to black) RJMP BackFromSetBlack128 SetBack64: (code to set composite output to black) RJMP BackFromSetBlack64 (rinse and repeat for each bit field)