This is my first post, Don't really use forums much so I hope this is the right place to ask this stuff.

Background:
I'm a freshman in college, Have been messing around with TI-BASIC since Sophmore year of high school. Besides TI-BASIC I can program Java, C++, BATCH, the normal stuff. At my college, we are not allowed to use programmable calculators for quizzes and tests, so my trusty TI hasn't gotten much love recently. So about a week ago I decided that I was going to finally learn z80 assembly! (I actually own a TI84+ CE, but I figured that there would be a lot more resources online for z80 asm, so I decided to learn that).
The first few days were terrible. I couldn't get anything to work from any of the resources I found (Mostly Learn TI-83 asm in 28 days), But not too long ago I found an online z80 assembler at clrhome.org/ And that made it easy to write code and move to my TI-83+ emulator.
So I've been following the 28 days tutorial and a using a few other resources and The following mess of code is the result of me trying to use what i've learned so far. I know its probably terrible and the only way for me to get better is for more experienced programmers to tell me how why I suck.
So Heres my code, you press the up and down arrow keys to increase or decrease an 8-bit number, Then you press enter to save that number, then you select a new number, and it adds those 2 numbers together. Tear it apart, Tell me what I should of done and why, Tell me what exactly I did wrong wherever it applys. Thanks Smile


Code:
; Learning ASM Day 4
; Exercise using:
;   1. Getting User Input
;   2. Displaying Number
;   3. The Stack (Only a lil bit)

#include "ti83plus.inc"
#define progStart $9D95
#define   number   0
.org progStart-2
.db $BB,$6D
bcall(_RunIndicOff)
bcall(_ClrLCDFull)
ld DE,0
ld (CurRow),DE
ld c,number
ld b,1   ;B is a counter for how many numbers to add, 2

PreLoop:
push de
call DisplayNumber
pop de
KeyLoop:   ;Repeat until Correct Button Pressed
bcall(_GetCSC)
cp skUp
call z,Increase
cp skDown
call z,Decrease
cp skEnter
jr z,StoreNumber
jr KeyLoop

Increase:
ld a,c
cp 255
ret z   ;If number is 255 dont increase
inc c
push de
call DisplayNumber
pop de
ret

Decrease:
ld a,c
cp 0   ;If number is 0 dont decease
ret z
dec c
push de
call DisplayNumber
pop de
ret

StoreNumber:
bcall(_NewLine)
ld a,b
cp 0   ;If this is the Second number
jr z,Finish   ;Goto End

dec b
ld d,c   ;Store Current Numer in D
ld c,number   ;reset c
jr PreLoop

Finish:
ld a,d   ;Put first number in A
add a,c   ;add first and 2nd numbers
ld c,a
call DisplayNumber
ret

DisplayNumber:   ;Sets Cursor all the way left and displays HL
ld H,0
ld a,H
ld (CurCol),a
ld L,c
bcall(_DispHL)
ret
From what I see so far: when you press UP it modifies register A, which is checked after that. Also, the increase and decrease routine both display the number, but you can also jump to the loop where it displays the numbers at first. Seems to work fine besides this though! Smile
P.S. You can also use our own SourceCoder3 with has z80 support and an integrated emulator. Smile
KaneE. wrote:
(I actually own a TI84+ CE, but I figured that there would be a lot more resources online for z80 asm, so I decided to learn that).
Interesting that you say you have a CE but the code indicates you're running on a plain-83+ emulator. They're largely similar, so if you're willing to wade through something of a lack of documentation it might be nicer just to write eZ80 code.

Quote:
The first few days were terrible. I couldn't get anything to work from any of the resources I found (Mostly Learn TI-83 asm in 28 days
We've done some work on updating 83pa28d to be more modern, but never got very far on actually updating the content. It would be neat if you wanted to contribute some thoughts back. Razz
Quote:
), But not too long ago I found an online z80 assembler at clrhome.org/ And that made it easy to write code and move to my TI-83+ emulator.
As PT_ observes, Sourcecoder may make that build/debug loop easier yet.

You might be interested in how Sourcecoder does its assembly- it's based on SPASM-ng compiled into Javascript with emscripten. SPASM is the most-maintained of the more traditional assemblers used by the community; some have recently started using fasmg instead.



I've already spent too long working on the forum this evening, so I'll leave the code to others and/or future-me.
Tari wrote:
SPASM is the most-maintained of the more traditional assemblers used by the community; some have recently started using fasmg

As a heads up, (reference url) fasmg is by far recommend for any new ez80 designs. Smile
MateoConLechuga wrote:
Tari wrote:
SPASM is the most-maintained of the more traditional assemblers used by the community; some have recently started using fasmg

As a heads up, (reference url) fasmg is by far recommend for any new ez80 designs. Smile
Which is to say, there's the pile of things you need to make it work as a TI-eZ80 assembler apparently.

You've been saying it's better, but IMHO that needs some justification (but it's not really relevant to this discussion).
I wouldn't recommend that most use fasmg. Most existing assembly references were written for TASM or SPASM. There are some syntax and many semantic differences between these assemblers and fasmg, and fasmg is generally more complex. This complexity is due to fasmg being capable of much more advanced things, but this can obstruct and confuse more than it helps.

tl;dr: Unless you're a seasoned Z80/eZ80 coder (and perhaps even if you are), use spasm-ng.
  
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
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement