a86 Palindrome

awuja awuja is offline Offline Nov 12th, 2009, 10:44 pm |
0
Hey guys.. need some help with this; I'm pulling my hair out.. i've trawled these boards but can't find anything that answers my question.

I, like many others before me (so it seems!) am trying to create a program to check for a palindrome.. this is what I have so far.

In the compare part.. it's just not working. I know I'm doing something wrong with SI and DI.. I just don't know what.

Any explanations would be greatly appreciate!

Thanks,

awuja
Quick reply to this message  
Assembly Syntax
  1. JMP START
  2.  
  3. CR equ 13 ; RETURN is 13D ASCII
  4. LF equ 10 ; LINE FEED is 10D ASCII
  5.  
  6. letterUnitCount DB 0
  7. letterTensCount DB 0
  8. vowelCount DB 0
  9.  
  10. getWord: DB "Please enter a word",CR, LF,"$"
  11. letterCountMessage: DB CR, LF, "Number of Characters: ", "$"
  12.  
  13. msg1: DB CR, LF, " this is palindrome!", "$"
  14. msg2: DB CR, LF, " this is not a palindrome!", "$"
  15.  
  16. inWord: DB 128 DUP (0)
  17.  
  18. START:
  19. LEA DX,getWord ;Output string asking user for word
  20. MOV AH,09h ;DOS call to output string
  21. INT 21H ;Execute interrupt 21H
  22.  
  23. KEYBUF:
  24. LEA DI,inWord ;Load inWord start address into DI
  25.  
  26. NEXTCHAR:
  27. MOV AH,01h
  28. INT 21H ;Read key pressed and echo to screen
  29.  
  30. CMP letterUnitCount, 10
  31. JE ROLLOVER
  32.  
  33. UNIT:
  34. INC letterUnitCount
  35.  
  36.  
  37. ;CMP AL, 65
  38. ;JE INCRVOWEL
  39. ;CMP AL, 97
  40. ;JE INCRVOWEL
  41.  
  42. STORE:
  43. MOV [DI],AL ;store in inWord at position [DI]
  44. INC DI ;Make DI point to next byte in inWord
  45. CMP AL,0Dh ;Was it the carriage return key?
  46. JNZ NEXTCHAR ;NO, get some more characters
  47. MOV [byte ptr DI],"$" ;YES, add end of string marker
  48.  
  49. MOV SI, DI
  50.  
  51. COMPARE:
  52.  
  53. ADD SI, DI
  54. DEC SI
  55.  
  56. MOV AL, [DI]
  57.  
  58. MOV DL, AL
  59. MOV AH, 2
  60. INT 21h
  61.  
  62. MOV BL, [SI]
  63.  
  64. MOV DL, BL
  65. MOV AH, 2
  66. INT 21h
  67.  
  68. CMP AL,BL
  69. JNE NOTPAL
  70.  
  71. INC DI
  72. DEC SI
  73. LOOP COMPARE
  74.  
  75. ISPAL:
  76. MOV DX, msg1
  77. MOV AH, 09h
  78. INT 21h
  79.  
  80. NOTPAL:
  81. MOV DX, msg2
  82. MOV AH, 09h
  83. INT 21h

Message:


Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC