Wiki
Clone wikicyy / CYYSAM
Assembler for the CYY VM
The assembler for the CYY-VM ist called cyysam.
Each source file consists up to three sections:
.DATA
Contains all definitions of constant values.
.BSS
Contains all definitions of variables.
.TEXT
Contains the program code
Here is a table with all supported instructions.
Example
Example of an recursive implementation of the factorial function n!.
#!asm ; ; demo programm for CYY assembler cyysam ; calculate 5! = 5*4*3*2*1 = 120 ; ; ------------------------------------------------------------------- ; ; declare initialized data and constants ; ; ------------------------------------------------------------------- section .data start.value 5u64 null.value 0idx one.value 1u64 ; ------------------------------------------------------------------- ; ; declare global variables ; ; ------------------------------------------------------------------- section .bss ; ; ; tmp 1u64 ; ------------------------------------------------------------------- ; ; keep the code here ; ; ------------------------------------------------------------------- section .text ; program start MAIN: ; ; set debug mode ON ; dbgon ; push start value on the stack pdata start.value ; call calculation call FACTORIAL ; ; dump result ; pbss tmp dump pop ; exit ja STOP ; ; function: FACTORIAL() ; FACTORIAL: ; set up base register esba ; push variable on the stack ; this is the position relativ to base pointer that address the start value (a local variable) pdata null.value pr ; push 1 ; this is the termination condition (if local value equals 1 then start calculation and return) pdata one.value ; compare values and set jump register cmp pop ; local variable equals 1 ; start calculation and return je CALCULATE ; push 1 pdata one.value ; load local variable (again) pdata null.value pr ; sub (local value - 1) sub ; recursion call FACTORIAL ; ; return from recursion ; pop CALCULATE: ; load variable "tmp" and local value on the stack, ; multiply and store value back ; PSH &tmp pbss tmp ; load local value pdata null.value pr mul ; pop ; STVA &tmp store tmp ; prepare to return reba ret ; ; program stop STOP: ; ; set debug mode ON ; ; dbgoff halt
Example to run this program on a linux system:
#!shell build/cyysam --verbose -r tools/asmblr/examples/factorial.cysam
Updated