User Tools

Site Tools


notes:comporg:spring2025:projects:dapx

This is an old revision of the document!


DAPX

stack operations

PUSH

POP

referencing relative to SP/BP

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 of our registers.

To do this we can set up a local stack to save the contents of our register while we use them with the instructions:

PUSH BP
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

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' instruction to get information from the GPU port like this:

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, R0
POP  R0
OUT  GPU_SelectedTexture, R0

bitwise operations

OR

AND

NOT

NAND

NOR

XOR

XNOR

SHIFT

Shift Right

Shift Left

pseudocode

debug

SET DATA
SET X
SET Y
SET POSITION TO LEFTMOST NIBBLE
UNTIL WE HAVE DISPLAYED ALL NIBBLES:
    OBTAIN NIBBLE AT POSITION
	SHOULD NIBBLE BE GREATER THAN OR EQUAL TO TEN:
	    ADD SEVEN TO ITS VALUE
	ADD FORTY EIGHT TO ITS VALUE
	DISPLAY NIBBLE AT X, Y
	INCREMENT X ACCORDINGLY
	ADJUST POSITION TO NEXT NIBBLE TO THE RIGHT
REPEAT

In your code you will want to put

%include "debug.s"

at the very end of your code. THIS IS VERY IMPORTANT. If you include debug.s at the top of your code, the hexadecimal values may print but the remainder of the program in which you called __debug may not function as expected.

debug function

Formatting

Beyond getting your values to be displayed you also need to include “0x” to signify that the number you are displaying in hexadecimal. It is important to know that the 0 and x have a number assigned to them in ASCII code which are as follows:

ASCII code for 0 --> decimal 48, hexadecimal 0x30
ASCII code for x --> 120
ASCII code for [ --> 92
ASCII code for ] --> 93
ASCII code for : --> 58

Knowing this, we can now select where we want to display these values by simply calling the following:

    mov R0, 48 ; ASCII code for 0 is moved into RO
    out  GPU_SelectedRegion, R0 ; Selecting region
    out  GPU_DrawingPointX, R2  ; Providing X axis location
    out  GPU_DrawingPointY, R3  ; Providing Y axis location
    out  GPU_Command, GPUCommand_DrawRegion ; Displaying
    iadd R2, 9 ; Spacing logic

Getting your value

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   R1,   0xF0000000  ; Creating the mask
   and   R1,   R0          ; R0 is the original value

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   R2,   R3          ; R3 is the loop count
   imux  R2,   -4          ; Left shift bits per nibble

   mov   R1,   0xF0000000  ; Creating the mask
   shl   R1,   R2
   
   and   R1,   R0          ; R0 is the original value

Shifting

To ASCII

debugmemory function

Displaying

debugregister function

dapX imagery

dap0

dap1

Debug Registers

Printing out R:

Printing registers

Debugging our debugregs Subroutine

Calling debugregs

notes/comporg/spring2025/projects/dapx.1741062529.txt.gz · Last modified: 2025/03/04 04:28 by tkastne1