What are the Assembler directives available in SHAKTI?

You are currently viewing What are the Assembler directives available in SHAKTI?

Assembly language often abbreviated as ASM programming, consists of two types of statements, executable statements, and Assembler directives. As we saw in the last article, executable statements execute a task whereas the assembler directives facilitate that execution. In this article, we’ll see the different assembler directives available for SHAKTI ASM Programming.

.TEXT

A read-only section containing the actual instructions of the program.

Syntax
.section .text or .text

.DATA

A read-write portion of the object file which contains data for the variables of the program.

Syntax
.section .data or .data

.RODATA

contains read-only data.

Syntax
.section .rodata or .rodata

.SECTION

Section (.SECTION) directive assembles the following code into a section named “name”.

Syntax
.section name

Directives for Definition and Exporting of symbols

.GLOBAL

The .GLOBAL directive to globalize symbols.

Syntax
.global symbol

.LOCAL

The .LOCAL directive limit the visibility of symbols.

Syntax
.local symbol

Assembler Directives for Alignment

.ALIGN

The .ALIGN directive aligns member byte boundaries. Aligns to the power of 2.

Syntax
.align size

.BALIGN

The .BALIGN directive aligns member byte boundaries with padding.

Syntax
.balign size

.P2ALIGN

The .P2ALIGN directive directive aligns member byte boundaries with padding. Alias for .ALIGN directive.

Syntax
.p2align size

Assembler Directives for Emitting Data

ASM DirectiveSyntaxDescription
.BYTE.byte valueIt initializes the specified value to 1 bytes or 8-bit unaligned integers.
.2BYTE.2byte valueinitializes the specified value to 2 bytes or 16-bit unaligned integers.
.4BYTE.4byte valueIt initializes the specified value to 4 bytes or 32-bit unaligned integers.
.8BYTE.8byte valueinitializes the specified value to 8 bytes or 64-bit unaligned integers
.HALF.half valueinitializes the specified value to 2 bytes or 16-bit aligned integers.
.WORD.word valueinitializes the specified value to 4 bytes or 32-bit aligned integers
.DWORD.dword valuecreates a double word constant.

.STRING

String (.STRING) instruction emits the specified string.

Syntax
.string "String"

.ASCIZ

ASCIZ (.ASCIZ) instruction is similar to the ascii instruction and emits the specified string within double quotes. The “z” in .ASCIZ stands for zero i.e each string is followed by a zero byte.

Syntax
.asciz "string"

SHAKTI ASM MANUAL contains detailed description of all the assembler directives with examples.

Check out this ASM Program on Bubble sort,

start:
.data
Array: .byte 6,7,3,2,9,8
Arraysize: .byte 6
.text
 andi t0, t0, 0
 andi t1, t1, 0
 andi t3, t3, 0
 andi t4, t4, 0
 andi t5, t5, 0
 andi t6, t6, 0
 la t0, Array
 la t1, Arraysize
 lb t1, 0(t1)
 addi t1, t1, -1
 andi x1, x1, 0
outerloop:
 bge x0, t1, outerend
 andi t2, 0
innerloop:
 bge t2, t1, innerend
 lb t3, 0(t0)
 lb t5, 1(t0)
 bgt t3, t5, swap
 addi t0, t0, 1
 addi t2, t2, 1
 j innerloop
swap:
 mv t6, t3
 mv t3, t5
 mv t5, t6
 sb t3, 0(t0)
 sb t5, 1(t0)
 addi t0, t0, 1
 addi t2, t2, 1
 j innerloop
innerend:
 la t0, Array
 addi t1, t1, -1
 j outerloop
outerend: j outerend

Leave a Reply