Skip to main content

A palindrome checker in 16-bit DOS assembly

A good morning to start off is to get this simple program working. This is an improvement of the previous palindrome checker posted. What can we benefit from this anyway? :)



; palindrome checker

start:
mov ah, 0ah
lea dx, strptr
int 21h

lea di, string
lea si, strlen
mov cl, [si]
xor ch, ch
mov bx, cx
lea si, string
shr cl, 1

check:
mov dl, [si]
mov dh, [di+bx-1]
cmp dl, dh
jne notpal
inc si
dec di

loop check

cmp dl, dh
je pal

notpal:
mov ah, 09h
lea dx, msg2
int 21h
int 20h

pal:
mov ah, 09h
lea dx, msg1
int 21h
int 20h

strptr label byte
maxlen db 49
strlen db ?
string db 50 dup ('$')
msg1 db '',10,'string is a palindrome!$'
msg2 db '',10,'string is not a palindrome!$'

“If God’s people which are called by His name, will humble themselves and pray, and seek His face, and turn from their wicked ways; then He will hear from heaven, and will forgive their sins, and will heal their land.” - 2 Chron 7:14

Comments

Popular posts from this blog

Architecture Complexity

Here are the items to consider: Coding to an interface Service Oriented Architecture Automated Testing Domain Driven Design Custom Data Access Layer Layered architecture Complexity is relatively equal the number of lines of code. Note that complexity is not bad. It must be justified.

Moving on

So I bought my self a 2.5″ hard drive enclosure for about 750 bucks. I wish I have my own tools for constructing a device as such. Instead of going for a 2GB USB flash drive, I chose to salvage the 30GB hard drive of an incapacitated laptop. Cool isn’t it? Though relatively slower than a typical USB flash drive, the storage capacity outweighs it. [To God] Thanks for being there always.

Bin to hex converter in 16-bit DOS assembly

Just a quick code like putting your keyboard where your brain is. There should be another way of doing this. I hate this code. start: xor al, al xor bl, bl xor cl, cl mov dl, 4 ; use dl as counter input: mov ah, 00 int 16h cmp ah, 1ch je exit cmp al, '0' jb input cmp al, '1' ja input convert: mov cl, dl dec cl ; dl - 1 sub al, 30h ; get original value shl al, cl ; place in the appropriate bit position or bl, al ; save in bl dec dl ; prepare for the next bit jnz input ; must be 4 bits cmp bl, 9 ja letter jbe number letter: add bl, 37h ; because 'A' - 37h is 0Ah jmp here number: add bl, 30h ; because '0' - 30h is 00h here: call display jmp start display: mov ah, 02h ...