Jump to content





Code As You Go

Posted by walker7, 25 November 2017 · 99 views

assembly computer 8-bit 16-bit 6502 Motorola 68000 Z80 65C02 coding code as you go

This next section is a big one.  Wouldn't it be great if you could test code as you programmed it?  Well that's where Code-As-You-Go comes into play.
 
The mode can be accessed with a dedicated button on a keyboard.  It's labeled "CAYG."
 
 
Take a look at this:
Posted Image
 
That's the code as you go screen.  On the panel at the right, you can enter the data you want to test.  On the upper right of the screen is the address that the code will assemble to.  In this example, the written code will compile at address $001404.  You could instead have it display which line of the source code the code will go in.
 
First, give the subroutine a name.
Posted Image
In this example, we have a routine called "TetrisLFSR."  This will be a Motorola 68000 version of the NES Tetris RNG routine.
 
The NES version of Tetris iterates its RNG (a 16-bit LFSR) in the following manner:  Set the output bit to the XOR of bits 1 and 9, and right-shift that input into the RNG.  We will replicate this routine as we enter the code.
 
For this test, enter the input in d0.  We need to enter a 16-bit value.  Using a mouse, click on the fourth-to-last digit of the d0 register, then type "7259."
Posted Image
The digit highlighted in green is the cursor.  Note that the register values are displayed in hexadecimal.  If you enter an invalid hexadecimal digit, nothing happens.  When you enter the last digit, the cursor stays there.  (If it were an A-register, the cursor would be red.)
 
Now, time for the first instruction.  Type "move.b", tab, then "d0,d2", and hit Enter (if you hit Space, it will tab for you).  When you press Enter, the last line of code you wrote is automatically executed in the CAYG window, and its machine language code appears in the window as well.  In M68K assembly, the instruction "move.b d0,d2" is represented by $1400.  The screen looks like this:
Posted Image
Note that after you typed the code line, that instruction automatically executed.  The last byte of d0 is $59, so the last byte of d2 is now also $59.
 
The next two instructions are "move.w d0,d1" and "lsr.w #8,d1".  These are necessary to retrieve the upper byte of a 16-bit value in d1.
Posted Image
After the second line was typed, d1 became $7259.  After the third line, it became $0072.  In the machine code box is E049, which is the code for "lsr.w #8,d1."  Remember, only the compiled code for the last line you typed appears in the machine code box.
 
Next, we want to take the XOR of bits 1 and 9 of the bytes in d1 and d2.  Since 1 and 9 differ by exactly 8, no shifting of either byte is needed.  Just XOR the bytes by typing "eor.b d2,d1", then pressing Enter.
Posted Image
Register d1 is now equal to $2B, which is the XOR of $72 and $59.  It is bit 1 from this value we need to extract and get into the X (extend) flag.
 
To do this, type "lsr.b #2,d1", and press Enter.
Posted Image
The value in d1 became $0A.  But more importantly, look at the X and C flags.  They lit up, so their value is 1.  Any flag that is clear appears as white-on-black, while a set flag is indicated by the opposite color scheme.  Since the XOR of bits 1 and 9 of our 16-bit value was 1, a 1 will be right-shifted in to get the new RNG value.
 
Here is the last piece of the puzzle.  Now that we have our output bit in X (and C), we can use a "roxr" instruction to shift it in.  Type "roxr.w #1,d0", and hit Enter.
Posted Image
 
And there you have it.  The new RNG value is $B92C.  With the ability to see the code execute as you type it, coding will become as easy as pie.
 
You could also toggle register updating off/on, and you could also move your cursor to any line in the code, and press a certain button to step through the code and see the results.
 
After finishing the code, press the CAYG button again.  All the code you wrote in the CAYG screen will be placed at the place in the source code you were at when you went to this screen.  You can then edit it, delete it, or change it as normal.
 
 
All in all, the code-as-you-go feature could be a breakthrough for future assemblers.  No matter whether it's 6502, M68K, Z80, or anything else, it's the next innovation in coding.






December 2017

S M T W T F S
     12
3456789
10111213141516
17 181920212223
24252627282930
31      

Recent Entries

Recent Comments

Categories