Old lady swallowed a fly: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add MAD) |
Not a robot (talk | contribs) (Add 8080 assembly) |
||
Line 37: | Line 37: | ||
print(animals[0][1]) |
print(animals[0][1]) |
||
print()</lang> |
print()</lang> |
||
=={{header|8080 Assembly}}== |
|||
<lang 8080asm> org 100h |
|||
mvi c,-1 ; C = verse counter |
|||
verse: inr c |
|||
lxi d,lady ; There was an old lady who swallowed a ... |
|||
call prstr |
|||
mov e,c ; <animal> |
|||
call pbeast |
|||
lxi d,comma |
|||
call prstr |
|||
mov e,c ; verse |
|||
call pverse |
|||
mov a,c ; is this the first verse? |
|||
ana a |
|||
jz verse ; then we're not swallowing animals yet |
|||
cpi 7 ; otherwise, is the lady dead yet? |
|||
rz ; if so, stop. |
|||
mov b,c ; otherwise, start swallowing |
|||
swallo: lxi d,swlw1 ; She swallowed the |
|||
call prstr |
|||
mov e,b ; <current animal> |
|||
call pbeast |
|||
lxi d,swlw2 ; to catch the |
|||
call prstr |
|||
dcr b |
|||
push psw ; store state (is B zero now) |
|||
mov e,b ; <previous animal> |
|||
call pbeast |
|||
lxi d,comma |
|||
call prstr |
|||
mov a,b |
|||
cpi 2 |
|||
mov e,b ; print associated verse if < 2 |
|||
cc pverse |
|||
pop psw ; was B zero? |
|||
jnz swallo ; if not, swallow more |
|||
jmp verse ; if so, next verse |
|||
prstr: push b ; print string in DE |
|||
mvi c,9 |
|||
call 5 |
|||
pop b |
|||
ret |
|||
pverse: lxi h,verses |
|||
jmp pstrn |
|||
pbeast: lxi h,beasts |
|||
;;; Print the E'th string from the list at HL |
|||
pstrn: push b ; keep counters in B and C |
|||
mvi a,'$' ; end-of-string marker |
|||
inr e |
|||
pscan: cmp m ; keep going until we find one |
|||
inx h |
|||
jnz pscan |
|||
dcr e ; is this the one we wanted? |
|||
jnz pscan ; if not, keep going |
|||
xchg ; otherwise, put in DE |
|||
mvi c,9 ; print string using CP/M |
|||
call 5 |
|||
pop b ; restore counters |
|||
ret |
|||
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,'$'</lang> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |