Odd and square numbers: Difference between revisions

Add 8080 Assembly
(Add MACRO-11)
(Add 8080 Assembly)
Line 19:
121 169 225 289 361 441 529 625 729 841 961
</pre>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="asm"> org 100h
lxi h,81 ; Holds current square
lxi d,19 ; Holds distance to next square
mvi b,12 ; Loop counter
jmp next
loop: call prhl
next: dad d ; Generate next square (will be even)
inx d ; Increase distance by 2
inx d
dad d ; Generate next square (will be odd)
inx d ; Increase distance by 2
inx d
dcr b
jnz loop
ret
; Print HL as decimal
prhl: push h ; Save all registers
push d
push b
lxi b,pnum ; Store pointer to num string on stack
push b
lxi b,-10 ; Divisor
prdgt: lxi d,-1
prdgtl: inx d ; Divide by 10 through trial subtraction
dad b
jc prdgtl
mvi a,'0'+10
add l ; L = remainder - 10
pop h ; Get pointer from stack
dcx h ; Store digit
mov m,a
push h ; Put pointer back on stack
xchg ; Put quotient in HL
mov a,h ; Check if zero
ora l
jnz prdgt ; If not, next digit
pop d ; Get pointer and put in DE
mvi c,9 ; CP/M print string
call 5
pop b ; Restore registers
pop d
pop h
ret
db '*****' ; Placeholder for number
pnum: db 13,10,'$'</syntaxhighlight>
{{out}}
<pre>121
169
225
289
361
441
529
625
729
841
961</pre>
 
=={{header|ALGOL 68}}==
2,093

edits