StNtMaN 0 Newbie Poster

Create a program that will input a sentence and push each character onto the stack all the while counting the number of characters. Then pop off each character and print them backwards (natural with a stack) and print the length. Like so:

I like burgers!

!sregrub ekil I

The number of characters is 15

Note, don't count the '\n' nor push it onto the stack. The stack should be empty when finished. Use an ".equate" to define a label to reference the top of the stack (can be any name but when you pop off the character, you need to use that label defined by the equate).

Note: Do NOT have a branch at the top like with the textbook examples. Place your data and the END of the program (before ".END") and have your program start at location 0 (WITHOUT the first branch). I'll ding you a point if you do.

Here is what I have so far...

ch:       .equate  1
count:   .equate   2
tos:     .equate   3
count2:  .equate   4
         lda      0,i 
         chari    ch,d 
         ldbytea  ch,d
for:     cpa      '\n',i
         breq    count  
         stbytea  -1,s
         subsp    1,i
         lda      count,d 
         adda     1,i
         sta      count,d

         charo    tos,s 
         addsp    1,s
         lda      count2,d 
         suba     1,i
         sta      count2,d
         stop
         .end

I really don't have much expertise with assembly and pep/8. Any help would be appreciated! Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.