ASSEMBLY LANGUAGE PROGRAMMING SETTING A BLOCK OF MEMORY TO A VALUE Last time we created a program which took a start and an end block and cleared the memory. This time, we are going to set a block of memory to a specified value instead of zero. This poses an interesting problem. There are not enough 8-bit registers to pass the value along with the memories. As I mentioned last time, we could set a block of memory aside to pass parameters. However, this doesn't make the code very flexible. I also mentioned passing parameters on the stack. This is the method I chose. There are at least two methods of doing this. One can rely on the caller to remove parameters from the stack when the subroutine returns, or one can program the subroutine to clean the stack. I personally prefer the latter method because it puts less of a burden on the programmer later, though it makes the subroutine code slightly longer. The algorithm for setting a memory block to a value is exactly the same as the algorithm for clearing that block of memory with the only exception that we must store the value instead of zero. Now for a rundown on how to use the stack to pass parameters. First, you decide what order you want them passed then document it. If you don't document it, you will easily forget what order you specified and end up tying your code into knots. Also, it is imperative to let the prorammers know how to use your subroutine. Now, you use "Stack Pointer Relative" addressing to access the data within your subroutine. You must take into account that the return address is stored on the stack immediately before your parameters and it is two bytes wide. You also must realize that if you PSHS anything, you must add that to your offsets as well or you will not obtain the expected data. The best way to explain this concept is through example. You can see how I did it by looking at the code in PART3.ASM or PART3.LST. Do not allow yourself to be confused. A little thought should make it fairly clear how it works. A note about how stack parameters are specified. A parameter specified by n,S is a parameter which is passed on the stack with the n being the offset without the return address being included. To call this routine where 0,S is the value which will be stored in the memory, 1,S is the start address in the form block, offset, and 4,S is the end address in the same form. First you would push A,X with the end address onto the stack, then A,X with the start address onto the stack than A with the value onto the stack. The you call the routine normally and everything is removed from the stack before the subroutine returns. (Note that you don't have to use A and X, but this is the easiest way to get the parameters on the stack in the correct order.) Until next time, have fun and keep programming.