Re: A86: Need more help


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

Re: A86: Need more help




> Sorry to have posted so many "I need help"-ish posts...

No problem, this is kind of a "I need help"-ish mailing list.


>everything seems longer than it should, at least in comparison to
> other languages I've ever programmed.

Higher languages, when compiled, output a huge block of assembly code
for some of the simplest operations.  Nearly everything looks longer in
assembly.  But nearly everything is faster in assembly, too, because you
can optimize far better than a higher-language compiler can, because you
know what you want to happen.


>  Thus, I just have one quick question.
> If I wanted to add a number (say, 6) to the E register, is there a faster
> way than this to do it?
> 
>  ld a,e         ;\
>  add a,6      ; >Adds 6 to e
>  ld e,a         ;/


If you really need the result in e, then that's probably the fastest you
are gonna get.  Or, if you don't care where the result ends up, you
could remove the 'ld e,a' and keep the result in a.  This is probably
fastest, but by no means the only way.  The beauty of asm is that there
are numerous ways of doing everything...

Examples that do the same as your code:

  ld b, 6
loop:
  inc e
  djnz loop	;e= e+1+1+1+1+1+1 or e+6

  ld a, 6
  add a, e
  ld e, a	;e= e+6

  ld b, e
  ld a, 6
loop:
  inc a
  djnz loop	;a= 6+(e*1)
  ld e, a	;e= 6+(e*1)


References: