Author : Grant Smith
Page : << Previous 14 Next >>
source is a byte, the source is
multiplied by AL, the result being
stored in AX. If source is a word,
the source is multiplied by AX, the
result being stored in DX:AX
movsb This moves the byte that DS:SI is
pointing to into ES:DI, and
increments SI and DI.
movsw Same as movsb except it moves a
word instead of a byte.
stosw This moves AX into ES:DI. stosb
moves AL into ES:DI. DI is then
incremented.
push register This saves the value of register by
pushing it onto the stack. The
register may then be altered, but
will be restored to it's original
value when popped.
pop register This restores the value of a pushed
register. NOTE : Pushed values must
be popped in the SAME ORDER but
REVERSED.
rep command This repeats Command by as many
times as the value in CX
SHL Destination,count ;
and SHR Destination,count ;
need a bit more explaining. As you know, computers think in ones and
zeroes. Each number may be represented in this base 2 operation. A byte
consists of 8 ones and zeroes (bits), and have a range from 0 to 255. A
word consists of 16 ones and zeroes (bits), and has a range from 0 to
65535. A double word consists of 32 bits.
The number 53 may be represented as follows : 00110101. Ask someone who
looks clever to explain to you how to convert from binary to decimal and
vice-versa.
What happens if you shift everything to the left? Drop the leftmost
number and add a zero to the right? This is what happens :
00110101 = 53
<-----
01101010 = 106
As you can see, the value has doubled! In the same way, by shifting one
to the right, you halve the value! This is a VERY quick way of
multiplying or dividing by 2. (note that for dividing by shifting, we
get the trunc of the result ... ie. 15 shr 1 = 7)
In assembler the format is SHL destination,count This shifts
destination by as many bits in count (1=*2, 2=*4, 3=*8, 4=*16 etc)
Note that a shift takes only 2 clock cycles, while a mul can take up to 133
clock cycles. Quite a difference, no? Only 286es or above may have count
being greater then one.
This is why to do the following to calculate the screen coordinates for
a putpixel is very slow :
mov ax,[Y]
mov bx,320
mul bx
add ax,[X]
mov di,ax
But alas! I hear you cry. 320 is not a value you may shift by, as you
may only shift by 2,4,8,16,32,64,128,256,512 etc.etc. The solution is
very cunning. Watch.
mov bx, [X] // set BX to X
mov dx, [Y] // set DX to Y
push bx // save BX (our X value)
mov bx, dx // now BX and DX are equal to Y
mov dh, dl // copy DL to DH (multiply Y by 256)
xor dl, dl // zero out DL
shl bx, 6 // shift BX left 6 places (multiply Y by 64).
add
Page : << Previous 14 Next >>