Hi,

So, I have this string:

Code:

.db "ABCDEFG"

How do I display 1 character of this string, like the "C"?

Thanks!
Here's a version of the canonical PutS, which should provide you with enough of a nudge in the right direction:

Code:
PutS:
; Read character from buffer
    ld a,(hl)
    inc hl
; Stop if zero (end-of-string)
    or a
    ret z
; Display the character in a
    bcall(_PutC)
; Continue with next character
    jr PutS

If you're familiar with PutS, you'll know that you point HL at the string you want to display.
Thus, in general, to display a character, you want to get it in A and call PutC. It might be as easy as loading the character value into A, or in most cases (including this one, it looks like) you'll read a byte from memory and use that.
aha thanks!
aeTIos, _PutC is exactly what you want, or _vputmap if you want the small (graphscreen) font.
Can someone give a code example?
I have a the value 3 in a and i want the A'th character of this string:

Code:

.db "ABCDEFGHI"

I just started learning ASM, so I didnt get really what The Tari meant.
Something like this:

Code:
; A = 3 coming in
; Adjust index (first character is indexed at 0)
    dec a
; DE = A
    ld e,a
    ld d,0
; Point HL to string
    ld hl,str
; HL -> str + A, the character we want
    add hl,de
; Read character..
    ld a,(hl)
; ..display
    bcall(_PutC)

str:
    .db "ABCDEFGHI"
I agree completely! AeTIos, notice especially the change from index-from-1 to index-from-0. If you can, it's ideal to design your systems to index from 0 instead of 1.
Yep, it's always easier in just about every language except TI-BASIC to start counting from zero.
That was very clear! Thanks!
Deep Thought wrote:
Yep, it's always easier in just about every language except TI-BASIC to start counting from zero.
And Matlab! That's the other important exception that makes me a sad panda.
KermMartian wrote:
Deep Thought wrote:
Yep, it's always easier in just about every language except TI-BASIC to start counting from zero.
And Matlab! That's the other important exception that makes me a sad panda.

I didn't know kermM was a panda. But yeah, dealing with trying to figure out if it starts with 0 or 1 was difficult at first, but I love starting with 0 now.
I learned QBASIC first, which didn't really have arrays, then TI-BASIC, so 1-offset was pounded into my head, but the same year I learned x86 ASM, then Perl, then PHP, then C, so I was swiftly switched to automatic 0-indexing. The only anomaly after that was Matlab.
KermMartian wrote:
I learned QBASIC first, which didn't really have arrays, then TI-BASIC, so 1-offset was pounded into my head, but the same year I learned x86 ASM, then Perl, then PHP, then C, so I was swiftly switched to automatic 0-indexing. The only anomaly after that was Matlab.

QBASIC has arrays. I'm pretty sure you could even reference index 0 in them. (When you DIM an array it would actually be 1 element larger than you asked for, so you could use it with either 0- or 1-indexing)
Christop, pardon, my post was extremely imprecise. I should have said "I learned QBASIC first, but didn't really use arrays." I think there was a disconnect between my brain and my fingers when I typed that sentence. That's cool to know about the indexing (although the trick would then be consistency!).
  
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