How to resolve the algorithm The Twelve Days of Christmas step by step in the 8080 Assembly programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm The Twelve Days of Christmas step by step in the 8080 Assembly programming language
Table of Contents
Problem Statement
Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas.
The lyrics can be found here.
(You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.)
Let's start with the solution:
Step by Step solution about How to resolve the algorithm The Twelve Days of Christmas step by step in the 8080 Assembly programming language
Source code in the 8080 programming language
CR: equ 13
LF: equ 10
puts: equ 9 ; CP/M function to write a string to the console
bdos: equ 5 ; CP/M entry point
org 100h
mvi e,0 ; Start with first verse
;;; Print verse
verse: lxi h,onthe ; On the
call pstr
lxi h,ordtab
call ptabs ; Nth
lxi h,doc
call pstr ; day of Christmas, my true love gave to me
lxi h,vrstab
call ptabs ; ...whatever stuff
inr e ; next verse
mov a,e
cpi 12 ; if at 12, stop
jnz verse ; otherwise, print another verse
ret
;;; Print the E'th string from the table under HL,
;;; preserving DE registers.
ptabs: push d ; Save DE registers
mvi d,0 ; Add E*2 to HL, looking up the pointer
dad d
dad d
mov a,m ; Load low byte of pointer
inx h
mov h,m ; Load high byte of pointer
mov l,a
xchg ; Store pointer in DE
mvi c,puts ; Print string in DE using CP/M
call bdos
pop d ; Restore registers
ret
;;; Print the string under HL, preserving DE registers.
pstr: push d
xchg
mvi c,puts
call bdos
pop d
ret
ordtab: dw first,second,third,forth,fifth,sixth
dw _7th,eighth,ninth,tenth,_11th,_12th
vrstab: dw one,two,three,four,five,six,seven,eight
dw nine,ten,eleven,twelve
onthe: db 'On the $'
first: db 'first$'
second: db 'second$'
third: db 'third$'
forth: db 'forth$'
fifth: db 'fifth$'
sixth: db 'sixth$'
_7th: db 'seventh$'
eighth: db 'eighth$'
ninth: db 'ninth$'
tenth: db 'tenth$'
_11th: db 'eleventh$'
_12th: db 'twelfth$'
doc: db ' day of Christmas',CR,LF
db 'My true love gave to me:',CR,LF,'$'
twelve: db 'Twelve drummers drumming',CR,LF
eleven: db 'Eleven pipers piping',CR,LF
ten: db 'Ten lords a-leaping',CR,LF
nine: db 'Nine ladies dancing',CR,LF
eight: db 'Eight maids a-milking',CR,LF
seven: db 'Seven swans a-swimming',CR,LF
six: db 'Six geese a-laying',CR,LF
five: db 'Five golden rings',CR,LF
four: db 'Four calling birds',CR,LF
three: db 'Three french hens',CR,LF
two: db 'Two turtle doves and',CR,LF
one: db 'A partridge in a pear tree.',CR,LF
db CR,LF,'$'
You may also check:How to resolve the algorithm 100 doors step by step in the Lily programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the DUP programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the SAS programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the Pure programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the J programming language