Formatted numeric output: Difference between revisions

Content added Content deleted
m (Updated description and link for Fōrmulæ solution)
Line 18: Line 18:
00007.125
00007.125
</pre>
</pre>

=={{header|8086 Assembly}}==
The <code>PrintString</code> and <code>PrintChar</code> routines was omitted to keep this short. They handle the printing of null-terminated strings.
<lang asm> model small
stack 1024
.data
;data segment is unused in this program
.code
start:

mov ax,@code
mov ds,ax
mov es,ax
cld ;make lodsb, etc. auto-increment
mov al, byte ptr [ds:LeadingZeroes]
mov cl,al
mov ch,0
mov al,'0' ;30h
jcxz DonePrintingLeadingZeroes ;there are leading zeroes so we won't skip that section. This branch is not taken.
printLeadingZeroes:
call PrintChar ;print ascii 0 to the terminal 4 times
loop printLeadingZeroes
DonePrintingLeadingZeroes:
mov si, offset TestString
call PrintString

mov al, byte ptr [ds:TrailingZeroes]
mov cl,al
mov ch,0
mov al,'0' ;30h
jcxz DonePrintingTrailingZeroes ;there are none in this example so this branch is always taken
printTrailingZeroes:
call PrintChar
loop printTrailingZeroes
DonePrintingTrailingZeroes:
mov ax,4C00h
int 21h ;exit to DOS
TestString byte "7.125",0

LeadingZeroes byte 4 ;number of leading zeroes to print
TrailingZeroes byte 0 ;number of trailing zeroes to print</lang>


=={{header|8th}}==
=={{header|8th}}==