Hi all,
I'm an Assembly newby and am studying Jeff Duntemann's book on programming Assembly on Linux. As much as I love Assembly and I have to learn it if I want to do anything significant in IT since it's part of a journey, I am finding difficult to get started because there are so many variables.
My environment is Ubuntu (Linux Debian) 9.10 64-bit and I am using NASM as compiler. Following Duntemann's suggestion, I created a sort of "sandbox" program where I can simply run few instructions and see the effect that these have on registers.
This is the simple program I'm writing:
I'm an Assembly newby and am studying Jeff Duntemann's book on programming Assembly on Linux. As much as I love Assembly and I have to learn it if I want to do anything significant in IT since it's part of a journey, I am finding difficult to get started because there are so many variables.
My environment is Ubuntu (Linux Debian) 9.10 64-bit and I am using NASM as compiler. Following Duntemann's suggestion, I created a sort of "sandbox" program where I can simply run few instructions and see the effect that these have on registers.
This is the simple program I'm writing:
Code:
; Executable name :
; Version : 1.0
; Created date :
; Last update :
; Author : Marco Tedone
; Description : A template to create sandbox programs
;
; Build using these commands:
; nasm -f elf64 -g -F stabs <your-asm-name>.asm
; ld -o <your-asm-name> <your-asm-name>.o
;
SECTION .data ; Section containing initialised data
SECTION .text ; Section containing code
global _start ; Linker needs this to find the entry point!
_start: ; Write your instructions between the two noops
nop
mov eax,0
inc eax
mov ebx,eax
nop
SECTION .bss ; Section containing uninitialised variables
[code]
The program compiles fine but when I run it I get segmentation fault. Why?
Also here there is another program (which actually does something useful) which runs fine:
[code]
; Executable name : EATSYSCALL
; Version : 1.0
; Created date : 1/7/2009
; Last update : 2/18/2009
; Author : Jeff Duntemann
; Description : A simple program in assembly for Linux, using NASM 2.05,
; demonstrating the use of Linux INT 80H syscalls to display text.
;
; Build using these commands:
; nasm -f elf -g -F stabs eatsyscall.asm
; ld -o eatsyscall eatsyscall.o
;
SECTION .data ; Section containing initialised data
EatMsg: db "Eat at Marco's !",10
EatLen: equ $-EatMsg
SECTION .bss ; Section containing uninitialized data
SECTION .text ; Section containing code
global _start ; Linker needs this to find the entry point!
_start:
nop ; This no-op keeps gdb happy...
mov eax,4 ; Specify sys_write call
mov ebx,1 ; Specify File Descriptor 1: Standard Output
mov ecx,EatMsg ; Pass offset of the message
mov edx,EatLen ; Pass the length of the message
int 80H ; Make kernel call
MOV eax,1 ; Code for Exit Syscall
mov ebx,0 ; Return a code of zero
int 80H ; Make kernel call
[code]