What is Chiper?
- Chiper is a emulator/virtual machine made by me.
- It's like Chip-8
- It runs bytecode and executes instructions like a CPU ( Central Processing Unit )
- If you are not interested, fine, but its a great tool to learn Assembly and fight the limitations that it comes with! Also its fun :P/>
- Yes
- Yes, its easier to target an Assembly language than Lua, C++, Java, Etc
- You can create whatever you can with it :D/>
Versions
- Version 1 here: pastebin get cR1ZuRX0 chiper
- Original release
- Version 2 here: pastebin get rQC0drnX chiper
- Assembler errors more readable
- Version 3 here: pastebin get aP1SN7gh chiper
- Bug fixes for Assembly Compiler
- Version 4 here: pastebin get 5zS3FUk8 chiper
- Added INTerupts! Check Assembly Tutorial Section!
- Version 5 here: pastebin get BYKVszJj chiper
- Added DB arguments! Check Assembly Tutorial Section!
- Version 6 here: pastebin get 54aZVDpG chiper
- Now you can store data! Check Assembly Tutorial Section!
- Added few helpful thingies!
- Version 7 here: pastebing get gE6AmbRG chiper
- Added bitwise operators! Check Assembly Tutorial Section!
- Added INC and DEC operator! Check Assembly Tutorial Section!
- Yes you can! Don't be angry :P/> : pastebin get QaLQDVgd print.asm
- chiper <ROM> -This will run the ROM
- chiper <ASM file> <OUT file> -This will run the compiler for the ASM file and OUTputs a ROM
Assembly Tutorial
Numbers can be: Hexadecimal ( $FF ) or Numeric ( #255 )Label can be: Strings ( .text db "Test" ), Pointers ( .loop jmp loop ), Numbers: ( .number db $FF )
Strings And Numbers in labels return a pointer in memory!
To create data in memory do:
.name db "String"
or
.name db $FF
You can have arguments in DB's:
.player db $0, $F, $2, …
hlt ; halts the program
ret ; returns from subroutine
call I ; jumps to a memory location at I and waits for RET
call <number/label> ; jumps to a memory location and waits for RET
jmp <number/label> ;jumps to a memory location
ld A, <number> ;loads a number to register A
ld B, <number> ;loads a number to register B
ld (I), A ;stores whatever is in register A
ld A, (I) ; loads from memory location I to register A
ld (I), B ;stores whatever is in register B
ld B, (I) ; loads from memory location I to register B
ld I, <number/label> ;sets register I to number or labeled memory location ( pointer )
ld X, <number/label> ;sets register X to number or labeled memory location ( pointer )
ld X, I ; sets register I to X
ld I, X ; sets register X to I
ld (I), <number> ; stores a value to memory location I
inc A ; increase register A value by one
inc B ; increase register B value by one
inc I ; increase register I value by one
inc X ; increase register X value by one
dec A ; decrease register A value by one
dec B ; decrease register B value by one
dec I ; decrease register I value by one
dec X ; decrease register X value by one
add A, <number> ; adds register A with a number
add A, B ; adds register A with register B
add B, <number> ; adds register B with a number
add B, A ; adds register B with register A
add I, <number> ; adds register I with a number
add I, A ; adds register I with register A
add I, B ; adds register I with register B
add X, <number> ; adds register X with a number
add X, A ; adds register X with register A
add X, B ; adds register X with register B
; there is sub ( subtract ), mul ( multiply ) but you cant subtract or multiply register I
eql A, <number> ; checks if A is equal to a number value, if false skip next instruction
eql B, <number> ; checks if B is equal to a number value, if false skip next instruction
eql A, B ; checks if A is equal to B and if false skip next instruction
meq A, <number> ; checks if A is more or equal to a number value, if false skip next instruction
meq B, <number> ; checks if B is more or equal to a number value, if false skip next instruction
meq A, B ; checks if A is more or equal to B and if false skip next instruction
leq A, <number> ; checks if A is less or equal to a number value, if false skip next instruction
leq B, <number> ; checks if B is less or equal to a number value, if false skip next instruction
leq A, B ; checks if A is less or equal to B and if false skip next instruction
mor A, <number> ; checks if A is more than a number value, if false skip next instruction
mor B, <number> ; checks if B is more than a number value, if false skip next instruction
mor A, B ; checks if A is more than B and if false skip next instruction
les A, <number> ; checks if A is less than a number value, if false skip next instruction
les B, <number> ; checks if B is less than a number value, if false skip next instruction
les A, B ; checks if A is less than B and if false skip next instruction
; bitwise operators <to be included!>
shl A ; shifts register A value by one to the left
shl B ; shifts register B value by one to the left
shr A ; shifts register A value by one to the right
shr B ; shifts register B value by one to the right
or A, <number> ; does bitwise or operation on register A
or B, <number> ; does bitwise or operation on register B
or A, B ; does bitwise or operation on register A with register B
or B, A ; does bitwise or operation on register B with register A
xor A, <number> ; does bitwise xor operation on register A
xor B, <number> ; does bitwise xor operation on register B
xor A, B ; does bitwise xor operation on register A with register B
xor B, A ; does bitwise xor operation on register B with register A
and A, <number> ; does bitwise and operation on register A
and B, <number> ; does bitwise and operation on register B
and A, B ; does bitwise and operation on register A with register B
and B, A ; does bitwise and operation on register B with register A
int A, <number/label> ; INT takes register A as timer, if A value will hit 0, PC will be set to <number/label>
int B, <number/label> ; INT takes register B as timer, if B value will hit 0, PC will be set to <number/label>
int A, I ; INT takes register A as timer, if A value will hit 0, PC will be set to Register I
int B, I ; INT takes register A as timer, if B value will hit 0, PC will be set to Register I
EXAMPLE:
call refreshScreen ; refreshScreen
.loop
; do stuff
jmp loop
.refreshScreen
ld I, $FFF
ld (I), #1 ; refresh it
ld A, $3A ; load immediate value of HEX 3A into register A
int A, refreshScreen ; set interupt to call refreshScreen every 58 ( or hex value of 3A ) CPU cycles
ret ; return from int/call
there are locations in memory that are being updated by the "hardware" or can be updated by the user:
- Key location: $FF9
- Text Color Location: $FFD ( write from $0 to $F )
- Background Color Location: $FFC ( write from $0 to $F )
- Char Location: $FFE ( write from $0 to $FF )
- Update Location: $FFF
- Screen X Pos: $FFA
- Screen Y Pos: $FFB
- Data Transfer Location: $FF8
- No Key: $0
- Up Arrow: $1
- Down Arrow: $2
- Left Arrow: $3
- Right Arrow: $4
- Key Z: $5
- Key X: $6
- Numpad8: $7
- Numpad5: $8
- Numpad4: $9
- Numpad6: $A
- Key ',' comma: $B
- Key '.' dot: $C
- 1 - Updates the Screen
- 2 - Reads current Pixel to its locations: Background Color( $FFC ), Text Color( $FFD ), Char( $FFE )
- 3 - Writes Data Register to Disk
- 4 - Read From Disk to Data Register Location( $FF8 )
Storing Values EXAMPLE
; set X register to Location in the Disk
ld X, $FFF
; write a value to Disk Register
ld I, $FF8
ld (I), $FF
;store it
ld I, $FFF
ld (I), $3
hlt
If you made a cool program, post it here, share with everybody so that we can try it :P/>
I hope you guys will make some awesome stuff, of course, if you're interested ;)/>
~LeDark Lua