Jump to content

Positive decimal integers with the digit 1 occurring exactly twice: Difference between revisions

Add 8080 Assembly
(Add APL)
(Add 8080 Assembly)
Line 13:
<pre>
11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911 </pre>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="asm"> org 100h
loop: lda tho ; Are we there yet?
cpi '0'
rnz
call incr ; If not, increment
lxi b,0203h ; Need two ones, 3 steps
mvi a,'1'
lxi h,acc
ones: cmp m ; Count the ones
jnz $+4
dcr b
dcr c
inx h
jnz ones
xra a ; If two ones, print
ora b
cz prn
jmp loop
 
incr: lxi h,acc ; Increment accumulator
mvi a,'9'+1
incrl: inr m
cmp m
rnz
mvi m,'0'
inx h
jmp incrl
 
prn: lxi h,acc+4 ; Print accumulator w/o leading zero
mvi a,'0'
skip: dcx h
cmp m
jz skip
prl: push h
mvi c,2 ; CP/M print character
mov e,m
call 5
pop h
dcx h
xra a
cmp m
jnz prl
mvi c,9 ; CP/M print newline
lxi d,nl
jmp 5
 
acc: db '000' ; Accumulator (stored backwards)
tho: db '0' ; Thousands digit (stop if not 0 anymore)
nl: db 13,10,'$' ; Newline</syntaxhighlight>
{{out}}
<pre>11
101
110
112
113
114
115
116
117
118
119
121
131
141
151
161
171
181
191
211
311
411
511
611
711
811
911</pre>
 
=={{header|Action!}}==
2,114

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.