This is my second tutorial for GBA Assembly. If you read the first, you likely noticed it was extremely basic. This tutorial will assume you understood the last one, and build on it. It won't point out opcodes, it won't point out destination and such.. I'll probly comment on blocks of code rather than line by line. Hope it's useful, and enjoy. I guess I should state somethings up here. First, all that's different between this tutorial and the last is that I added in a complete fill of the screen. I added more opcodes, all of which will be described, and also added conditional operators to some. Second, the batch file to make it is still exactly the same. Same commands, and it still makes an elf and a .bin, the .bin being renamable to .agb or whatever else. Tutorial: Newly used opcodes: beq: branch, with a conditional operator. I guess I'll use this chance to describe conditio EIEPFFFDEFCACACACACACACACACACABO À “à€À¨&ave instructions and you can make them execute only on certain conditions. In this case, "eq" is used. The command translates to "branch if the last comparison is equal." Some opcodes have an optional appended s, such as adds, which will set such status flags on things like overflows. If you used just add, the flags would not be set even if something does overflow. cmp: comparison. It takes 2 operands, and compares them. It sets the flags accordingly (equal, less than, greater than, ...). Flag settings should be available in any good arm reference. add: simply adds 2 registers together. first operand is destination, second and third are the registers to add together. As was seen, I used an immediate instead of a register. bl: branch with link. It branches to the label you specify, and puts a return address (address of opcode after the branch) in r14. special registers: pc: Program Counter. It stores the current address of execution. r14: used during bl to store the return address. Assembly: At first I tried to make a stack. I was told the stack functions built in were extremely slow with the GBA RAM, so I decided to try to make my own. It'd end up being about 3-5 instructions per push/pop, so I decided to scratch that and just hard code registers to specific things. I had enough, after all, and assume I will until the end of these tutorials. (Can anyone guess what I'm making? Hint: it was a somehwat popular toy (I guess) that was red with 2 dials... :-) The only change in the main loop is to branch with link to PaintScreen. Nothing real special about it; it is a bl instead of a b though. Then, there's the entirely new function: PaintScreen. This function paints the screen a specific color. The color, as you may have noticed, is stored in r5 as 0xfff (it turns out to be an ugly yellow). r0 is preserved from the beginning of the program as the video ram base address. r5 will be used as the color of the pixel, and r6 is the end of the video ram.. or at least, the length of it. The labels: PaintMain is the main loop of the paint function. PaintEnd will be reached to end the function and return to the main code. Mainloop is, again, the main program loop, because GBA code never needs to end :-) The code: First 3 lines of paintscreen are simply initialization. These registers need to be set that way every time the function executes (or at least r3 does; the others don't change). The main loop of PaintScreen copies the pixel to the video ram address + r3. r3 is incremented by 2 (2 bytes/pixel), and then the next will be put in video ram+ 2, then video ram + 4, etc. As is obvious, add adds r3 and 2, and puts the result in r3, thus incrementing our offset into video ram and allowing us to place the next pixel. We then use cmp to compare the offset (r3) to the length of the video ram (r6; 0x12C00). When they're equal, cmp will set the flags. After than comes "beq PaintEnd". If the offset and the length are equal, the branch will execute. This will go to the end of the function. Otherwise, it won't execute, and the next command, "b PaintMain" will start the loop over again to do the next pixel. At the end of the paintmain function seems something basic. "mov pc, r14". Remember, r14 contains the return address since we used "bl". This simply moves it into the program counter (PC), and the next thing to execute is the instruction after where we branched from (way up at the top, in the main loop, it executes "b mainloop"). And that concludes tutorial 2. I didn't do nearly as much explanation, and wrote it in school as everyone was watching Jurassic park 3. The next tutorial shouldn't be too far off, and I assume 2-3 more until I've completed this... "demo", and then I'll likely write one more to show off at least one mode other than mode 3 (most likely mode 0, or some other tile mode). Hope you found it helpful. -DrkShadow http://drkshadow.no-ip.com/ http://members.corecomm.net/~blairk/