Reverse Engineering for Beginners

(avery) #1
CHAPTER 83. DEMOS CHAPTER 83. DEMOS
Some other optimization tricks:


  • The 1-byte CWD is used here for clearing DX instead of the 2-byteXOR DX, DXor even the 3-byteMOV DX, 0.

  • The 1-byteXCHG AX, CXis used instead of the 2-byteMOV AX,CX. The current value of AX is not needed here
    anyway.

  • DI (position in video buffer) is not initialized, and it is 0xFFFE at the start^8. That’s OK, because the program works
    for all DI in the range of 0..0xFFFF eternally, and the user can’t notice that it is started off the screen (the last pixel of
    a 320*200 video buffer is at address 0xF9FF). So some work is actually done off the limits of the screen. Otherwise,
    you’ll need an additional instructions to set DI to 0 and check for the video buffer’s end.


83.2.3 My “fixed” version


Listing 83.6: My “fixed” version
1 org 100h
2 mov al,13h
3 int 10h
4
5 ; set palette
6 mov dx, 3c8h
7 mov al, 0
8 out dx, al
9 mov cx, 100h
10 inc dx
11 l00:
12 mov al, cl
13 shl ax, 2
14 out dx, al ; red
15 out dx, al ; green
16 out dx, al ; blue
17 loop l00
18
19 push 0a000h
20 pop es
21
22 xor di, di
23
24 FillLoop:
25 cwd
26 mov ax,di
27 mov cx,320
28 div cx
29 sub ax,100
30 sub dx,160
31
32 xor bx,bx
33 xor si,si
34
35 MandelLoop:
36 mov bp,si
37 imul si,bx
38 add si,si
39 imul bx,bx
40 jo MandelBreak
41 imul bp,bp
42 jo MandelBreak
43 add bx,bp
44 jo MandelBreak
45 sub bx,bp
46 sub bx,bp
47
48 sar bx,6
49 add bx,dx
50 sar si,6
51 add si,ax
52


(^8) More information about initial register values:http://go.yurichev.com/17004

Free download pdf