This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
Tyraniek


Member


Joined: 07 Jun 2003
Posts: 133

Posted: 08 Jul 2003 07:19:27 am    Post subject:

How would you do the equivalent of this ?

Code:
ld bc, 12*a+12


Of course, I tried

Code:
   add   a, a  ; A = 2*initiale
   add   a, a  ; A = 4*initiale
   ld   e, a  ; E = 4*initiale
   add   a, a  ; A = 8*initiale
   add   a, e  ; A = 12*initiale
   add   a, 12  ; A = 12*initiale + 12
   ld   bc, a  ; cannot copy


But the problem is that A should be able to store a number like 768 (12*64), so it is not possible (A is 8bits, so it can just store a number between 0 and 255).
So what would you do ? Wacko

Thank you.


Last edited by Guest on 08 Jul 2003 07:50:48 am; edited 1 time in total
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 08 Jul 2003 08:18:39 am    Post subject:

Hmm, what about using a 16-bit register? :|

inc a ; just a substitute for the +12
ld h,0
ld l,a
add hl,hl
add hl,hl
ld d,h
ld e,l
add hl,hl
add hl,de
ld b,h
ld c,l
Back to top
Tyraniek


Member


Joined: 07 Jun 2003
Posts: 133

Posted: 08 Jul 2003 08:32:49 am    Post subject:

works perfectly, thank you ! Laughing
it's something clever (notably the "inc a" which becomes add a, 12) !

Oh, and, how would you do

Code:
sub hl, 12

I wrote "dec hl" 12 times, but is there any better code ?


Last edited by Guest on 08 Jul 2003 08:34:22 am; edited 1 time in total
Back to top
Tyler


Advanced Member


Joined: 29 May 2003
Posts: 352

Posted: 08 Jul 2003 09:04:26 am    Post subject:

Argh ... I'm trying to figure out how the "sub" command works! It's more efficent to do it that way because it will only take 1 line of code! I'll edit the post if I get it!
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 08 Jul 2003 02:19:43 pm    Post subject:

sub # = a-#
if u want to use subtraction with a 16b reg, then u have to use sbc (subract with carry) but first, u would want to reset the carry flag...

sbc rr,rr = rr-rr
others avaliable, but not bothering to check Wink
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 08 Jul 2003 02:21:27 pm    Post subject:

16-bit sbc can only take hl as first operand:

ld de,12
or a
sbc hl,de
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 08 Jul 2003 02:36:52 pm    Post subject:

well then, there u go!
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 08 Jul 2003 03:31:56 pm    Post subject:

Of course, you can do it in a bit different way as well:

ld de,-12
add hl,de

Here you can use ix and iy too instead of hl.
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 08 Jul 2003 05:40:29 pm    Post subject:

but u dont want to modify iy, cause then all ur set/res instructions are messed up Neutral
Back to top
Job the GameQuitter


Member


Joined: 04 Jun 2003
Posts: 102

Posted: 08 Jul 2003 06:35:50 pm    Post subject:

That only matters if you give a #### about bcalls; if you use nothing but your own routines, you can use IX and IY without worrying.

Last edited by Guest on 08 Jul 2003 07:41:24 pm; edited 1 time in total
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 08 Jul 2003 07:41:13 pm    Post subject:

not bcalls, but the flags!
Back to top
Job the GameQuitter


Member


Joined: 04 Jun 2003
Posts: 102

Posted: 08 Jul 2003 09:05:48 pm    Post subject:

Woops, forgot to watch my language there. Sorry Adm. Wiggin, won't happen again! Laughing

Anyway, the system flags aren't important for um... just about anything but bcalls. ;)

Unless you use some custom flags of your own that is.
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 08 Jul 2003 10:31:08 pm    Post subject:

ya, it ok...

but about the flags, read my asm tut. (in asm forum Wink ) on changing the shape of the run indic, and u will see that it doesnt use a single bcall, but it does use the flags!
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 09 Jul 2003 12:44:14 am    Post subject:

Why on earth do you need to worry about the run indicator? If you do everything with rom calls, you could be much better off with basic, because it's a lot more compact than asm.
Back to top
Tyraniek


Member


Joined: 07 Jun 2003
Posts: 133

Posted: 09 Jul 2003 12:54:07 pm    Post subject:

Quote:
you could be much better off with basic, because it's a lot more compact than asm.


Yeah, but it is also a hell of a lot more slow than ASM ;-)

Concerning my question, I think I'll add the negative value (-12). It's a good idea.
Thx for having shown me how to use SBC, I'm sure it will be useful one day Smile
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 10 Jul 2003 01:44:42 am    Post subject:

Not really. The BASIC interpreter uses the very same romcalls. Writing a program in asm only makes sense if you are willing to use integer algebra and a directly accessed virtual screen. Other than that, you are just wasting precious memory.
Back to top
Job the GameQuitter


Member


Joined: 04 Jun 2003
Posts: 102

Posted: 10 Jul 2003 09:04:25 am    Post subject:

Now now CoBB, even if you only use bcalls, you remove the part where the TI-OS has to interpret the basic code. That saves some time AND memory.

But I agree that you're usually better of using routines of your own.
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 10 Jul 2003 09:06:51 am    Post subject:

yes, faster with ur own routines, i mean, look at ionfastcopy! it is his own routine, and it runs super fast!
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 10 Jul 2003 10:28:31 am    Post subject:

Well, there's certainly a speed increase at the cost of reduced error handling. Memory usage is probably not trivial. In BASIC you are compelled to store numbers in a not-so-effective way (1 digit per byte means wasting 8 bits for storing ~3.32 bits of information), but you don't need to worry about the OP handling routines, which can turn the simplest equations into a long series of romcalls, which would take just some tokens in BASIC. Unless you create some new functionality the TIOS isn't capable of itself, BASIC is usually a good choice.

Last edited by Guest on 10 Jul 2003 10:29:12 am; edited 1 time in total
Back to top
Job the GameQuitter


Member


Joined: 04 Jun 2003
Posts: 102

Posted: 10 Jul 2003 01:05:06 pm    Post subject:

"New" ofcourse meaning "fast, good-looking games" Laughing.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    » Goto page 1, 2  Next
» View previous topic :: View next topic  
Page 1 of 2 » All times are UTC - 5 Hours

 

Advertisement