This popped into my mind: what if you want to display a large amount of text? I assume there's some better way than loading each individual character. The book I'm reading may explain it in a later chapter, and maybe it's counterproductive for me to ask at this point! Not looking for a code example right now. But someone please assure me assembly isn't always * this tedious *.
I hate to be the bearer of bad news but assembly language is probably the most tedious of programming environments. The tradeoff is that it's also the most powerful in many ways. Good assembly language programmers have libraries of frequently needed routines (e.g. to print text or do 16 bit manipulations). I have not programmed the Apple but on Heathkit machines there are many such useful routines embedded in the machine's ROMs (I'm sure that's true for Apple too). Others were freely distributed with the OS or through Heath User's group (HUG). Glad you're getting some real experience "close to the hardware"! Hang in there! - Glenn
-----Original Message----- From: vcf-midatlantic [mailto:vcf-midatlantic- bounces@lists.vintagecomputerfederation.org] On Behalf Of Evan Koblentz via vcf-midatlantic Sent: Sunday, July 30, 2017 4:52 AM To: Vcf <vcf-midatlantic@lists.vintagecomputerfederation.org> Cc: Evan Koblentz <evan@vcfed.org> Subject: Re: [vcf-midatlantic] Woohoo!
This popped into my mind: what if you want to display a large amount of text? I assume there's some better way than loading each individual character. The book I'm reading may explain it in a later chapter, and maybe it's counterproductive for me to ask at this point! Not looking for a code example right now. But someone please assure me assembly isn't always * this tedious *.
On 7/30/2017 4:52 AM, Evan Koblentz via vcf-midatlantic wrote:
This popped into my mind: what if you want to display a large amount of text? I assume there's some better way than loading each individual character. The book I'm reading may explain it in a later chapter, and maybe it's counterproductive for me to ask at this point! Not looking for a code example right now. But someone please assure me assembly isn't always * this tedious *.
I posted what follows on Facebook and share it with members here with the understanding that while my expertise is in teaching high school students 6502 assembly and I'm pretty good at breaking things down into digestible bites there are people on this list here who know *insanely* more about 6502 assembly than I do, so feel free to to tear me apart. All is good in the pursuit of knowledge! --- It depends on what you need by a larger amount of text. A line or a couple of lines, you'd use a loop. A lot more than that, you might have to read it off disk.. which is an entirely different conversation. Check out this for a simple hello world Merlin style: http://ceos.io/dev/hello.s <https://l.facebook.com/l.php?u=http%3A%2F%2Fceos.io%2Fdev%2Fhello.s&h=ATN45XJBM8cUfJumY0xMqdCGrpW6IcGneJFP0wksTOwbaUEhlZbFPb5GwoMJqOObCpTQj8fue7Q21rOb5-0pRIM89QCcpNB0fbXWrUJkIS1A5cFeuy4PlX-fjPU5QfIOtCiH0AmRBQ> A few things to note: We put the characters directly into memory. Memory stores both the program and any data for the program. This is possible without an assembler, but you then have to hand calculate the addresses for all the data (kind of like when you have to hand calculate PEEKs in BASIC). The BEQ and BPL instructions are what are called branch logic conditions. Think of them kind of like an if statements. The BEQ is interesting because we take advantage of the 0 at the end of the string (so called NULL termination - note the HEX 0 after the ASC command). So we load each character into the A register, print each character, and then check if equal. Well, testing for equal just means subtract (if the subtraction equals 0, the two numbers are equal, set the zero status flag). So if we load 0 in A, we also set the zero status flag and get to skip the subtraction part. The zero status flags tells the computer to take the branch and we brand to the RTS at the end of the program. All done. What is tricky about hand coding branch instruction is it uses *relative* addressing. That is, you don't say: Branch to 0300hex and do something you say: Branch -30hex relative to my current memory address This has the amazing advantage of lowering the memory requirements of the program (since you need only the storage for the opcode - always - and the and the smaller relative address). But it also limits how far you can branch. FFhex instead of FFFFhex. This, however, is a prime reason to use an assembler. If you hand assemble you have to figure out the relative address on your own. And if you are going backwards in memory, you have to know how the Apple II represents negative numbers (something called 2s complement notation). Ever wonder why you do CALL -151? 2s complement notation. But, see, the wonderful assembler just does this all for you since it can easily calculate relative addresses and knows all about things like 2s complement notation. Not to discourage you from learning 2s complement notation, but it will make a lot more sense once you've assembled a few programs with something like Merlin. --- -Adam
On 07/30/2017 08:19 AM, Adam Michlin via vcf-midatlantic wrote:
On 7/30/2017 4:52 AM, Evan Koblentz via vcf-midatlantic wrote:
This popped into my mind: what if you want to display a large amount of text? I assume there's some better way than loading each individual character. The book I'm reading may explain it in a later chapter, and maybe it's counterproductive for me to ask at this point! Not looking for a code example right now. But someone please assure me assembly isn't always * this tedious *.
...
It depends on what you need by a larger amount of text. A line or a couple of lines, you'd use a loop. A lot more than that, you might have to read it off disk.. which is an entirely different conversation.
Check out this for a simple hello world Merlin style:
Thanks. Presumably/hopefully the "ASC" command is covered later in the book.
The BEQ and BPL instructions are what are called branch logic conditions...
I understand branching in theory but I don't understand most of your detailed explanation. Fortunately I don't * need * to understand that right now. Will save your message for when the right time arrives.
On Jul 30, 2017, at 4:52 AM, Evan Koblentz via vcf-midatlantic <vcf-midatlantic@lists.vintagecomputerfederation.org> wrote:
This popped into my mind: what if you want to display a large amount of text? I assume there's some better way than loading each individual character. The book I'm reading may explain it in a later chapter, and maybe it's counterproductive for me to ask at this point! Not looking for a code example right now. But someone please assure me assembly isn't always * this tedious *.
There are lots of common routines to do this. A good collection of handy 6502 routines is here: http://www.6502.org/source/ <http://www.6502.org/source/> There’s an entry for PRIMM, and if follow that page to the last version (by Russ Archer) you’ll see a very nice way of doing it. Just change to your local character-output subroutine. jsr PUTSTRI db “Hello world. Wow.” db 0 Let’s not get into religious discussions about whether strings should be in-line with the code or not. This was just an example. Suggestions on your original code: Use labels, not hard coded addresses (“magic numbers”). Most assemblers also allow character constants, like: lda #’H’ jsr OUTCH Etc. Use of magic numbers is highly discouraged and would fail pretty much any code review. But… congrats on your first 6502 assembly language program! Bob
There’s an entry for PRIMM, and if follow that page to the last version (by Russ Archer) you’ll see a very nice way of doing it. Just change to your local character-output subroutine.
jsr PUTSTRI db “Hello world. Wow.” db 0
Interesting! What are the pros/cons of doing it this way vs. the way Adam posted (http://ceos.io/dev/hello.s)?
Suggestions on your original code:
Use labels, not hard coded addresses (“magic numbers”). Most assemblers also allow character constants, like:
lda #’H’ jsr OUTCH
I'll try that. I suppose the book starts with hard-coded addresses to teach readers what happens underneath.
Etc. Use of magic numbers is highly discouraged and would fail pretty much any code review.
Understood.
But… congrats on your first 6502 assembly language program!
Thanks!
participants (4)
-
Adam Michlin -
Bob Applegate -
Evan Koblentz -
Glenn Roberts