How to resolve the algorithm Loops/N plus one half step by step in the 8086 Assembly programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/N plus one half step by step in the 8086 Assembly programming language
Table of Contents
Problem Statement
Quite often one needs loops which, in the last iteration, execute only part of the loop body. Demonstrate the best way to do this. Write a loop which writes the comma-separated list using separate output statements for the number and the comma from within the body of the loop.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Loops/N plus one half step by step in the 8086 Assembly programming language
Source code in the 8086 programming language
.model small
.stack 1024
.data ;no data needed
.code
start:
mov ax,0000h
mov cx,0FFFFh ;this value doesn't matter as long as it's greater than decimal 10.
repeatPrinting:
add ax,1 ;it was easier to start at zero and add here than to start at 1 and add after printing.
aaa ;ascii adjust for addition, corrects 0009h+1 from 000Ah to 0100h
call PrintBCD_IgnoreLeadingZeroes
cmp ax,0100h ;does AX = BCD 10?
je exitLoopEarly ;if so, we're done now. Don't finish the loop.
push ax
mov dl,"," ;print a comma
mov ah,02h
int 21h
mov dl,20h ;print a blank space
mov ah,02h
int 21h
pop ax
loop repeatPrinting
exitLoopEarly:
mov ax,4C00h
int 21h ;return to DOS
PrintBCD_IgnoreLeadingZeroes:
push ax
cmp ah,0
jz skipLeadingZero
or ah,30h ;converts a binary-coded-decimal value to an ASCII numeral
push dx
push ax
mov al,ah
mov ah,0Eh
int 10h ;prints AL to screeen
pop ax
pop dx
skipLeadingZero:
or al,30h
push dx
push ax
mov ah,0Eh
int 10h ;prints AL to screen
pop ax
pop dx
pop ax
ret
end start ;EOF
You may also check:How to resolve the algorithm Stack step by step in the Retro programming language
You may also check:How to resolve the algorithm Pascal matrix generation step by step in the Scheme programming language
You may also check:How to resolve the algorithm Empty program step by step in the Go programming language
You may also check:How to resolve the algorithm Leap year step by step in the Picat programming language
You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the BASIC programming language