Task

Create Magic 8-Ball.



See details at:   Magic 8-Ball.




Other tasks related to string operations:

Metrics
 Array length
 String length
 Copy a string
 Empty string  (assignment)
Counting
 Word frequency
 Letter frequency
 Jewels and stones
 I before E except after C
 Bioinformatics/base count
 Count occurrences of a substring
 Count how many vowels and consonants occur in a string
Remove/replace
 XXXX redacted
 Conjugate a Latin verb
 Remove vowels from a string
 String interpolation (included)
 Strip block comments
 Strip comments from a string
 Strip a set of characters from a string
 Strip whitespace from a string -- top and tail
 Strip control codes and extended characters from a string
Anagrams/Derangements/shuffling
 Word wheel
 ABC problem
 Sattolo cycle
 Knuth shuffle
 Ordered words
 Superpermutation minimisation
 Textonyms (using a phone text pad)
 Anagrams
 Anagrams/Deranged anagrams
 Permutations/Derangements
Find/Search/Determine
 ABC words
 Odd words
 Word ladder
 Semordnilap
 Word search
 Wordiff  (game)
 String matching
 Tea cup rim text
 Alternade words
 Changeable words
 State name puzzle
 String comparison
 Unique characters
 Unique characters in each string
 Extract file extension
 Levenshtein distance
 Palindrome detection
 Common list elements
 Longest common suffix
 Longest common prefix
 Compare a list of strings 
 Longest common substring
 Find common directory path
 Words from neighbour ones
 Change e letters to i in words
 Non-continuous subsequences
 Longest common subsequence
 Longest palindromic substrings
 Longest increasing subsequence
 Words containing "the" substring
 Sum of the digits of n is substring of n
 Determine if a string is numeric
 Determine if a string is collapsible
 Determine if a string is squeezable
 Determine if a string has all unique characters
 Determine if a string has all the same characters
 Longest substrings without repeating characters
 Find words which contains all the vowels
 Find words which contains most consonants
 Find words which contains more than 3 vowels
 Find words which first and last three letters are equals
 Find words which odd letters are consonants and even letters are vowels or vice_versa
Formatting
 Substring
 Rep-string
 Word wrap
 String case
 Align columns
 Literals/String
 Repeat a string
 Brace expansion
 Brace expansion using ranges
 Reverse a string
 Phrase reversals
 Comma quibbling
 Special characters
 String concatenation
 Substring/Top and tail
 Commatizing numbers
 Reverse words in a string
 Suffixation of decimal numbers
 Long literals, with continuations 
 Numerical and alphabetical suffixes
 Abbreviations, easy
 Abbreviations, simple
 Abbreviations, automatic
Song lyrics/poems/Mad Libs/phrases
 Mad Libs
 Magic 8-ball
 99 Bottles of Beer
 The Name Game (a song)
 The Old lady swallowed a fly
 The Twelve Days of Christmas
Tokenize
 Text between
 Tokenize a string
 Word break problem
 Tokenize a string with escaping
 Split a character string based on change of character
Sequences
 Show ASCII table
 De Bruijn sequences
 Self-referential sequences
 Generate lower case ASCII alphabet




 
.model small
.stack 1024
 
.data
UserRam BYTE 256 DUP(0)
xorshift32_state_lo equ UserRam
xorshift32_state_hi equ UserRam+2
 
Ans0 byte "It is certain.",0
Ans1 byte "It is decidedly so.",0
Ans2 byte "Signs point to yes.",0
Ans3 byte "You can rely on it.",0
Ans4 byte "Most likely.",0
Ans5 byte "Cannot predict now.",0
Ans6 byte "Reply hazy, try again.",0
Ans7 byte "Outlook not so good.",0
Ans8 byte "My sources say no.",0
Ans9 byte "Very doubtful.",0
AnsA byte "Without a doubt.",0
AnsB byte "Outlook good.",0
AnsC byte "Ask again later.",0
AnsD byte "Better not tell you now.",0
AnsE byte "Don't count on it.",0
AnsF byte "Yes.",0
 
AnswerLookup word Ans0,Ans1,Ans2,Ans3,Ans4,Ans5,Ans6,Ans7
	     word Ans8,Ans9,AnsA,AnsB,AnsC,AnsD,AnsE,AnsF
.code
 
start:
 
	mov ax,@data
	mov ds,ax
 
	mov ax,@code
	mov es,ax
 
 
	CLD	;have LODSB,MOVSB,STOSB,etc. auto-increment
 
	mov ax,03h
	int 10h        ;sets video mode to MS-DOS text mode. Which the program is already in, so this just clears the screen.
 
	mov ah,2Ch
	int 21h         ;returns hour:minute in cx, second:100ths of second in dx
        mov word ptr [ds:xorshift32_state_lo],dx
        mov word ptr [ds:xorshift32_state_hi],cx
 
	call doXorshift32 ;uses the above memory locations as input. Do it three times just to mix it up some more
	call doXorshift32
	call doXorshift32
 
	mov ax,word ptr[ds:xorshift32_state_lo] ;get the random output from the RNG
	and al,0Fh		
	;keep only the bottom nibble of al, there are only 16 possible messages.
	mov bx,offset AnswerLookup
	call XLATW
	;translates AX using a table of words as a lookup table.
	mov si,ax         ;use this looked-up value as the source index for our text.
	call PrintString  ;print to the screen
 
	mov ax,4C00h
	int 21h        ;return to DOS
 
XLATW:
;input: ds:bx = the table you wish to look up
;AL= the raw index into this table as if it were byte data.
;So don't left shift prior to calling this.
;AH is destroyed.
		SHL AL,1
		mov ah,al	;copy AL to AH
		XLAT		;returns low byte in al
		inc ah
		xchg al,ah	;XLAT only works with AL
		XLAT		;returns high byte in al (old ah)
		xchg al,ah
		;now the word is loaded into ax, big-endian.
		ret