i all the A langs

This commit is contained in:
Ingy döt Net 2013-04-10 14:16:51 -07:00
parent 86c034bb8b
commit 9246b988c7
245 changed files with 3941 additions and 0 deletions

View file

@ -0,0 +1,79 @@
.lf fzbz6502.lst
.cr 6502
.tf fzbz6502.obj,ap1
;------------------------------------------------------
; FizzBuzz for the 6502 by barrym95838 2013.04.04
; Thanks to sbprojects.com for a very nice assembler!
; The target for this assembly is an Apple II with
; mixed-case output capabilities and Applesoft
; BASIC in ROM (or language card)
; Tested and verified on AppleWin 1.20.0.0
;------------------------------------------------------
; Constant Section
;
FizzCt = 3 Fizz Counter (must be < 255)
BuzzCt = 5 Buzz Counter (must be < 255)
Lower = 1 Loop start value (must be 1)
Upper = 100 Loop end value (must be < 255)
CharOut = $fded Specific to the Apple II
IntOut = $ed24 Specific to ROM Applesoft
;======================================================
.or $0f00
;------------------------------------------------------
; The main program
;
main ldx #Lower init LoopCt
lda #FizzCt
sta Fizz init FizzCt
lda #BuzzCt
sta Buzz init BuzzCt
next ldy #0 reset string pointer (y)
dec Fizz LoopCt mod FizzCt == 0?
bne noFizz yes:
lda #FizzCt
sta Fizz restore FizzCt
ldy #sFizz-str point y to "Fizz"
jsr puts output "Fizz"
noFizz dec Buzz LoopCt mod BuzzCt == 0?
bne noBuzz yes:
lda #BuzzCt
sta Buzz restore BuzzCt
ldy #sBuzz-str point y to "Buzz"
jsr puts output "Buzz"
noBuzz dey any output yet this cycle?
bpl noInt no:
txa save LoopCt
pha
lda #0 set up regs for IntOut
jsr IntOut output itoa(LoopCt)
pla
tax restore LoopCt
noInt ldy #sNL-str
jsr puts output "\n"
inx increment LoopCt
cpx #Upper+1 LoopCt >= Upper+1?
bcc next no: loop back
rts yes: end main
;------------------------------------------------------
; Output zero-terminated string @ (str+y)
; (Entry point is puts, not outch)
;
outch jsr CharOut output string char
iny advance string ptr
puts lda str,y get a string char
bne outch output and loop if non-zero
rts return
;------------------------------------------------------
; String literals (in '+128' ascii, Apple II style)
;
str: ; string base offset
sFizz .az -"Fizz"
sBuzz .az -"Buzz"
sNL .az -#13
;------------------------------------------------------
; Variable Section
;
Fizz .da #0
Buzz .da #0
;------------------------------------------------------
.en

View file

@ -0,0 +1,88 @@
; Init the registers
mov dx,03030h ; For easier printing, the number is
;kept in Binary Coded Decimal, in
----
;the DX register.
mov ah,0Eh ; 0Eh is the IBM PC interrupt 10h
;function that does write text on
;the screen in teletype mode.
mov bl,100d ; BL is the counter (100 numbers).
xor cx,cx ; CX is a counter that will be used
;for screen printing.
xor bh,bh ; BH is the counter for counting
;multiples of three.
writeloop: ; Increment the BCD number in DX.
inc dl ; Increment the low digit
cmp dl,3Ah ; If it does not overflow nine,
jnz writeloop1 ;continue with the program,
mov dl,30h ;otherwise reset it to zero and
inc dh ;increment the high digit
writeloop1:
inc bh ; Increment the BH counter.
cmp bh,03h ; If it reached three, we did
;increment the number three times
;from the last time the number was
;a multiple of three, so the number
;is now a multiple of three now,
jz writefizz ;then we need to write "fizz" on the
;screen.
cmp dl,30h ; The number isn't a multiple of
jz writebuzz ;three, so we check if it's a
cmp dl,35h ;multiple of five. If it is, we
jz writebuzz ;need to write "buzz". The program
;checks if the last digit is zero or
;five.
mov al,dh ; If we're here, there's no need to
int 10h ;write neither "fizz" nor "buzz", so
mov al,dl ;the program writes the BCD number
int 10h ;in DX
writespace:
mov al,020h ;and a white space.
int 10h
dec bl ; Loop if we didn't process 100
jnz writeloop ;numbers.
programend: ; When we did reach 100 numbers,
cli ;the program flow falls here, where
hlt ;interrupts are cleared and the
jmp programend ;program is stopped.
writefizz: ; There's need to write "fizz":
mov si,offset fizz ; SI points to the "fizz" string,
call write ;that is written on the screen.
xor bh,bh ; BH, the counter for computing the
;multiples of three, is cleared.
cmp dl,30h ; We did write "fizz", but, if the
jz writebuzz ;number is a multiple of five, we
cmp dl,35h ;could need to write "buzz" also:
jnz writespace ;check if the number is multiple of
;five. If not, write a space and
;return to the main loop.
writebuzz: ; (The above code falls here if
;the last digit is five, otherwise
;it jumps)
mov si,offset buzz ;SI points to the "buzz" string,
call write ;that is written on the screen.
jmp writespace ; Write a space to return to the main
;loop.
write: ; Write subroutine:
mov cl,04h ; Set CX to the lenght of the string:
;both strings are 4 bytes long.
write1:
mov al,[si] ; Load the character to write in AL.
inc si ; Increment the counter SI.
int 10h ; Call interrupt 10h, function 0Eh to
;write the character and advance the
;text cursor (teletype mode)
loop write1 ; Decrement CX: if CX is not zero, do
ret ;loop, otherwise return from
;subroutine.
fizz: ;The "fizz" string.
db "fizz"
buzz: ;The "buzz" string.
db "buzz"

View file

@ -0,0 +1,15 @@
main:(
FOR i TO 100 DO
printf(($gl$,
IF i %* 15 = 0 THEN
"FizzBuzz"
ELIF i %* 3 = 0 THEN
"Fizz"
ELIF i %* 5 = 0 THEN
"Buzz"
ELSE
i
FI
))
OD
)

View file

@ -0,0 +1 @@
FOR i TO 100 DO print(((i%*15=0|"FizzBuzz"|:i%*3=0|"Fizz"|:i%*5=0|"Buzz"|i),new line)) OD

View file

@ -0,0 +1,2 @@
⎕IO0
(L,'Fizz' 'Buzz' 'FizzBuzz')[¯1+(L×W=0)+W(100×~0=W)+W+/1 2×0=3 5|L1+100]

View file

@ -0,0 +1,14 @@
property outputText: ""
repeat with i from 1 to 100
if i mod 15 = 0 then
set outputText to outputText & "FizzBuzz"
else if i mod 3 = 0 then
set outputText to outputText & "Fizz"
else if i mod 5 = 0 then
set outputText to outputText & "Buzz"
else
set outputText to outputText & i
end if
set outputText to outputText & linefeed
end repeat
outputText

View file

@ -0,0 +1,15 @@
fizzbuzz():
for x in [1..100]
if x%5==0 and x%3==0
return "FizzBuzz"
else
if x%3==0
return "Fizz"
else
if x%5==0
return "Buzz"
else
return x
main():
fizzbuzz() -> io

View file

@ -0,0 +1,14 @@
Loop, 100
{
If (Mod(A_Index, 15) = 0)
output .= "FizzBuzz`n"
Else If (Mod(A_Index, 3) = 0)
output .= "Fizz`n"
Else If (Mod(A_Index, 5) = 0)
output .= "Buzz`n"
Else
output .= A_Index "`n"
}
FileDelete, output.txt
FileAppend, %output%, output.txt
Run, cmd /k type output.txt

View file

@ -0,0 +1,7 @@
Gui, Add, Edit, r20
Gui,Show
Loop, 100
Send, % (!Mod(A_Index, 15) ? "FizzBuzz" : !Mod(A_Index, 3) ? "Fizz" : !Mod(A_Index, 5) ? "Buzz" : A_Index) "`n"
Return
Esc::
ExitApp

View file

@ -0,0 +1,11 @@
For $i = 1 To 100
If Mod($i, 15) = 0 Then
MsgBox(0, "FizzBuzz", "FizzBuzz")
ElseIf Mod($i, 5) = 0 Then
MsgBox(0, "FizzBuzz", "Buzz")
ElseIf Mod($i, 3) = 0 Then
MsgBox(0, "FizzBuzz", "Fizz")
Else
MsgBox(0, "FizzBuzz", $i)
EndIf
Next