flat assembler
Message board for the users of flat assembler.
Index
> DOS > Line drawing 
Author 

revolution 25 Mar 2011, 04:44
It is adding one half (0.5) using fixed point (16 bit integer and 16 bit fraction) arithmetic.


25 Mar 2011, 04:44 

me239 25 Mar 2011, 21:13
revolution wrote: It is adding one half (0.5) using fixed point (16 bit integer and 16 bit fraction) arithmetic. 

25 Mar 2011, 21:13 

revolution 25 Mar 2011, 23:11
me239 wrote: Well could you explain how it works? Thanks 

25 Mar 2011, 23:11 

me239 26 Mar 2011, 02:07
revolution wrote:


26 Mar 2011, 02:07 

revolution 26 Mar 2011, 02:42
me239 wrote: ... one last thing though, why when AX is empty and DX has a value the DIV command returns a number in AX. 

26 Mar 2011, 02:42 

me239 26 Mar 2011, 04:48
revolution wrote:
Code: mov dx, 2 ; DX = 2 xor ax, ax ; AX = 0 mov bx, 10d ; BX = 0Ah div bx ; Now AX hold 3333h?!? int 20h 

26 Mar 2011, 04:48 

revolution 26 Mar 2011, 04:54
DX:AX == 0002:0000
BX == 000A DX:AX / BX = 20000h / 0Ah = 3333h (in AX) + 2 remainder (in DX). Same as: 131072 / 10 = 13107.2 

26 Mar 2011, 04:54 

me239 26 Mar 2011, 05:19
revolution wrote: DX:AX == 0002:0000 

26 Mar 2011, 05:19 

revolution 26 Mar 2011, 12:26
me239 wrote: I'm still trying to decipher what the .5 shl 16 is really for with respect to the code, but thanks anyway Anyhow, I suggest you try it with a zero value in BX instead of the 0.5 value and watch what happens to lines of various slopes. And then try with 3/4, or some other value, and see the results. 

26 Mar 2011, 12:26 

bitRAKE 28 Mar 2011, 05:38
Think about it in binary.
0001 in binary is one. If you divide this number by two (i.e. shift right by one) the answer is one half. We can represent this as 0000.1000  requiring a fractional register with the high bit set. Each position to the right of the decimal represents negative powers of two: 2^1, 2^2, 2^3, ... Work through smaller examples in binary until you are fully convinced as this is a very useful technique. 

28 Mar 2011, 05:38 

me239 28 Mar 2011, 23:05
bitRAKE wrote: Think about it in binary. 

28 Mar 2011, 23:05 

revolution 28 Mar 2011, 23:09
me239 wrote: I'm understanding the fixed point math using DX:AX, but I'm still confused as to why adding 32768(.1) make an accurate line. Did you try it with a zero value yet? When you see the results then you will understand why. 

28 Mar 2011, 23:09 

me239 29 Mar 2011, 01:37
revolution wrote:


29 Mar 2011, 01:37 

bitRAKE 29 Mar 2011, 05:45
Adding 1/2 centers the overflow. Look at a steep/shallow line and compare different starting values for BX  the steps will move, 1/2 gives the most esthetically pleasing line  symmetric steps.


29 Mar 2011, 05:45 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.