• Post author:
  • Reading time:2 mins read
  • Post category:Announcements

Assembly language, often abbreviated ASM, is a low-level programming language. We know the processor takes care of the arithmetic, control and logical operations of a system. But it understands only machine language instructions, which are strings of 1’s and 0’s. So we require an interface between the High level Languages ( C, C++) and the Machine code. Thus came the Assembly language. Its not easier like a C program but also not obscure like the machine code.

Why ASM Programs?

  • It requires less memory and execution time.
  • It allows hardware-specific complex jobs in an easier way.

Where are they mainly used?

  • It is most suitable for writing interrupt service routines and other memory resident programs.
  • It is suitable for time-critical jobs;

Assembly language instructions are architecture specific.

RISC-V architecture which is used in SHAKTI has less than 200 instructions. RISC-V Green Card consists of the entire assembly instructions of RISC-V. ASM programs are used with extension .S

Some of these instructions might be quite tricky. That is why we have the SHAKTI ASM Manual. It has an elaborate account of all the instructions with thorough examples.

This Manual includes,

  • General purpose registers in RISC-V
  • CSR Registers in RISC-V
  • Load and store instructions
  • Arithmetic instructions
  • Bit wise instructions
  • Control transfer instructions
  • Traps
  • Interrupts
  • Assembly directives

It also contains many complicated examples.

For instance, this is an ASM program to determine whether the given number in a array is odd or even. Save this program as even-odd.S

_start:
.data
Array: .byte 12,19,45,69,98,23
.text
  andi t0, t0, 0
  andi t1, t1, 0
  andi t2, t2, 0
  andi t3, t3, 0
  andi t4, t4, 0
  andi t5, t5, 0
  li t4, 6
  li t5, 2
FOR_loop: bge t3, t4, END
          la t2, Array
          add t2, t2, t3
          lb t2, 0(t2)
          rem t2, t2, t5
IF: bnez t2, ELSE
    addi t0, t0, 1
    addi t3, t3, 1
    j FOR_loop
ELSE:
    addi t1, t1, 1
    addi t3, t3, 1
j FOR_loop
END: j END

Compiling this program,

riscv64-unknown-elf-gcc -nostdlib -nostartfiles -T spike.lds even-odd.S -o even-odd.elf

Learn how to understand this program and also debug this using objdump with GDB.

Try reading How to debug an ASM Program with GDB using objdump?

It has a simple if-else program for starters.

Shakti ASM Manual

Leave a Reply