FizzBuzz/Assembly: Difference between revisions

m
Fixed syntax highlighting and duplicate headers.
(Add ARM Assembly)
m (Fixed syntax highlighting and duplicate headers.)
 
(One intermediate revision 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|=8080 Assembly}}===
 
<syntaxhighlight lang="asm">;; CP/M FizzBuzz in 8080 assembly
 
bdos: equ 5 ; CP/M calls
Line 337:
buzz: db 'Buzz$'
num: db '000$'
nl: db 13, 10, '$'</langsyntaxhighlight>
 
 
=={{header|=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 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 458:
 
buzz: ;The "buzz" string.
db "buzz"</langsyntaxhighlight>
 
=={{header|ARM=Z80 Assembly}}===
This program runs under Linux. To make it run on another system, you would have to rewrite the <code>print</code> routine.
 
<lang>.text
.global _start
_start: mov r8,#100 @ 100 loops
mov r9,#3 @ "Fizz" counter
mov r10,#5 @ "Buzz" counter
mov r11,#'0 @ Decimal representation
mov r12,#'1
1: mov r6,#0 @ R6 will be set if Fizz or Buzz output
subs r9,r9,#1 @ Decrement Fizz counter
moveq r9,#3 @ If zero, reset to 3
moveq r6,#1 @ and set R6
ldreq r1,=fizz @ and print "Fizz"
bleq print
subs r10,r10,#1 @ Decrement Buzz counter
moveq r10,#5 @ If zero, reset to 5
moveq r6,#1 @ and set R6
ldreq r1,=buzz @ and print "Buzz"
bleq print
tst r6,r6 @ If R6 set, don't print number
bne 2f
ldr r1,=num
strb r12,[r1,#-1]! @ Store first digit in string
cmp r11,#'0 @ If the first digit is > 0...
strhib r11,[r1,#-1]! @ ...then store the first one too
bl print
2: ldr r1,=nl @ Finally, print a newline
bl print
add r12,r12,#1 @ Increment the low digit
cmp r12,#'9 @ If that puts it higher than 9...
movhi r12,#'0 @ Then reset it to 0,
addhi r11,r11,#1 @ And increment the high digit instead
subs r8,r8,#1 @ Decrement loop counter
bne 1b @ If not done yet, do next number
mov r0,#0 @ Otherwise, exit to Linux
mov r7,#1
swi #0
print: mov r2,r1 @ Print zero-terminated string on Linux
1: ldrb r0,[r2],#1 @ Get byte and advance R2
tst r0,r0 @ Zero yet?
bne 1b @ If not, keep going
sub r2,r2,r1 @ Calculate length
mov r0,#1 @ STDOUT
mov r7,#4 @ write
push {lr} @ Save the link register first
swi #0
pop {pc}
.data
.align 4
.ascii "**"
num: .asciz ""
fizz: .asciz "Fizz"
buzz: .asciz "Buzz"
nl: .asciz "\n"</lang>
 
=={{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 644 ⟶ 580:
 
buzz:
db "Buzz"</langsyntaxhighlight>
9,476

edits