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
Trogdorgar


Newbie


Joined: 26 Jan 2009
Posts: 8

Posted: 27 Jan 2009 11:56:22 pm    Post subject:

Hi there guys, I have been using basic for a long while now, and want to start getting into assembly.
I have read some pretty good tutorials, especially the "Learn Assembly in 28 Days" Tutorial by Sean McLaughlin
It was an excellent read, and a good start for anyone wanting to learn the basic of assembly and beyond :biggrin:

Want I am wanting to do to get a grand understanding of Assembly is to have one of my programs, which is my Sudoku Solver, converted from TI-BASIC into assembly,
so that i can understand the basics of assembly more fluently.

I will attach the program to this post and hope that someone can convert it for me,
because there is no chance that I can without screwing it up. <insert completely stupid joke here> haha....

So if theres anyone out there looking for a good challenge for assembly or would like to help me out, that would be great, the program itself is pretty much as completely optimized
as i can get it.
The basic overview of the solver is in the mapping file.
The solver was made for use with the TI-84+
The solver programs are all in group names SKDUSLVR

and before I forget, the "probability of choice" grid is written in basically a reverse binary format
a.k.a 0.111111111 = 0.(Prob of 1)(P of 2)(P of 3) etc...
the conversion method I used in the programming to get the probability integer of a number from the format is this code
int(fpart(I10^(N-1))10)

As I complete more methods of solving for the solver, I'll try to append them to the post.


Updates:


Last edited by Guest on 29 Jan 2009 12:19:29 am; edited 1 time in total
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 28 Jan 2009 09:38:36 am    Post subject:

bah, I need to install GFM or use the TI-Connect in my laptop. Today I don't have time for this. Exam tomorrow...

But BASIC and ASM are in so different levels that the ported code can be unexpected to you.
And in ASM, because of the speed, you can have the chance to use simply use a pure brute force algorithm. But I will try to make an equivalent code.


ASM in 28 days is a great tutorial. But you can also try later Cobb's tutorial or some TI documentation about b_calls and handling TI-OS variables and such. And practising is really needed!


Another programming enthusiast, just like me! Welcome to UTI forums.
Back to top
Trogdorgar


Newbie


Joined: 26 Jan 2009
Posts: 8

Posted: 28 Jan 2009 04:39:35 pm    Post subject:

Yeah right now I use both TI-Connect and TI-Graph Link, TIGL to create and edit the BASIC programs and TI-Connect to send them, since GL doesn't support the usb port sending for the 84+

Yeah and the reason I would like the program to be in logical format, instead of brute force is because of a few things.
1. I know the exact coding of a logical solver, since they are based on equalities instead of guess-and-check like in brute forcers.
2. The logical solver is easier to code and maintain, unlike the brute forcer, which if something goes wrong, you have to go through hours of searching the code to figure out what screwed up.
3. If I just have the program I have converted as it is, I won't have to read thousands of tutorials trying to figure out what each little command does, and I can use code relation to get a fair basis of what a patch of code does.
4. I would come to believe that a logical solver would be faster, due to the fact that brute forcing has to go through every single number, and if there is an error, has to backtrack until the error is fixed, where logical solvers don't.
5. I don't exactly get how a brute forcer works, so I would have no idea what the code is doing until I become fluent in assembly, where if i found a brute forcer in BASIC, I would basically know what is happening without even trying, BASIC is like a second language to me :P

In relation to the tutorials, I will check out Cobb's tutorials to see what they are all about, since right now I am basically on a "language learning" binge, and trying to learn multiple languages at once lol, right now im learning C / C++, ASM, HTML, PHP, and trying a little bit of Java.

Yay for enthusiasts lol, been doing BASIC for the past 2 years now, I can't get enough of it, started doing it on my old CASIO FX-9750G, but then took it apart and the keypad stopped working Laughing so I got a TI-84+ and kept doing BASIC ever since, and recently saw the stuff people were making in Assembly on ticalc, and wanted to get in on the action, so far my fav asm game is either ZTetris or Degeneration.
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 28 Jan 2009 11:29:16 pm    Post subject:

Please don't learn assembly by trying to compare it to basic. It won't work. Assembly is a completely different beast, and must be approached as such. Read 28 days, and all will be explained.
Back to top
Trogdorgar


Newbie


Joined: 26 Jan 2009
Posts: 8

Posted: 28 Jan 2009 11:50:06 pm    Post subject:

magicdanw wrote:
Please don't learn assembly by trying to compare it to basic. It won't work. Assembly is a completely different beast, and must be approached as such. Read 28 days, and all will be explained.


I know about the "28 Days"... I've already read it... I said that in the first post

Trogdorgar wrote:
Hi there guys, I have been using basic for a long while now, and want to start getting into assembly.
I have read some pretty good tutorials, especially the "Learn Assembly in 28 Days" Tutorial by Sean McLaughlin
It was an excellent read, and a good start for anyone wanting to learn the basic of assembly and beyond :biggrin:


In regards to the comparation, I'm not going to do a direct comparison of the two programs, a.k.a taking a batch of assembly and taking batch of basic and say, "That is how that BASIC code is written in ASM", I am going to do a relative comparison, a.k.a take the same scenario, and say, "This is basically what the Assembly code is trying to do, with a slight margin of error"


Last edited by Guest on 28 Jan 2009 11:51:18 pm; edited 1 time in total
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 29 Jan 2009 01:12:17 pm    Post subject:

Multiple languages at once is definitely bad idea. I just know TI-BASIC and z80 ASM. Great distance between both but once I master (somewhat) ASM I want try another one :biggrin:

And comparing both is not good idea... I though you wanted the code as curiosity or see some code in action.
Anyway, GFM is giving me too much trouble. At night I will use my other computer...



just a little code to see the point. (And action equivalent to BASIC: [A](R,C) )
;Do you remember using data tutorials in ASMin28days?
retrieveabyte:
;input: b=row c=column
;output: a in the position wanted in the matrix
ld hl,Matrixdata
dec b ;just to give the BASIC feel of [A](1,1
dec c ;very dumb ASM because you just assume 0 as the first byte
ld a,b
add a,a
add a,a
add a,a
add a,b ;a=b*9
add a,c
ld b,0
ld c,a
add hl,bc
ld a,(hl)
ret

Matrixdata: ;9x9 matrix
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0

The following example can explain why doing kind of BASIC in ASM is bad. ASM is not optimized if you use call's to the retrieveabyte routine every time you need a number in a certain position the matrix. You can just have hl always pointing to the matrix and retrieve every time you want. No need to do what the second code will do.
For example search for a value of 0 in the matrix and solve it with a subroutine, just:

ld b,255 ;loop 255 times is sufficient to pass the matrix many times...
ld hl,Matrixdata
loop:
ld a,(hl)
or a
call z,solve ;this calls a routine to find out which value can be given and we assume it preserves hl
inc hl
;I am lazy enough to not write a code that will restore hl to the start of matrix
;just assume it is done here:
<code that load hl with the start of matrix when hl has passed through it>
djnz loop

;ASM guys don't look if you don't need.
;I don't know how I was capable of this...
No need to:
ld e,255
ld b,1
ld c,1
loop:
call retrieveabyte
or a
call z,solve
inc c
ld a,c
cp 9
jr nz,loop
ld c,1
inc b
ld e,a
or a
jp nz,loop

This code lacks a check for if the sudoku is already solved after some passes... I hope there is no error.
So using the BASIC method in ASM is wasting ASM speed, space and your time. (note: I wasted time Razz )


You may want to know the solve routine itself. Later I will see your basic code and see what I will do...


Last edited by Guest on 29 Jan 2009 01:20:15 pm; edited 1 time in total
Back to top
Trogdorgar


Newbie


Joined: 26 Jan 2009
Posts: 8

Posted: 30 Jan 2009 12:30:47 am    Post subject:

Galandros wrote:
Multiple languages at once is definitely bad idea. I just know TI-BASIC and z80 ASM. Great distance between both but once I master (somewhat) ASM I want try another one :biggrin:

lol yeah i know, but i just cant help it.


Galandros wrote:
And comparing both is not good idea... I though you wanted the code as curiosity or see some code in action.
Anyway, GFM is giving me too much trouble. At night I will use my other computer...

Yeah, i know its a bad idea, but it might give some slight help in aiding me in answering some questions...
Like when should i use Mathematics coding or Assembly Math coding

such as when should i use

ld a, 9

and when should i use

ld b,1
ld a,b
add a,a
add a,a
add a,a
add a,b

And besides, i would have my very first ever big program coded in asm ^^, and you can put ur name in the credits if you want.


Last edited by Guest on 30 Jan 2009 12:31:35 am; edited 1 time in total
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 30 Jan 2009 01:11:37 am    Post subject:

Trogdorgar wrote:
such as when should i use

ld a, 9

and when should i use

ld b,1
ld a,b
add a,a
add a,a
add a,a
add a,b
You should use the first one when you know the number you want to use while coding. You should use the second when you don't know the number while coding, but you know that when the program is run, there will be some number you want to multiply by a set amount. Really, I would suggest you learn to make a program by...making a program. The people on this board, myself included, will be more than happy to help you out along the way. But if we write the program for you, you really will barely learn anything, even if you examine the source code. And as for basing it off of the Basic version, there's no point. It will be an example of bad assembly coding, since it wasn't designed with assembly code in mind.

Really, just come up with an idea and try to do it in assembly code. It's fun, and it's how I started out myself. Set a goal and try to do it, piece by piece. We'll be here to help Smile
Back to top
simplethinker
snjwffl


Active Member


Joined: 25 Jul 2006
Posts: 700

Posted: 30 Jan 2009 01:27:56 am    Post subject:

When you're just loading a constant in, it's always best to just do "ld A, 9" (or whatever). One of the key differences between thinking in Asm and BASIC is that with BASIC you want to do as much as possible with one command and stuff like multiplication and boolean expressions are more efficient. With Asm, you can only do one thing at a time and trying to combine many things and do them once is often more cumbersome and complicated than doing them one at a time. Multiplication is considerably slower than "and" in Asm, so those "optimizations" in BASIC considerably slow Asm down.

You really have to change your mindset when switching (doing that is what finally made Asm click in my head), so instead of converting your BASIC program into Asm, start from scratch and try and formulate how your algorithm could be implemented in Asm (remember, at the highest level you're still only dealing with data 8 bits at a time Neutral ). I think Iambian put it perfectly in his tutorials
Quote:
...this language is the easiest in the world, but most people think too complex to understand its simplicity. Instead, one has to think in little chunks at a time, breaking up a task in the most simple of tasks done in sequence to achieve the desired effect


Quote:
3. If I just have the program I have converted as it is, I won't have to read thousands of tutorials trying to figure out what each little command does, and I can use code relation to get a fair basis of what a patch of code does.

Reading all the documentation and lots of tutorials actually is the best way to learn (besides lots and lots of first hand experience of course :biggrin:). If you don't know what's out there and just use the commands people recommend to you then you don't have a wide enough knowledge of the language to be able to go out and make any kind of programs yourself. Assembly is something that you just have to "get the hang of" by practice and experimentation.

TI's documentation on assembly is a must as a reference. WikiTI has a bit more information on the bcalls and how to handle some things not heavily covered in most tutorials.

Good luck with this. We're here to help :biggrin:
And welcome to UTI!
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 30 Jan 2009 01:50:16 am    Post subject:

The things that are easy to do in assembly are rather different from the things that are easy to do in BASIC. Start out with something simple and highly interactive, like a game. Nothing that requires complicated algorithms.

I must disagree that Z80 assembly is the "easiest", but I agree with the spirit of that statement Smile
Back to top
Trogdorgar


Newbie


Joined: 26 Jan 2009
Posts: 8

Posted: 30 Jan 2009 08:17:29 am    Post subject:

Alright, thanks, I'll check out more tutorials and try out Cobb's tutorial, since apparently this has a good documentation about b_calls, since i have already red "Learn assembly in 28 days" and didn't learn much about b_calls from it.

You guys just continue to work on the Assembly sudoku solver, since i know that will be a good challenge for you, and would be a cool UTI project, like a assembly version of the scanraid.com sudoku solver, for ppl that dont have laptops :lol:

I will make sure to add all the names of the people who helped me put this together into the Credits whenever the program is finished, or as it is being worked on.
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 31 Jan 2009 03:24:35 pm    Post subject:

Heh. Assembly is definitely very different from bASIC. You probably want to get the best feel of asm through smaller programs and then progress to this sudoku solver. ;o
Back to top
Trogdorgar


Newbie


Joined: 26 Jan 2009
Posts: 8

Posted: 04 Feb 2009 11:46:36 pm    Post subject:

Yeah, thats what i'm planning on, just gonna start slow, so i don't annihalate my ti-84 lol.

Sorry for the delay in reply, having computer troubles, a virus took out my main computer, and now somethin went wrong with our backup PC and now it wont even start, so i'm replying from the laptop... kinda sucks lol.
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 09 Feb 2009 02:54:41 pm    Post subject:

I haven't patient lately to put your program on my calc and see how it works deeply. (and also I have school work...)

I could make an solver like the attached. I did it and I know very well how it works. Interested?


Last edited by Guest on 09 Feb 2009 02:55:56 pm; edited 1 time in total
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement