Re: Why is my nasm program killing itself?



ivanatora wrote:

Hello,
I've built an entry level program to print a few numbers/digits
(without using printf) and it is acting strange. If I print 1 symbol
it is ok. If I print 1 symbol multiple times - it is still ok. If I
try to modify the printing symbol (print different symbol at each
iteration) it is getting killed. Here is the nasm source:

---------------------------------------------------
Do you have any ideas?

Seems to be an assembler/linker problem.

When directly assembling your code to a binary the code works:



; nasm -f bin -o test test.asm


;===========================================================================
[bits 32]
orig equ $08048000
code_addr equ orig
code_offset equ 0
section .text vstart=code_addr

;--------------------------- ELF header -----------------------------------

dd $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dd 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dd 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096

;--------------------------- code ------------------------------------------

main:
mov byte [i],49 ;working once
mov esi,4
bla:
mov eax, 0x04
mov ebx, 0x01
mov ecx, i
mov edx, 1
int 80H
mov byte [i],65 ;no longer working. If I leave that here the program gets killed
mov eax, 0x04
mov ebx, 0x01
mov ecx, i
mov edx, 1
int 80H
; dec esi ;if I remove the last print sequence and uncomment these loop instructions I can print the same number 'esi' times
; jnz bla

mov eax, 0x01
int 80H

;--------------------------- constant data ---------------------------------


;---------------------------------------------------------------------------

align 4
code_memsz equ $-$$
code_filez equ code_memsz
data_addr equ (orig+code_memsz+4095)/4096*4096 + (code_filez % 4096)
data_offset equ code_filez
section .data vstart=data_addr

;--------------------------- initialized data ------------------------------

;---------------------------------------------------------------------------

idat_memsz equ $-$$
bss_addr equ data_addr+ ($-$$)
section .bss vstart=bss_addr

;--------------------------- uninitialized data ----------------------------
i resb 1

;---------------------------------------------------------------------------

udat_memsz equ $-$$
data_memsz equ idat_memsz + udat_memsz
data_filez equ idat_memsz

;===========================================================================
.



Relevant Pages