Feeds:
Posts
Comments

Archive for December 28th, 2018

In assembly, you can execute a program with or without parameter. In order to do that, you need to call syscall no 11.

Execute without arguments.
This program (execute) will call a program (hello) without pass any argument.
Let’s try.
Type the codes below and save it to ‘execute.asm’.

1 section .text
2
3 global _start
4 _start:
5
6 mov eax,11 ;sys_execve
7 mov ebx,command
8 mov ecx,0h
9 int 0x80 ;syscall
10
11 mov eax,1 ;exit
12 int 0x80
13
14 section .data
15 command db './hello'

Type the codes below and save it to ‘hello.asm’.

1 section .text
2 global _start
3 _start:
4 mov eax,sys_write
5 mov ebx,stdout
6 mov ecx,msg
7 mov edx,lenmsg
8 int 0x80
9
10 mov eax,sys_exit
11 int 0x80
12
13 section .data
14 sys_write equ 4
15 sys_exit equ 1
16 stdout equ 1
17 msg db 'Hello word!',0xA
18 lenmsg equ $ - msg

Compile and run the program.

$ nasm -f elf32 hello.asm -o hello.o && ld hello.o -o hello
$ ls -l hello*
-rwxrwxr-x 1 darklinux darklinux 739 2018-12-23 10:04 hello
-rw-rw-r-- 1 darklinux darklinux 253 2018-12-23 09:58 hello.asm
-rw-rw-r-- 1 darklinux darklinux 704 2018-12-23 10:04 hello.o
$ nasm -f elf32 execute.asm -o execute.o && ld execute.o -o execute
$ ls -l execute*
-rwxrwxr-x 1 darklinux darklinux 636 2018-12-23 10:04 execute
-rw-rw-r-- 1 darklinux darklinux 183 2018-12-23 09:56 execute.asm
-rw-rw-r-- 1 darklinux darklinux 608 2018-12-23 10:04 execute.o
$ ./execute
Hello word!
$

(more…)

Read Full Post »

The ‘error: operation size not specified’ is a common error that occur when you try to copy a value into a location of a memory without specify the size of data that you want to copy.

I will show what it is.
Type the codes below and save it to ‘test.asm’.

1 section .text
2 global _start
3 _start:
4
5 mov ebx,33 ;copy '33' to ebx register
6 mov [x],5 ;copy '5' to location of address
7 ;pointer x
8
9 mov eax,1
10 int 0x80
11
12 section .data
13 x db 0

Compile it.

$ nasm -f elf32 test.asm -o test.o && ld test.o -o testtest.asm:5: error: operation size not specified
$

As you see the this error occur.

Now change the code:

1 section .text
2 global _start
3 _start:
4
5 mov ebx,33 ;copy '33' to ebx register
6 mov byte [x],5 ;copy '5' to location of address
7 ;pointer x
8
9 mov eax,1
10 int 0x80
11
12 section .data
13 x db 0

Compile it again.

$ nasm -f elf32 test.asm -o test.o && ld test.o -o test
$

When I specify the size of data (mov byte [x],5), there is no error now.

Read Full Post »