Old lady swallowed a fly: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add 8080 assembly) |
Not a robot (talk | contribs) (Add 8086 assembly) |
||
Line 97: | Line 97: | ||
pop b ; restore counters |
pop b ; restore counters |
||
ret |
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|8086 Assembly}}== |
|||
<lang asm> 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 ; <animal> |
|||
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 ; <current animal> |
|||
call pbeast |
|||
mov dx,swlw2 ; to catch the |
|||
call prstr |
|||
dec bh ; <previous animal> |
|||
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 ' |
lady: db 'There was an old lady who swallowed a ' |
||
beasts: db '$fly$spider$bird$cat$dog$goat$cow$horse' |
beasts: db '$fly$spider$bird$cat$dog$goat$cow$horse' |