How to resolve the algorithm Loops/Downward for step by step in the 8080 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/Downward for step by step in the 8080 Assembly programming language

Table of Contents

Problem Statement

Write a   for   loop which writes a countdown from   10   to   0.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/Downward for step by step in the 8080 Assembly programming language

Source code in the 8080 programming language

	;-------------------------------------------------------
	; some useful equates
	;-------------------------------------------------------
bdos	equ	5h	; location ofjump to BDOS entry point
wboot   equ     0       ; BDOS warm boot function
conout  equ     2       ; write character to console
	;-------------------------------------------------------
	; main code
	;-------------------------------------------------------
	org	100h
	lxi	sp,stack  ; set up a stack
	;
	lxi	h,10	; starting value for countdown 
loop:	call	putdec	; print it
	mvi	a,' '	; space between numbers
	call	putchr
	dcx	h	; decrease count by 1 
	mov	a,h	; are we done (HL = 0)?
	ora	l
	jnz	loop	; no, so continue with next number
	jmp	wboot	; otherwise exit to operating system
	;-------------------------------------------------------
	; console output of char in A register
	; preserves BC, DE, HL
	;-------------------------------------------------------
putchr:	push	h
	push	d
	push	b
	mov	e,a
	mvi	c,conout
	call	bdos
	pop	b
	pop	d
	pop	h
	ret
	;---------------------------------------------------------
	; Decimal output to console routine
	; HL holds 16-bit unsigned binary number to print
	; Preserves BC, DE, HL
	;---------------------------------------------------------
putdec: push	b
	push	d
	push	h
	lxi	b,-10
	lxi	d,-1
putdec2:
	dad	b
	inx	d
	jc	putdec2
	lxi	b,10
	dad	b
	xchg
	mov	a,h
	ora	l
	cnz	putdec		; recursive call!
	mov	a,e
	adi	'0'		; make printable
	call	putchr
	pop	h
	pop	d
	pop	b
	ret
	;----------------------------------------------------------
	;  data area
	;----------------------------------------------------------
stack	equ	$+128	; 64-level stack to support recursion
	;
	end


  

You may also check:How to resolve the algorithm Eban numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the C++ programming language
You may also check:How to resolve the algorithm Filter step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Ada programming language
You may also check:How to resolve the algorithm Array length step by step in the Idris programming language