CreativeASM/Examples

From Esolang
Jump to navigation Jump to search

Back to CreativeASM

Here is a catalog of examples for CreativeASM! Now added with FizzBuzz and Never Gonna Give You Up...

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 

Never Gonna Give You Up

@ Welcome text
put ecx "Welcome to Never Gonna Give You Up!"
int ecx 01h
put ecx "Written in pure CreativeASM - by Mihai Popa!"
int ecx 01h
@ Variables
put ebx 1
put rdx 0
put rcx 0
@ Lyrics for Never Gonna Give You Up
put rax "We're no strangers to love"
int rax 01h
put rax "You know the rules and so do I (do I)"
int rax 01h
put rax "A full commitment's what I'm thinking of"
int rax 01h
put rax "You wouldn't get this from any other guy"
int rax 01h
bl
@ Second part
put rax "I just wanna tell you how I'm feeling"
int rax 01h
put rax "Gotta make you understand"
int rax 01h
bl
@ Third part
put rax "Never gonna give you up"
int rax 01h
put rax "Never gonna let you down"
int rax 01h
put rax "Never gonna run around and desert you"
int rax 01h
put rax "Never gonna make you cry"
int rax 01h
put rax "Never gonna say goodbye"
int rax 01h
put rax "Never gonna tell a lie and hurt you"
int rax 01h
bl
@ Fourth part
put rax "We've known each other for so long"
int rax 01h
put rax "Your heart's been aching, but you're too shy to say it (say it)"
int rax 01h
put rax "Inside, we both know what's been going on (going on)"
int rax 01h
put rax "We know the game and we're gonna play it"
int rax 01h
bl
@ Fifth part
put rax "And if you ask me how I'm feeling"
int rax 01h
put rax "Don't tell me you're too blind to see"
int rax 01h
bl
@ Sixth part
lbl never
put rax "Never gonna give you up"
int rax 01h
put rax "Never gonna let you down"
int rax 01h
put rax "Never gonna run around and desert you"
int rax 01h
put rax "Never gonna make you cry"
int rax 01h
put rax "Never gonna say goodbye"
int rax 01h
put rax "Never gonna tell a lie and hurt you"
int rax 01h
bl
add rdx ebx rdx
beqrdx 1 never
beqrdx 2 rest
@ Seventh part
lbl rest
put rax "We've known each other for so long"
int rax 01h
put rax "Your heart's been aching, but you're too shy to say it (say it)"
int rax 01h
put rax "Inside, we both know what's been going on (going on)"
int rax 01h
put rax "We know the game and we're gonna play it"
int rax 01h
@ Eighth part
bl
put rax "I just wanna tell you how I'm feeling"
int rax 01h
put rax "Gotta make you understand"
int rax 01h
bl
jmp never2
@ End
lbl never2
put rax "Never gonna give you up"
int rax 01h
put rax "Never gonna let you down"
int rax 01h
put rax "Never gonna run around and desert you"
int rax 01h
put rax "Never gonna make you cry"
int rax 01h
put rax "Never gonna say goodbye"
int rax 01h
put rax "Never gonna tell a lie and hurt you"
int rax 01h
bl
add rcx ebx rcx
beqrcx 1 never2
beqrcx 2 never2
beqrcx 3 exit
lbl exit
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 Welcome text    
set ecx="Welcome to Never Gonna Give You Up!" 
echo %ecx% 
set ecx="Written in pure CreativeASM - by Mihai Popa!" 
echo %ecx% 
REM Variables     
set ebx=1    
set rdx=0    
set rcx=0    
REM Lyrics for Never Gonna Give You Up 
set rax="We're no strangers to love" 
echo %rax% 
set rax="You know the rules and so do I (do I)" 
echo %rax% 
set rax="A full commitment's what I'm thinking of" 
echo %rax% 
set rax="You wouldn't get this from any other guy" 
echo %rax% 
echo. 
REM Second part    
set rax="I just wanna tell you how I'm feeling" 
echo %rax% 
set rax="Gotta make you understand" 
echo %rax% 
echo. 
REM Third part    
set rax="Never gonna give you up" 
echo %rax% 
set rax="Never gonna let you down" 
echo %rax% 
set rax="Never gonna run around and desert you" 
echo %rax% 
set rax="Never gonna make you cry" 
echo %rax% 
set rax="Never gonna say goodbye" 
echo %rax% 
set rax="Never gonna tell a lie and hurt you" 
echo %rax% 
echo. 
REM Fourth part    
set rax="We've known each other for so long" 
echo %rax% 
set rax="Your heart's been aching, but you're too shy to say it (say it)" 
echo %rax% 
set rax="Inside, we both know what's been going on (going on)" 
echo %rax% 
set rax="We know the game and we're gonna play it" 
echo %rax% 
echo. 
REM Fifth part    
set rax="And if you ask me how I'm feeling" 
echo %rax% 
set rax="Don't tell me you're too blind to see" 
echo %rax% 
echo. 
REM Sixth part    
:never 
set rax="Never gonna give you up" 
echo %rax% 
set rax="Never gonna let you down" 
echo %rax% 
set rax="Never gonna run around and desert you" 
echo %rax% 
set rax="Never gonna make you cry" 
echo %rax% 
set rax="Never gonna say goodbye" 
echo %rax% 
set rax="Never gonna tell a lie and hurt you" 
echo %rax% 
echo. 
set /a rdx=%rdx%+%ebx% 
if %rdx% EQU 1 goto never 
if %rdx% EQU 2 goto rest 
REM Seventh part    
:rest 
set rax="We've known each other for so long" 
echo %rax% 
set rax="Your heart's been aching, but you're too shy to say it (say it)" 
echo %rax% 
set rax="Inside, we both know what's been going on (going on)" 
echo %rax% 
set rax="We know the game and we're gonna play it" 
echo %rax% 
REM Eighth part    
echo. 
set rax="I just wanna tell you how I'm feeling" 
echo %rax% 
set rax="Gotta make you understand" 
echo %rax% 
echo. 
goto never2 
REM End     
:never2 
set rax="Never gonna give you up" 
echo %rax% 
set rax="Never gonna let you down" 
echo %rax% 
set rax="Never gonna run around and desert you" 
echo %rax% 
set rax="Never gonna make you cry" 
echo %rax% 
set rax="Never gonna say goodbye" 
echo %rax% 
set rax="Never gonna tell a lie and hurt you" 
echo %rax% 
echo. 
set /a rcx=%rcx%+%ebx% 
if %rcx% EQU 1 goto never2 
if %rcx% EQU 2 goto never2 
if %rcx% EQU 3 goto exit 
:exit 
pause >nul