Re: Re: A82: Hmm


[Prev][Next][Index][Thread]

Re: Re: A82: Hmm




>You mean, 32-bit Intel machine code (32-bit uncompiled ASM program section
>that appears to plot a single pixel).  I can understand some of what you
>are doing there (a little bit since I don't have much knowledge in Intel
>ASM) and you are using 3 32-bit registers.  So, in order to compile this,
>you must have a 32-bit assembler (like TASM 5.0)...which I don't have and
>the guy who originally started this thread probably doesn't have either.
>So, that's why I used C to help him on his way.

You can use TASM 3.0 by renaming the EXE file to tasm32.exe.  I don't know why this
matters, but this
works...

Anyways, the basic idea behind this is to use the fact that you can multiply BL by
257 by doing something like MOV BH,BL.  (257 = shift left 8 + uncorrupted original).
 How this works is simple, really.  256 + 64
= 320, so 256y + 64y = 320y.  This is what the classic
C method [y << 8 + y << 6 + x] means - 256y + 64y.

To do a multiply by 256, we use the same trick as the
257 one but don't write to the same register.  This is
a simplified version of the code I pasted:

MOV ECX,0
MOV EAX,Xloc
MOV EBX,Yloc
MOV DL,color
MOV CH,BL
SHL EBX,6
ADD EBX,ECX
MOV [EAX+EBX+0A0000h],DL

The MOV CH,BL makes ECX equal 256*BL (which as long as
EBX is < 256 equals EBX also), because it is writing
one byte higher in the register.  Then it shifts left
EBX by 6 (multiply by 64) then adds ECX, completing the
256y + 64y part.

There is an optimization here though.  ECX is not
needed.  If you add the result of the shift left by 8
to EAX, you won't have to use EAX+EBX+ECX.  This can
be done very easily using ADD AH,BL, making the final:

MOV EBX,Yloc            ; 1/2
MOV EAX,Xloc            ; 1/2
MOV DL,color            ; 1/2
ADD AH,BL               ; 1/2
SHL EBX,6               ; 1
MOV [EBX+EAX+0A0000h],DL; 2, scaled index, EBX modified
                        ; in previous instruction
                        ; 5 clocks total

Another method (slower):
MOV EBX,Y               ; 1/2
MOV DL,color            ; 1/2
MOV EAX,X               ; 1
SHL EBX,6               ; 1
LEA EBX,[EBX+EBX*4]     ; 1, scaled index
MOV [EBX+EAX+0A0000h],DL; 2, scaled index, EBX modified
                        ; in previous instruction
                        ; 6 clocks total

The second one can be thought of in two ways.  You can
either see it as 64 * 5 = 320 (EBX+EBX*4), or as the
64 + 256 method (64 * 4 = 256, EBX(64y) + EBX*4(256y)).

-- Barubary, posting from crash account



Free web-based email, Forever, From anywhere!
http://www.mailexcite.com


Follow-Ups: