CreativeASM/Examples
Jump to navigation
Jump to search
Here is a catalog of examples for CreativeASM! Now added with FizzBuzz...
Examples
Hello, world!
@ Hello, world! example, in CreativeASM put rax "Hello, world!" @ We need to put that message in the "rax" register and command to output content from rax. int rax 01h
Assembled to Batch
@echo off set ra= set rb= set rc= set rd= REM Another set set rax= set rbx= set rcx= set rdx= REM Special ones set r= set s= set t= set u= REM x86 assembly ones set eax= set ebx= set ecx= set edx= REM Hello, world! example, in CreativeASM set rax="Hello, world!" REM We need to put that message in the "rax" register and command to output content from rax. echo %rax%
A calculator
@ A calculator program in CreativeASM lbl main @ Lines of text to be printed clr put rax "Welcome to CreativeCalc, version 1" int rax 01h put rax "What to do?" int rax 01h put rax "1. Add" int rax 01h put rax "2. Subtract" int rax 01h put rax "3. Multiply" int rax 01h put rax "4. Divide" int rax 01h @ Input int rbx 00h @ Jumping beqrbx 1 add beqrbx 2 subtract beqrbx 3 multiply beqrbx 4 divide @ Label for Add lbl add clr int ra 00h int rb 00h add ra rb rc put rd "The result is:" int rd 01h int rc 01h slp jmp main @ Label for Subtract lbl subtract clr int ra 00h int rb 00h sub ra rb rc put rd "The result is:" int rd 01h int rc 01h slp jmp main @ Label for Multiply lbl multiply clr int ra 00h int rb 00h mul ra rb rc put rd "The result is:" int rd 01h int rc 01h slp jmp main @ Label for Divide lbl divide clr int ra 00h int rb 00h div ra rb rc put rd "The result is:" int rd 01h int rc 01h slp jmp main
Assembled to Batch
@echo off set ra= set rb= set rc= set rd= REM Another set set rax= set rbx= set rcx= set rdx= REM Special ones set r= set s= set t= set u= REM x86 assembly ones set eax= set ebx= set ecx= set edx= REM A calculator program in CreativeASM :main REM Lines of text to be printed cls set rax="Welcome to CreativeCalc, version 1" echo %rax% set rax="What to do?" echo %rax% set rax="1. Add" echo %rax% set rax="2. Subtract" echo %rax% set rax="3. Multiply" echo %rax% set rax="4. Divide" echo %rax% REM Input set /p rbx=? REM Jumping if %rbx% EQU 1 goto add if %rbx% EQU 2 goto subtract if %rbx% EQU 3 goto multiply if %rbx% EQU 4 goto divide REM Label for Add :add cls set /p ra=? set /p rb=? set /a rc=%ra%+%rb% set rd="The result is:" echo %rd% echo %rc% pause >nul goto main REM Label for Subtract :subtract cls set /p ra=? set /p rb=? set /a rc=%ra%-%rb% set rd="The result is:" echo %rd% echo %rc% pause >nul goto main REM Label for Multiply :multiply cls set /p ra=? set /p rb=? set /a rc=%ra%*%rb% set rd="The result is:" echo %rd% echo %rc% pause >nul goto main REM Label for Divide :divide cls set /p ra=? set /p rb=? set /a rc=%ra%/%rb% set rd="The result is:" echo %rd% echo %rc% pause >nul goto main
Cat program
@ A "cat" program, but in CreativeASM @ Input int eax 00h @ Output int eax 01h slp
Assembled to Batch
@echo off set ra= set rb= set rc= set rd= REM Another set set rax= set rbx= set rcx= set rdx= REM Special ones set r= set s= set t= set u= REM x86 assembly ones set eax= set ebx= set ecx= set edx= REM A "cat" program, but in CreativeASM REM Input set /p eax=? REM Output echo %eax% pause >nul
XKCD Random Number
@ XKCD Random Number, in CreativeASM! @ Output put rax 4 int rax 01h slp
Assembled to Batch
@echo off set ra= set rb= set rc= set rd= REM Another set set rax= set rbx= set rcx= set rdx= REM Special ones set r= set s= set t= set u= REM x86 assembly ones set eax= set ebx= set ecx= set edx= REM XKCD Random Number, in CreativeASM! REM Output set rax=4 echo %rax% pause >nul
Truth machine
@ A truth machine, in CreativeASM @ Input int rax 00h @ Jumping beqrax 0 zero beqrax 1 one @ Zero lbl zero put rax 0 int rax 01h slp hal @ One lbl one put rax 1 int rax 01h jmp one
Assembled to Batch
@echo off set ra= set rb= set rc= set rd= REM Another set set rax= set rbx= set rcx= set rdx= REM Special ones set r= set s= set t= set u= REM x86 assembly ones set eax= set ebx= set ecx= set edx= REM A truth machine, in CreativeASM REM Input set /p rax=? REM Jumping if %rax% EQU 0 goto zero if %rax% EQU 1 goto one REM Zero :zero set rax=0 echo %rax% pause >nul exit REM One :one set rax=1 echo %rax% goto one
A+B Problem
@ A+B Problem in CreativeASM @ Input int rax 00h int rbx 00h @ Math add rax rbx rcx @ Output int rcx 01h
Assembled to Batch
@echo off set ra= set rb= set rc= set rd= REM Another set set rax= set rbx= set rcx= set rdx= REM Special ones set r= set s= set t= set u= REM x86 assembly ones set eax= set ebx= set ecx= set edx= REM A+B Problem in CreativeASM REM Input set /p rax=? set /p rbx=? REM Math set /a rcx=%rax%+%rbx% REM Output echo %rcx%
FizzBuzz
@ FizzBuzz in CreativeASM put eax 1 put rb 1 @ "Fizz", "Buzz" and "FizzBuzz" modulos put rax 3 put rbx 5 put rcx 15 @ Code lbl fizz mod eax rax ebx mod eax rbx ecx mod eax rcx edx beqeax 100 sleep beqedx 0 printfizzbuzz beqecx 0 printbuzz beqebx 0 printfizz jmp printnumber @ Fizz lbl printfizz put ra Fizz int ra 01h add eax rb eax jmp fizz @ Buzz lbl printbuzz put ra Buzz int ra 01h add eax rb eax jmp fizz @ FizzBuzz lbl printfizzbuzz put ra FizzBuzz int ra 01h add eax rb eax jmp fizz @ Else lbl printnumber int eax 01h add eax rb eax jmp fizz @ Pause lbl sleep slp hal
Assembled to Batch
@echo off set ra= set rb= set rc= set rd= REM Another set set rax= set rbx= set rcx= set rdx= REM Special ones set r= set s= set t= set u= REM x86 assembly ones set eax= set ebx= set ecx= set edx= REM FizzBuzz in CreativeASM set eax=1 set rb=1 REM "Fizz", "Buzz" and "FizzBuzz" modulos set rax=3 set rbx=5 set rcx=15 REM Code :fizz set /a ebx=%eax%%%%rax% set /a ecx=%eax%%%%rbx% set /a edx=%eax%%%%rcx% if %eax% EQU 100 goto sleep if %edx% EQU 0 goto printfizzbuzz if %ecx% EQU 0 goto printbuzz if %ebx% EQU 0 goto printfizz goto printnumber REM Fizz :printfizz set ra=Fizz echo %ra% set /a eax=%eax%+%rb% goto fizz REM Buzz :printbuzz set ra=Buzz echo %ra% set /a eax=%eax%+%rb% goto fizz REM FizzBuzz :printfizzbuzz set ra=FizzBuzz echo %ra% set /a eax=%eax%+%rb% goto fizz REM Else :printnumber echo %eax% set /a eax=%eax%+%rb% goto fizz REM Pause :sleep pause >nul exit