Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I need help with my 8085 assembly palindrome checking program for class

Status
Not open for further replies.

xXFrostXx

New Member
Yeah, we're supposed to create an 8085 assembly program to check if words/sentences that the user types in are palindromes (ex. racecar). I found a flow chart online for a program that checks if a number defined in the program(not user input) is a palindrome, and from that I get the general sense of what I need to do(RLC, RRC, and CMP stuff mostly) but there's one thing that's confusing me and it's driving me nuts. User. input. The code I know for reading user input sends one character at a time to the A register. For this program to work(far as I know), my thinking is I need to be able to have it send a whole string of letters to the A register(I can have it weed out any non-letter characters and ignore them) so I can then rotate the register.

I know two ways of printing output to the screen:
mvi c, 2
mov e,'A'
call bdos ;bdos defined at the start of the program as 05 hex

and

mvi c,9
mov d,mess1 ;mess1 is a string like 'Hi, please enter a letter.$' defined after the program code
call bdos

The latter prints a string whereas the former prints only one character. So I'm thinking

mvi c,1
call bdos

isn't the only code for reading user input. Please tell me if any of my thinking here is even close to correct, because this is driving me nuts and I'm not getting myself dinner until I finish this stupid thing.
 
Tell me if I am wrong by missing what your problem is:

A register (a byte - 8 bits) cannot contain but one character (ASCII code?) at a time.

You need first to enter (user input) the whole word what would take a variable number of those bytes. Have you identified what registers (or simple memory positions) are these?

Once done, you then start checking maybe with register A as the "compare with" target byte.

I am 100% self taught and any code I write is based on a flow chart.

Could you show yours? At the beginning, it is a good practice to note with what data into what bytes you start that part of the code.
 
This is an example of some of the code I've been taught, including the bdos stuff. This sample program converts a user-typed lowercase letter to uppercase.
Code:
bdos      equ    5            ; CP/M function call address
   boot      equ    0            ; address to get back to CP/M
   conin     equ    1            ; keyboard read function number
   conout    equ    2            ; console output function number
   sprint    equ    9            ; string print function number
   cr        equ    0Dh          ; value of ASCII code of <CR>
   lf        equ    0Ah          ; value of ASCII code of line feed
;
             org    100h         ; standard origin for CP/M
             lxi    sp,sp0       ; initialize stack pointer
;
             mvi    c,sprint     ; print welcome message 
             lxi    d,mess1      ; (the message at mess1 is printed through
             call   bdos         ; these three lines)

   Do:       mvi    c,sprint     ; prompt user for an input
             lxi    d,mess4
             call   bdos

             mvi    c,conin      ; the ASCII code of the character is read
             call   bdos         ; into A reg. through these two instructions

             cpi    cr           ; determine if a <CR> was typed in
             jz     donot        ; if so, end the program

             mvi    c,sprint     ; print string at mess2
             lxi    d,mess2
             call   bdos

             cpi    'a'
             jc     nocvt        ; trying to find if in the range 'a' to 'z'
             cpi    'z'+1        ; if so then convert to Capital
             jnc    nocvt
             adi    'A'-'a'

   nocvt:    cpi    'A'          
             jc     junk         ; trying to find if input was a letter
             cpi    'Z'+1
             jnc    junk

             mvi    c,conout     ; if so, then print that letter
             mov    e,a
             call   bdos
             jmp    last         ; and jump to the end

   junk:     mvi    c,sprint    ; else print the message at mess3 and
             lxi    d,mess3      ; go to the end
             call   bdos

   last:     jmp    do           ; and do the complete thing again

   donot:    mvi    c,sprint    ; print a log out message
             lxi    d,mess5
             call   bdos
             jmp    boot         ; and get back to the operating system

;  This ends the program.  Data and stack area follows.
;  Note all messages printed with function 9 MUST end with '$'.

   mess1:    db     'Capital Converter (Hit ENTER key to end).$'
   mess2:    db     ' ====> $'
   mess3:    db     lf,cr,'Are you sure you passed your first grade?$'
   mess4:    db     lf,cr,'Please type in a letter  : $'
   mess5:    db     lf,cr,'I hope you now know your alphabet better.',lf,'$'

             ds     20           ; 20 bytes reserved for stack
   sp0       equ    $            ; initial address of stack pointer
;
             end                 ; just another assembler directive

And we just have an 8085 simulator for our laptops, along with an assembler.
 
Last edited:
Are you checking complete strings, words or single chars to see if they are palindromes? You don't need bdos routines to check... Unless there's a routine for it... I checked the available routines CP/M bios and its very small to say the least.

You'll need a small loop to send several characters from a string as you can only check one character at a time.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top