Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fast pixel plot for 13h

Status
Not open for further replies.

AalfaBob

Programmer
Jan 9, 2004
5
0
0
US
Ive been working on a fast pset and so far here is what I have come up with :
Ticks:
MOV AX, 0A000h ;Move to Video Memory 1
MOV ES, AX ;Load ES with it 1
MOV DX, Y ;Load in Y Value 1
XCHG DH, DL ;Solve for, 3
MOV DI, DX ;DI = Y * 320 + X 1
SHR DI, 2 ; " 3
ADD DI, DX ; " 1
ADD DI, X ; " 1
MOV ES:[DI], C ;Pixel into memory 1?
Total 13
Does the last MOV have 1 tick or more? Also, did I mess up on any of the ticks?
 
Time it. Counting ticks is a nice start but often not reliable because of pipelining and the fact modern processors can be handling two instructions at once. But whether they can or not depends on the instruction's surroundings. For instance, in your code, the first 2 instructions cannot run simultaneously because the second depends on the first (it needs what you are loading into ax). If you swap the second and third instructions, then theoretically mov ax, number and mov dx, y can run simultaneously (1 tick for two instructions!). Xchg doesn't pair with anything and therefore is dodgy; you don't need it anyway since you're only using this to shift left 8 bits and you could do that with a mov; would mov dh, dl be quicker?
You might also experiment with lea as a way to multiply. lea can be used even if you're in 16bit code with its 32 bit scaled index addressing. For instance:
lea ebx, [ebx + ebx*4]
should compile, and multiplies by 5!
This, and a shift, is all it takes to multiply by 320. And lea is a quick instruction, though you'll lose out in 16-bit code because the scaled index prefix may cost you, and so will the prefix to indicate a 32 bit instruction in a 16 bit segment.
Have fun!
 
How can I time my program, I guessing that I have to use some type of software or add in code? Thanks for your help lionelhill.
 
Various options. I'd do some web-searching if I were you. Michael Abrash produced a long time ago a thing he called the "Zen timer" in two different versions for longer and shorter bits of code (it's based on the IBM-compatible's own internal timing). Or you can write your own code to repeat the pixel plot enough times to take an appreciable amount of time relative to any source of time you have, even the bios clock if you draw enough dots.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top