Archived

This topic is now archived and is closed to further replies.

Debug Registers?

This topic is 6355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

High there, I''ve been studying the Intel Cpu architechure and was looking at the Debug Registers. There are 8 Debug registers which are quite usefull when debugging your asm programs. But now let''s say your done you game, it''s ready to go to market is it ok to use the Debug registers as normal registers? Cause you could make graphics loops which only use registers, no mem variable which would speed it up significanlty, I think! So does anybody use these registers for anything other than Debugging? Thanks, Ben

Share this post


Link to post
Share on other sites
ben, since you seem to be using only ASM, I was wondering if you could take a look at this code and tell me if there''s something wrong with it. Thanks!

(I tested it on a simple program, and it does exactly what it''s supposed to do, and then I tested it on my original program, and it reboots the PC. Any ideas?)

The code is for Watcom C++!!

It has to draw a horizontal line in mode 13h!

    
void HLine(int x1, int x2, int y, byte color)
{
_asm
{
// EDI = A0000+(y*320+x)
// ECX = (x2-x1) (the singles loop adds one anyways)

mov edi, 0A0000h

mov edx, [y]
shl edx, 6
mov eax, edx
shl eax, 2
add eax, edx
add edi, eax
mov eax, [x1]
add edi, eax
mov ecx, [x2]
sub ecx, eax

// EDX = color

mov dl, [color]
mov dh, dl
mov ax, dx
shl eax, 16
mov ax, dx

// EBX = ECX % 4 (modulus)
// Finds out how many single bytes need to be placed on the screen

mov ebx, ecx
and ebx, 3

// ECX = ECX / 4 (get''s the number of DWORD''s to be placed on screen)
shr ecx, 2
repeat:
mov [edi], eax
add edi, 4
dec ecx
jnz repeat

singles:
mov [edi], dl
inc edi
dec ebx
jns singles
}
}



Thank you very much!


..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
btw, I already know of a few flows with that function that I have to fix (for accuracy) but I''m pretty sure they''re not the cause for the reboot. It has something to do with the address, and I have no idea what it might be


..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
These debug registers are VERY SLOW - each "mov" takes 15..20 clocks.
Besides, these "mov"s are serializing instructions - it means they break pipelining.

And these instuctions are available only on privilege level #0,
so this code cannot be ported to any OS besides DOS

Share this post


Link to post
Share on other sites
Wow! My friend just got a PIII 733Mhz ship for $359 CANADAIN!! Cpu's have gone cheap! Anyhow gladiator here's what I would try, later you can try to optimize by taken out the mul and using shift's but it's easy to go wrong and end up calculating 0's and stuff, so stick to the mul for now...

            
void HLine(int x1, int x2, int y, byte color)
{
_asm
{
// EDI = A0000+(y*320+x)
mov edi, 0A0000h

mov eax, [y] // move in y

mov ebx, 320 // use 320 as other multiplicand

mul ebx // multiply the two

add eax, [x1]
add edi, eax // Got the address to the first pixel


// EDX = color

mov dl, [color]
mov dh, dl
mov ax, dx
shl eax, 16
mov ax, dx // 4 - byte colour value in edx


cld // Clear direction flag


mov ecx, x2
sub ecx, x1 // Calculate the with of the line

mov ebx, ecx // save width in ebx


shr ecx, 2 // Calculate the number of DWORDS to move

rep stosd

mov ecx, ebx // Calculate the number of bytes to move

and ecx, 3
rep stosb

}
}




Edited by - cyberben on July 18, 2000 7:03:01 PM

Share this post


Link to post
Share on other sites
Ok that looks right, I haven''t tested it but it should be fine... note that it assumes that x2 > x1 so x1 is the first pixel and we draw in the direction towards x2... try that out, if it works perfect try to optimize the mul out but sometimes it''s not even worth it... How many lines will you draw each frame?
- Ben

Share this post


Link to post
Share on other sites
Yeah, I had pretty much the same code as yours, but I tried to optimize it, and it wasn''t working afterwards. The code looks good to me, and maybe I''ve missed something small that I can''t see... I have no idea... anyways... if you figure a way to fix the optimized technique let me know. It works fine when I crate a small test project to draw a few horizontal lines, but I have no idea why it wouldn;t work when I try to use it in my project''s code. If you could test it out and let me know whether it works or not that''d be great. It''s for 32-bit PMode. I''m using Watcom C++.

----------------------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites