How to resolve the algorithm Old lady swallowed a fly step by step in the 8086 Assembly programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Old lady swallowed a fly step by step in the 8086 Assembly programming language
Table of Contents
Problem Statement
Present a program which emits the lyrics to the song I Knew an Old Lady Who Swallowed a Fly, taking advantage of the repetitive structure of the song's lyrics. This song has multiple versions with slightly different lyrics, so all these programs might not emit identical output.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Old lady swallowed a fly step by step in the 8086 Assembly programming language
Source code in the 8086 programming language
cpu 8086
org 100h
section .text
mov bl,-1 ; BL = verse counter
verse: inc bl
mov dx,lady ; There was an old lady who swallowed
call prstr
mov dl,bl ;
call pbeast
mov dx,comma
call prstr
mov dl,bl ; verse
call pverse
test bl,bl ; is this the first verse?
jz verse ; then we're not swallowing anything yet
cmp bl,7 ; otherwise, is the lady dead yet?
je stop ; if so, stop.
mov bh,bl ; otherwise, start swallowing
swallo: mov dx,swlw1 ; She swallowed the
call prstr
mov dl,bh ;
call pbeast
mov dx,swlw2 ; to catch the
call prstr
dec bh ;
mov dl,bh
call pbeast
mov dx,comma
call prstr
cmp bh,2 ; print associated verse if BH<2
jae .next
mov dl,bh
call pverse
.next: test bh,bh ; is BH zero yet?
jnz swallo ; if not, swallow next animal
jmp verse ; otherwise, print next verse
pverse: mov di,verses ; Print verse DL
jmp pstrn
pbeast: mov di,beasts ; Print animal DL
;;; Print DL'th string from [DI]
pstrn: inc dl
mov al,'$' ; end-of-string marker
.scan: mov cx,-1
repne scasb
dec dl
jnz .scan
mov dx,di
prstr: mov ah,9 ; MS-DOS syscall to print a string
int 21h
stop: ret
section .data
lady: db 'There was an old lady who swallowed a '
beasts: db '$fly$spider$bird$cat$dog$goat$cow$horse'
verses: db '$I don',39,'t know why she swallowed that fly -'
db ' Perhaps she',39,'ll die.',13,10,13,10
db '$That wiggled and jiggled and tickled inside her!',13,10
db '$How absurd to swallow a bird',13,10
db '$Imagine that! She swallowed a cat!',13,10
db '$What a hog to swallow a dog',13,10
db '$She just opened her throat and swallowed that goat',13,10
db '$I don',39,'t know how she swallowed that cow',13,10
db '$She',39,'s dead, of course.',13,10,'$'
swlw1: db 'She swallowed the $'
swlw2: db ' to catch the $'
comma: db ',',13,10,'$'
You may also check:How to resolve the algorithm Hello world/Text step by step in the PASM programming language
You may also check:How to resolve the algorithm Sierpinski arrowhead curve step by step in the REXX programming language
You may also check:How to resolve the algorithm SHA-256 step by step in the Clojure programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the Io programming language
You may also check:How to resolve the algorithm Deepcopy step by step in the Julia programming language