flat assembler
Message board for the users of flat assembler.
Index
> Programming Language Design > Pointer Arithmetic: *EDI++=*ESI-- |
Author |
|
revolution 01 Jun 2015, 01:41
Can I ask why you chose the asterisk (*) instead of the more usual assembly style square brackets ([])?
[edi++] = [esi++] Also, how does the code decide to use EBX? It becomes a hidden used register which makes it easy to forget that it is corrupted. What about changing ADD REG,1 to INC REG? |
|||
01 Jun 2015, 01:41 |
|
codestar 01 Jun 2015, 02:57
Quote: revolution: Can I ask why you chose the asterisk (*) instead of the more usual assembly style square brackets ([])? Code: [edi++]=[esi++] ; wrong [edi]++=[esi]++ ; right, get value first Quote: Also, how does the code decide to use EBX? Now, may I ask you a question? What makes you think you're a "programmer" when you never write code and can't understand simple things? YOu can't teach an old dog new tricks. Answer: revolution is just a fake who comes online and pretends to have programming abilities which he can't prove. After 12,767 posts, he has never created one single program by himself. What little code he writes is so illogical and easy to improve in 5 seconds. Why follow their stupid rules - which have gotten them NOWHERE - unless you want to be like them and have no programs? I challenge anyone to improve my code: Code: while c, c=*p++, endw, p-s, p-- while s<e, c=*s, *s++=*e, *e--=c, endw if n=0, *p++='0', *p=0 return s end loop n, c=*s++, *p++=c if c=0, break, end endl, p-- while c, c=*s++, *p++=c, endw, p-- while c=d, c=*p++, d=*s++ if c=0, break, end if d=0, break, end endw, p=c, p-d while n, x=n, x&1, x+'0' . *p++=x, n>>>1 endw, *p=0 forever, c=*p++ if c=0, return n, end . x=n, x<<2, n+x, n+n . n-'0', n+c endfv ; draw bit/byte function draw.bit, n, x, y if n draw.image bit1.i, x, y else draw.image bit0.i, x, y end endf function draw.byte, n, x, y locals i . i=8 loop i, r0=n, r1=i . r1--, r0>>cl, r0&1 draw.bit r0, x, y . x+BIT.W endl endf ; draw pixel function draw.pixel, x, y, c alias p=r0, z=r1 try clip.pixel x, y vga.xy x, y . z=c, (u32) *p=z endf 1 ; draw horizontal line function draw.line.h, x, y, n, c alias p=r0, z=r1, w=r2 . p=&x, z=&y, w=&n try clip.line 0, p, z, w vga.xy x, y . z=c loop n, (u32) *p++=z, endl endf 1 ; draw solid rectangle function draw.box, x, y, w, h, c locals i try visible x, y, w, h . i=y, i-- loop h, i++ draw.line.h x, i, w, c endl endf 1 ; draw scanline function draw.scanline, pixels, x, y, w alias p=r0, s=r1 vga.xy x, y . s=pixels loop w, (u32) *p++=*s++, endl endf 1 ; draw 8BPP scanline/bitmap with palette function draw.scanline.8, pixels, x, y, w alias p=r0, s=r1, c=r2, q=r3 vga.xy x, y . s=pixels loop w, q=*s++, q*4, q+palette.p . (u32) c=*q, (u32) *p++=c endl endf 1 function draw.bitmap.8, pixels, x, y, w, h locals i, p try visible x, y, w, h . i=y, i--, p=pixels loop h, i++ draw.scanline.8 p, x, i, w . r0=w, p+r0 endl endf 1 function draw.my.numbers locals i, n, y . i=bits.h, y=404 loop i, r0=my.numbers, r0+i, r0-- . r0=*r0, n=r0 draw.byte n, 4, y . y-BIT.H endl endf function draw.title.scene draw.text help.t, 16, 130 draw.byte magic.n, 50, 300 endf function draw.play.scene draw.board draw.my.numbers endf function draw.pause.scene draw.text pause.t, 16, 130 draw.byte magic.n, 50, 300 endf function draw.game.over print t, game.over.t, score draw.text t, 44, 170 draw.byte magic.n, 50, 300 endf ; convert 32BIT binary number to text function b2t, n, t alias p=r0, x=r1 . p=t if n=0, *p++='0', *p=0 return end while n, x=n, x&1, x+'0' . *p++=x, n>>>1 endw, *p=0 text.reverse t endf ; text.copy a, b - standard copy with ; 0 after. return advanced address function text.copy, a, b alias p=r0, s=r1, c=r2 . p=a, s=b, c=1 while c, c=*s++, *p++=c, endw, p-- endf ; text.copy.n a, b, n - copy with maximum ; size specified. return & function text.copy.n, a, b, n alias p=r0, s=r1, c=r2 . p=a, s=b loop n, c=*s++, *p++=c if c=0, break, end endl, p-- endf ; text.go t, n - advance to line # function text.go, t, n loop n try t=text.find t, 0Dh . t+2 endl endf t ; text.skip.0 a - skip 0s, return address or 0 function text.skip.0, a alias p=r0, c=r1 . p=a, c='0' while c='0', c=*p++, endw, p-- if c=0, return 0, end endf ; convert text to 32BIT binary function t2b, t alias p=r0, c=r1, n=r2 try text.skip.0 t . n=0 loop, c=*p++ if c=0, return n, end . n<<1, n-'0', n+c endl endf function draw.my.text, t, x, y locals p, n get n=text.n t . p=t loop n, r0=p, r0=*r0 draw.my.c r0, x, y, WHITE . x+r0, x+4, p++ endl endf function randomize.puzzle locals q, n alias p=r0, x=r1 . q=puzzle, n=(MAP.W*MAP.H) loop n get x=get.random . p=q, (u32) *p=x, q+4 endl endf function is.solved locals n alias p=r0, x=r1 . p=puzzle, n=(MAP.W*MAP.H) loop n, (u32) x=*p++ if x<>NORMAL, return 0, end endl endf 1 function draw.puzzle locals x, y . y=0 while y<8, x=0 while x<8 . r0=x, r0*TILE.W, r0+MAP.X . r1=y, r1*TILE.H, r1+MAP.Y draw.piece x, y, r0, r1 . x++ endw . y++ endw endf function on.key if key.event='c' if scene=SCENE.TITLE . scene=SCENE.PLAY go .draw end if scene=SCENE.GAME.OVER go .reset end if key='r' .reset: reset.game go .draw end if key='p' .pause: if scene=SCENE.PLAY . scene=SCENE.PAUSE else.if scene=SCENE.PAUSE . scene=SCENE.PLAY end go .draw end .draw: render end endf function on.mouse locals r if mouse.event='c' . r0=&close.i.x if.select r0 exit end if scene=SCENE.TITLE reset.game . scene=SCENE.PLAY go .draw end if scene=SCENE.PLAY if.select puzzle.box get.select.xy get r=get.piece.rotate \ select.x, select.y . r++ set.piece.rotate \ select.x, select.y, r go .draw end end if scene=SCENE.SOLVED reset.game . scene=SCENE.TITLE go .draw end .draw: render end endf |
|||
01 Jun 2015, 02:57 |
|
revolution 01 Jun 2015, 09:20
codestar wrote:
I also find the ++ notation for C to be ambiguous. Without the actual parsing rules being stated there can be other ways to interpret it. [esi++]: increment ESI after getting the memory address for reading? [esi]++: increment the memory at [esi] after reading it? |
|||
01 Jun 2015, 09:20 |
|
Tomasz Grysztar 01 Jun 2015, 14:09
revolution wrote: Okay, so standard for C. But not standard for assembly. |
|||
01 Jun 2015, 14:09 |
|
codestar 01 Jun 2015, 18:30
Your argument is basically, "X is not a real X-Tian. I think X is clearer than Y but I don't know why and can't give reasons". Who cares? I'm a programmer, period, and I believe in writing good code in Abakis, C/C++, ASM, Javascript, doesn't matter which language. What is "good" code? Whatever works. "The right way is the way that works".
Tomasz: On all keyboards I've used, * is easier to type than []. No one can argue logically that 2 inaccessible symbols [] is better to use than *. I don't see the ambiguity that you're referring to. Please clarify. In C, *(p++) means advance pointer by its size first then get *(value) after: add [p], size | mov x, type [p]. And p[i] means p[i*size] due to automatic scale. [ means +. array[i*s] = [array+i*s]. Quote: Opinion: X is clearer than Y (based on "I don't know but I believe") Last edited by codestar on 12 Jun 2015, 17:02; edited 1 time in total |
|||
01 Jun 2015, 18:30 |
|
revolution 01 Jun 2015, 22:18
codestar wrote: On my good day, I can beat Tomasz at programming, but on his good day, he can beat me. |
|||
01 Jun 2015, 22:18 |
|
codestar 02 Jun 2015, 01:46
It's harmless fun like kids playing video games. Since 2001/2-ish, I've always thought that Tomasz was a good programmer and I remember when vid first presented his FASMLIB which inspired me. Show me a better way so that I can learn. It's frustrating to hear people say "You're wrong" but they don't show me a right way.
Who is "we"? Speak for yourself. Personally, I write all code for my own satisfaction and development then I put it online with the hopes that it will help *advanced* programmers. I know that some people (sleepS, JohnS, they're everywhere) will misinterpret it as "Look at me, I'm so great, better than you" (nonsense). |
|||
02 Jun 2015, 01:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.