FizzBuzz/Assembly: Difference between revisions

m
Fixed syntax highlighting and duplicate headers.
(moved z80 Assembly)
m (Fixed syntax highlighting and duplicate headers.)
 
(3 intermediate revisions by one other user not shown)
Line 1:
{{collection|FizzBuzz}}
 
=={{header|=360 Assembly}}===
<syntaxhighlight lang="asm">FIZZBUZZ CSECT A SECTION OF CODE STARTS HERE, LABEL IT FIZZBUZZ
**********HOUSE KEEPING AREA**********************
USING *,12 FOR THIS PROGRAM WE ARE GOING TO USE REGISTER 12
Line 87:
**********HOUSE KEEPING AREA**********************
SAVE DS 18F
END HELLO </langsyntaxhighlight>
 
 
=={{header|=6502 Assembly}}===
The modulus operation is rather expensive on the 6502,
so a simple counter solution was chosen.
<syntaxhighlight lang="asm"> .lf fzbz6502.lst
.cr 6502
.tf fzbz6502.obj,ap1
Line 171:
Buzz .da #0
;------------------------------------------------------
.en </langsyntaxhighlight>
 
=={{header|=68000 Assembly}}===
This implementation uses two counters instead of divisions for the moduli.
<langsyntaxhighlight lang="68000devpac">;
; FizzBuzz for Motorola 68000 under AmigaOs 2+ by Thorham
;
Line 271:
 
buzz
dc.b "Buzz",0</langsyntaxhighlight>
 
=={{header|8086=8080 Assembly}}===
 
<syntaxhighlight lang="asm">;; CP/M FizzBuzz in 8080 assembly
 
bdos: equ 5 ; CP/M calls
puts: equ 9
 
max: equ 100 ; Amount of lines to print
 
org 100h
mvi d,max
lxi b,0305h ; Fizz and buzz counters
line: lxi h,num + 2 ; Increment the ASCII number
incn: inr m
mov a,m
cpi '9' + 1
jnz print
mvi m,'0'
dcx h
jmp incn
 
print: mvi e,0 ; Mark that we haven't output anything
dcr b ; Time for fizz?
cz fizzo
dcr c ; Time for buzz?
cz buzzo
dcr e ; Output number if nothing else has been printed
jz check
lxi h,num
call outs
check: lxi h,nl ; Output a newline
call outs
dcr d ; More lines?
jnz line
ret
;; "Fizz", and reset the fizz counter
fizzo: lxi h,fizz
mvi b,3
inr e
jmp outs
;; "Buzz", and reset the buzz counter
buzzo: lxi h,buzz
mvi c,5
mvi e,1
;; Output string in HL preserving registers
outs: push b
push d
push h
mvi c,puts
xchg
call bdos
pop h
pop d
pop b
ret
 
;; Strings
fizz: db 'Fizz$'
buzz: db 'Buzz$'
num: db '000$'
nl: db 13, 10, '$'</syntaxhighlight>
 
 
===8086 Assembly===
Assembly programs that output a number on the screen are programmable in two ways: calculating the number in binary to convert it next in ASCII for output,
or keeping the number in Binary Coded Decimal (BCD) notation
Line 304 ⟶ 371:
is a multiple of five, so the number is never displayed,
because it is replaced by the string "buzz".
<langsyntaxhighlight lang="asm"> ; Init the registers
mov dx,03030h ; For easier printing, the number is
;kept in Binary Coded Decimal, in
Line 391 ⟶ 458:
 
buzz: ;The "buzz" string.
db "buzz"</langsyntaxhighlight>
 
=={{header|=Z80 Assembly}}===
For the Amstrad CPC (should work with e.g. the built-in assembler in JavaCPC; use <tt>call &4000</tt> to start from BASIC):
<langsyntaxhighlight lang="z80">org &4000 ; put code at memory address 0x4000
wr_char equ &bb5a ; write ASCII character in register A to screen
cursor equ &bb78 ; get cursor position
Line 513 ⟶ 580:
 
buzz:
db "Buzz"</langsyntaxhighlight>
9,476

edits