Department numbers: Difference between revisions

Add 8080 assembly
(Add APL)
(Add 8080 assembly)
Line 54:
6 5 1
</pre>
 
=={{header|8080 Assembly}}==
<lang 8080asm> org 100h
lxi h,obuf ; HL = output buffer
mvi b,2 ; B = police
pol: mvi c,1 ; C = sanitation
san: mvi d,1 ; D = fire
fire: mov a,b ; Fire equal to police?
cmp d
jz next ; If so, invalid combination
mov a,c ; Fire equal to sanitation?
cmp d
jz next ; If so, invalid combination
mov a,b ; Total equal to 12?
add c
add d
cpi 12
jnz next ; If not, invalid combination
mov a,b ; Combination is valid, add to output
call num
mov a,c
call num
mov a,d
call num
mvi m,13 ; Add a newline to the output
inx h
mvi m,10
inx h
next: mvi a,7 ; Load 7 to compare to
inr d ; Next fire number
cmp d ; Reached the end?
jnc fire ; If not, next fire number
inr c ; Otherwise, next sanitation number
cmp c ; Reached the end?
jnc san ; If not, next sanitation number
inr b ; Increment police number twice
inr b ; (twice, because it must be even)
cmp b ; Reached the end?
jnc pol ; If not, next police number
mvi m,'$' ; If so, we're done - add CP/M string terminator
mvi c,9 ; Print the output string
lxi d,ohdr
jmp 5
num: adi '0' ; Add number A and space to the output
mov m,a
inx h
mvi m,' '
inx h
ret
ohdr: db 'P S F',13,10
obuf: equ $ ; Output buffer goes after program</lang>
 
{{out}}
 
<pre>P S F
2 3 7
2 4 6
2 6 4
2 7 3
4 1 7
4 2 6
4 3 5
4 5 3
4 6 2
4 7 1
6 1 5
6 2 4
6 4 2
6 5 1
</pre>
 
 
=={{header|Ada}}==
2,114

edits