This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:comporg:spring2025:projects:dapx [2025/03/02 23:52] – [Preserving our Registers] cgrant9 | notes:comporg:spring2025:projects:dapx [2025/03/09 15:44] (current) – [Masking] Made asm code format consistent tkastne1 | ||
---|---|---|---|
Line 10: | Line 10: | ||
=====Preserving our Registers===== | =====Preserving our Registers===== | ||
- | For our debug to work with any given code we need to preserve everything that we may be using; part of this is to save the contents | + | For our debug to work with any given code we need to preserve everything that we may be using; part of this is to save the contents |
To do this we can set up a local stack to save the contents of our register while we use them with the instructions: | To do this we can set up a local stack to save the contents of our register while we use them with the instructions: | ||
Line 16: | Line 16: | ||
PUSH BP | PUSH BP | ||
MOV BP, SP | MOV BP, SP | ||
+ | </ | ||
+ | Once we set up a local stack, we can push all of our registers onto this new stack, while still having access to the previous stack with some manipulations.\\ | ||
+ | |||
+ | Once you have done everything you need to, you need to restore your registers and stack.\\ | ||
+ | For the registers, simply pop them off the stack in reverse order, i.e if you pushed 0-13, you will pop 13-0. | ||
+ | The stack can be just as simple as that, or more difficult depending on your approach. The simpler approach is to do the reverse of creating a local stack, that is: | ||
+ | < | ||
+ | MOV SP, BP | ||
+ | POP BP | ||
</ | </ | ||
=====Preserving our Textures===== | =====Preserving our Textures===== | ||
+ | Along with preserving your register you need to preserve your texture and region, this should be done after preserving at least one of your registers, as we need to use a register to get the data to preserve.\\ | ||
+ | Once we have preserved our registers, simply use the ' | ||
+ | < | ||
+ | IN R0, GPU_SelectedTexture | ||
+ | PUSH R0 | ||
+ | IN R0, GPU_SelectedRegion | ||
+ | PUSH R0 | ||
+ | </ | ||
+ | And just like our registers, we need to pop them in reverse order to restore them when we're done: | ||
+ | < | ||
+ | POP R0 | ||
+ | OUT GPU_SelectedRegion, | ||
+ | POP R0 | ||
+ | OUT GPU_SelectedTexture, | ||
+ | </ | ||
=====bitwise operations===== | =====bitwise operations===== | ||
====OR==== | ====OR==== | ||
====AND==== | ====AND==== | ||
+ | The AND op code will do an and comparison of two values | ||
+ | < | ||
+ | mov R0, 0x00F00000 | ||
+ | mov R1, 0x12689649 | ||
+ | and R0, R1 | ||
+ | </ | ||
+ | This code will leave us with 0x00600000 because every other value was put into and with a zero. | ||
====NOT==== | ====NOT==== | ||
====NAND==== | ====NAND==== | ||
Line 29: | Line 60: | ||
====SHIFT==== | ====SHIFT==== | ||
- | ===Shift Right==== | ||
===Shift Left=== | ===Shift Left=== | ||
+ | A shift left can be done with the op code SHL | ||
+ | < | ||
+ | mov R0, 0x00F00000 | ||
+ | mov R1, 4 | ||
+ | shl R0, R1 | ||
+ | </ | ||
+ | This code will give R0 the value 0x0F000000 because the original value was left-shifted by 4 bits. | ||
+ | ===Shift Right==== | ||
+ | There isn't an op code provided by Vircon32 for right shifts, so we must shift left by a negative value. | ||
+ | < | ||
+ | mov R0, 0x00F00000 | ||
+ | mov R1, -4 | ||
+ | shl R0, R1 | ||
+ | </ | ||
+ | This code will give R0 the value 0x000F0000 because we shifted the original value to the left by -4 bits. | ||
=====pseudocode===== | =====pseudocode===== | ||
Line 63: | Line 108: | ||
ASCII code for 0 --> decimal 48, hexadecimal 0x30 | ASCII code for 0 --> decimal 48, hexadecimal 0x30 | ||
ASCII code for x --> 120 | ASCII code for x --> 120 | ||
- | ASCII code for [ --> | + | ASCII code for [ --> |
ASCII code for ] --> 93 | ASCII code for ] --> 93 | ||
ASCII code for : --> 58 | ASCII code for : --> 58 | ||
Line 81: | Line 126: | ||
====Masking==== | ====Masking==== | ||
+ | We need to get a nibble on it's own, to do this we can use a bit mask | ||
+ | A mask only allows certain bit positions to be either 1 or 0, and forces everything else to be 0 | ||
+ | |||
+ | This is done with the **and** operator | ||
+ | |||
+ | In order to get the most significant nibble we would want a mask of 0xF0000000 (0b11110000000000000000000000000000) | ||
+ | |||
+ | < | ||
+ | mov | ||
+ | and | ||
+ | </ | ||
+ | |||
+ | To get the second most significant nibble, instead of creating a new mask by hand, we can shift the old mask over by a nibble ever time we loop | ||
+ | |||
+ | We should have a register keep track of our loop count | ||
+ | |||
+ | < | ||
+ | mov | ||
+ | imul R2, | ||
+ | |||
+ | mov | ||
+ | shl | ||
+ | |||
+ | and | ||
+ | </ | ||
====Shifting==== | ====Shifting==== | ||
Line 89: | Line 159: | ||
===Displaying=== | ===Displaying=== | ||
+ | Because we already have the debug function, we can use that to display all of the hex values needed | ||
+ | |||
+ | The format is identical for every address, and goes as the following: [address]: | ||
+ | |||
+ | We can print the brackets and colon manually and leave the address and values to the debug function | ||
+ | |||
+ | < | ||
+ | mov | ||
+ | out | ||
+ | mov | ||
+ | out | ||
+ | out | ||
+ | </ | ||
+ | |||
+ | Repeat this for ' | ||
+ | |||
+ | Utilize the debug function to print the address and value as shown in the following | ||
+ | |||
+ | < | ||
+ | push R2 ;R2 is the current address | ||
+ | mov | ||
+ | push R3 | ||
+ | push R4 ;Ypos | ||
+ | call _debug | ||
+ | |||
+ | mov | ||
+ | push R3 | ||
+ | mov | ||
+ | push R3 | ||
+ | push R4 ;Ypos | ||
+ | call _debug | ||
+ | </ | ||
+ | |||
+ | All of this code should be run for every address, stepping from the start value to the end value | ||
+ | |||
+ | We will need to setup a loop with an exit condition | ||
+ | |||
+ | ===pseudocode=== | ||
+ | < | ||
+ | MOVE THE STARTING ADDRESS INTO A DEDICATED REGISTER (current address) | ||
+ | UNTIL WE HAVE PASSED THE FINAL ADDRESS: | ||
+ | TEST IF THE CURRENT ADDRESS IS GREATER THAN THE FINAL ADDRESS | ||
+ | SHOULD IT BE GREATER SKIP TO AFTER THIS LOOP | ||
+ | | ||
+ | | ||
+ | | ||
+ | REPEAT | ||
+ | </ | ||
======debugregister function====== | ======debugregister function====== | ||
=====dapX imagery===== | =====dapX imagery===== | ||
Line 99: | Line 217: | ||
{{: | {{: | ||
{{: | {{: | ||
+ | |||
+ | ====dap1==== | ||
+ | {{: | ||
+ | {{: | ||
+ | |||
+ | ====dap2==== | ||
+ | {{: | ||
+ | {{: | ||
======Debug Registers====== | ======Debug Registers====== |