#The TOY Assembly Language
The TOY language is an experimental ( educational ) assembly language target for TOY achitecture, and is a part of our final project C14-Assembler. Primary contributors to this project include: Andy , Tony and Borris.
##Directive
.DATA.TEXT
Case-insensitive
##Data
- All variables must be declared within
.DATA - Declaration must abide to the following form:
< variable name > < size > < value > where
- < variable name > := An alphanumeric symbol with length no more than 10. It should not start with number.
_is allowed. For example:my_varis ok, while0_0_My_Varis strictly forbidden. - < size > :=
BYTEorWORDorDWORD - < value > := Any integer within the range of 0 to 4294967295 , i.e. 32 bits, unsigned integer, binary number unsupported. Prefix with
0xif the value is encoded hexadecimally. If you want to declare uninitialized value, set value to?. You can also declare array byArray WORD DUP(10), which reserves 10 words forArray.
####Legal declaration
.DATA
myVar WORD 32766
foo BYTE -10
myArray WORD DUP(10)
bar DWORD ?
##Complete Instruction Specification
####Terminology
<reg>:=R<i>whereiin range 1 to F.Rcase-sensitive. For example:R1,RAare valid register namerrebyr1,R17are invalid.<con>:= Any 16-bit integer.<var>:= Any variable declared in.data<mem>:=[<reg>][<var>]or[<con>]. For example:[R1],[myVariable],[0xF8]are valid, but[ R1 ]is invalid.<instr>:= Instruction.<dest>:= Destination operand.<src>:= Source operand.
####Rule
- Ternary instructions:
<instr> <dest> <src1> <src2>. For example:add R2 R1 R1. - Binary instructions:
<instr> <dest> <src>. For example:ld R1 0xF1.
####Instruction
The table is transcribed from CYY as seen here
| Name | Opcode | Mnemonic | Format | Pseudocode |
|---|---|---|---|---|
| Halt | 0 | hlt | hlt | Exit |
| Add | 1 | add | add <reg>, <reg>, <reg> |
R[d] = R[s] + R[t] |
| Sub | 2 | sub | sub <reg>, <reg>, <reg> |
R[d] = R[s] - R[t] |
| And | 3 | and | and <reg>, <reg>, <reg> |
R[d] = R[s] & R[t] |
| Xor | 4 | xor | xor <reg>, <reg>, <reg> |
R[d] = R[s] ^ R[t] |
| Shift left | 5 | shl | shl <reg>, <reg>, <reg> |
R[d] = R[s] << R[t] |
| Shift right | 6 | shr | shr <reg>, <reg>, <reg> |
R[d] = R[s] >> R[t] |
| Load address | 7 | lda | lda <reg>, <con> |
R[d] = addr or constant |
| Load | 8 | ld | ld <reg>, <mem> |
R[d] = mem[addr] |
| Store | 9 | st | st <mem>, <reg> |
mem[addr] = R[d] |
| Load indirect | A | ldi | ldi <reg>, [<reg>] |
R[d] = mem[ R[t] ] |
| Store indirect | B | sti | sti [<reg>], <reg> |
mem[ R[t] ] = R[d] |
| Branch zero | C | bz | bz <reg>, <con> |
if( R[d] == 0 ) pc = addr |
| Branch positive | D | bp | bp <reg>, <con> |
if(R[d] > 0 ) pc = addr |
| Jump register | E | jr | jr <reg>, (<reg>) |
pc = R[t] |
| Jump and link | F | jl | jl <reg>, <con> |
R[d] = pc , pc = addr |
<reg> |
||||
<reg> |
||||
| All instructions are case-insensitive |
##Constant
Behave like the preprocessed #define in C.
myConstant EQU 100##Symbol / label
- Update: Label can share line with instruction.
- Symbol can be referenced even before it's declared.
- Symbol contains only alphanumeric characters and
_and must not conflict with register name. - Symbol name must not start with digits.
- A symbol must contains no more than 20 characters.
####Invalid symbol name
R8 ; conflicts with register name
myLongLongLongLongLongSymbol ; too long
2BeOrNot2Be ; starts with digit##Comment
Anything prefixed by ; is regarded as comment and will not parsed by the assembler.