Skip to content

vorotynsky/Kroha

Repository files navigation

Kroha

Improve your assembly experience with Kroha! This language is more comfortable than a pure assembly.

Examples

Instead of documentation

You can find more examples here.

Frames

program {
  manual frame act {
    mov ax, [bp-4]
    inc ax
    leave
    ret
  }

  frame main {
    reg a : ax
    a = 5
    call <act> (a)
  }
}

Compiled

section .text
act:
  mov ax, [bp-4]
  inc ax
  leave
  ret

section .text
main:
enter 0, 0
  mov ax, 5
  push ax
  call act
  add sp, 2
leave
ret

Variables

program {
  var a : int16 = 32
  var b : int8 = 1
  const c : int16 = 32
  const d : int8 = 1

  manual var arr : &int8 {
    times 64 db 0
  }

  frame main {
    reg ra : ax
    reg rb : bl
    var sb : int16
    ra = 5
    sb = 6
    rb = b
  }
}

Compiled

section .data
a: dw 32

section .data
b: db 1

section .rodata
c: dw 32

section .rodata
d: db 1

section .data
arr:
  times 64 db 0
    

section .text
main:
enter 2, 0
  mov ax, 5
  mov word [bp - 2], 6
  mov bl, [b]
leave
ret

Conditions and loops

program {
  frame main {
    reg val : ax
    val = 0

    loop (LOOP) {
      if (val > 5, CMP) {
        break (LOOP)
      }
      else {
        !dec bx
      }
      !inc ax
    }
  }
}

Compiled

section .text
main:
enter 0, 0
  mov ax, 0
  LOOP_begin:
    cmp ax, 5
    jg CMP_begin
      dec bx
    jmp CMP_end
    CMP_begin:
      jmp LOOP_end
    CMP_end:
    inc ax
  jmp LOOP_begin
  LOOP_end:
leave
ret

Check more examples.

Build and install

Build using stack.

stack build

Install using stack.

stack install

Run Kroha

It compiles each file individually and prints nasm to the terminal.

Kroha ./file1 ./file2 ./file3