How to resolve the algorithm The Twelve Days of Christmas step by step in the 8086 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 8086 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 8086 Assembly programming language

Source code in the 8086 programming language

CR:	equ	10
LF:	equ	13
puts:	equ	9	; MS-DOS syscall to print string
	cpu	8086
	bits	16
	org	100h
section	.text
	xor	cx,cx		; Start with first verse
verse:	mov	dx,onthe	; On the...
	call	pstr
	mov	si,ord.tab	; Nth
	call	ptabs
	mov	dx,doc		; day of Christmas, my true love
	call	pstr		; gave to me...
	mov	si,vrs.tab	; the gifts
	call	ptabs
	inc	cx		; Next verse
	cmp	cx,12		; If not last verse,
	jb	verse		; then print next verse.
	ret
	;;;	Print the CX'th string from the table in [SI].
ptabs:	mov	bx,cx		; BX = CX*2
	shl	bx,1		; (Each entry is 2 bytes wide)
	mov	dx,[bx+si]	; Retrieve table entry
	;;;	Print the string in DX.
pstr:	mov	ah,puts		; Tell DOS to print the string
	int	21h
	ret
section	.data
onthe:	db	'On the $'
ord:
.n1:	db	'first$'
.n2:	db	'second$'
.n3:	db	'third$'
.n4:	db	'forth$'
.n5:	db	'fifth$'
.n6:	db	'sixth$'
.n7:	db	'seventh$'
.n8:	db	'eighth$'
.n9:	db	'ninth$'
.n10:	db	'tenth$'
.n11:	db	'eleventh$'
.n12:	db	'twelfth$'
.tab:	dw	.n1,.n2,.n3,.n4,.n5,.n6
	dw	.n7,.n8,.n9,.n10,.n11,.n12
doc:	db	' day of Christmas',CR,LF
	db	'My true love gave to me:',CR,LF,'$'
vrs:
.n12:	db	'Twelve drummers drumming',CR,LF
.n11:	db	'Eleven pipers piping',CR,LF
.n10:	db	'Ten lords a-leaping',CR,LF
.n9:	db	'Nine ladies dancing',CR,LF
.n8:	db	'Eight maids a-milking',CR,LF
.n7:	db	'Seven swans a-swimming',CR,LF
.n6:	db	'Six geese a-laying',CR,LF
.n5:	db	'Five golden rings',CR,LF
.n4: 	db	'Four calling birds',CR,LF
.n3:	db	'Three french hens',CR,LF
.n2:	db	'Two turtle doves and',CR,LF
.n1:	db	'A partridge in a pear tree.',CR,LF
	db	CR,LF,'$'
.tab:	dw	.n1,.n2,.n3,.n4,.n5,.n6
	dw	.n7,.n8,.n9,.n10,.n11,.n12


  

You may also check:How to resolve the algorithm Count in octal step by step in the LFE programming language
You may also check:How to resolve the algorithm Play recorded sounds step by step in the Delphi programming language
You may also check:How to resolve the algorithm Department numbers step by step in the AWK programming language
You may also check:How to resolve the algorithm Death Star step by step in the Nim programming language
You may also check:How to resolve the algorithm Median filter step by step in the Java programming language