This is an assignment in assembly programming last year (2007). If I am not mistaken, this program ask the user to input a string/word (all in lowercase) and from that, the code will going to return all possible 2 letter word that is found in the predefined dictionary (found at the end of the code).
Thanks to Dino Bansigan for helping in this assignment. ;) Please do comment for any suggestion. Thanks!
;----------- start of code
lea dx, msg
mov ah, 09
int 21h
lea dx, input
mov ah, 0ah
int 21h
mov dl, 0dh
mov ah, 02
int 21h
mov dl, 0ah
int 21h
lea dx, msga
mov ah, 09
int 21h
mov dl, 0dh
mov ah, 02
int 21h
mov dl, 0ah
int 21h
lea si, actlen
mov al, [si]
mov cl, al
cmp cl, 1
je invalid
mov bh, 0
mov bl, 0
next:
mov ch, 0
lea si, dictionary
lea di, temp
mov al, [si+bx]
cmp al, 33
je exit
mov [di], al
inc di, 1
inc bx, 1
mov al, [si+bx]
cmp al, 33
je exit
mov [di], al
inc bx, 2
lea si, temp
lea di, string
compare:
mov al, [si]
cmp al, [di]
je compare2
inc di, 1
inc ch, 1
cmp ch, cl
je next
jmp compare
compare2:
inc si, 1
lea di, string
mov ch, 0
compare3:
mov al, [si]
cmp al, [di]
je display
inc di, 1
inc ch, 1
cmp ch, cl
je next
jmp compare3
display:
lea dx, temp
mov ah, 09
int 21h
mov dl, 0dh
mov ah, 02
int 21h
mov dl, 0ah
int 21h
jmp next
invalid:
lea dx, msge
mov ah, 09
int 21h
int 20h
exit:
int 20h
input label byte
maxlen db 255
actlen db ?
string db 255 dup('$')
temp db 3 dup('$')
msg db "Enter a word with only lowercase letters: $"
msga db "2 letter words found from input: $"
msge db "Invalid Input!$"
dictionary db "aa ab ad ae ag ah ai al am an ar as at aw ax ay ba be bi bo by de do ef eh el em en er es et ex fa go ha he hi hm ho if in is it jo ka la li lo ma me mi mm mo mu my na ne no nu od oe of oh om on op or os ow ox oy pa pe pi re sh si so ta ti to uh um un up us ut we wo xi xu ya ye yo!$"
;------ end of code

0 comments:
Post a Comment