www.main.lv
Don't think just code it

2011-01-22 Linux assembler scripting language

This is small interpretr in asm.
It works with small language thats can make simple things
All that you need to know about language
is this symbols "ABCDI$@"

ABCD is used with parametr.
I without param
$@ is params


ABCD - is like assembler command mov where symbol is register name
A0 is mov eax, 0
B9 is mov ebx, 9
only one number is supported. Number range after ABCD suposed to be 0...9. But you can add any other symbol only not @ or $. Look inside ascii table char '0' is 0 and other goes relativly from it. number '~' is '~'-'0'=127-48=79

I - is interupt number 80h

$@ - is variables from stack
@ - uses current varaible from stack and stack pointer goes to next stack value
$ - uses current stack value and dont change stack pointer position

Thats all.

Now we can make our first script and run it.

There is 2 thing that you should know. Script is converted to assembler commands and copyed in memory position.

Every file has hiw own purpose and all they seperated for easy to use

'script.inc' you scipt inside it
'stack_table.inc' configure stack for use
'variables.inc' define variables
'exec.inc' memory region wher script interpreted commands will copyed

Example 1:
Now first example script:
script db 'A1B0I'
mov eax, 1 ;you can look this variable inside
#include < asm/unistd.h> 
or in http://bluemaster.iu.hio.no/edu/dark/lin-asm/syscalls.html
mov ebx, 0
int 80h

it is command exit. stack can be empty.
Example2:
Now we can make hello_world.
script db 'A4B1C@D@IA1B0I'
It is
mov eax, 4
mov ebx, 1
mov ecx, buffer_msg; stack value 0
mov edx, buffer_len; stack value 1
int 80h

mov eax, 1
mov ebx, 0
int 80
in C it would be
write(1,buffer_msg,buffer_len)
exit(0);
Here is example how corresponds asm to C code http://www.main.lv/posts/view/linux-assembler-open-file. Ther is used stack in 'stack_table.inc':
stack_table:
	dd buffer_msg ;variable 0
	dd buffer_len ;variable 1
and in 'variables.inc' we define this variables:
buffer_msg db "Hello world",10	;with newline
buffer_len = $-buffer_msg	;using fasm mega feature to detect size
we can count equvialent asm commands and there is 8 of them it means add 8 lines in 'exec.inc'
	db 0x90,0x90,0x90,0x90,0x90
	db 0x90,0x90,0x90,0x90,0x90
	db 0x90,0x90,0x90,0x90,0x90
	db 0x90,0x90,0x90,0x90,0x90
	db 0x90,0x90,0x90,0x90,0x90
	db 0x90,0x90,0x90,0x90,0x90
	db 0x90,0x90,0x90,0x90,0x90
	db 0x90,0x90,0x90,0x90,0x90

type make and everything works =]. WooHoo small interpretd language is made and it fits in 417 bytes.

Downloads