Author Topic: segmentation fault(core dumped) and infinite loop..!  (Read 5255 times)

Offline avajos

  • Jr. Member
  • *
  • Posts: 5
segmentation fault(core dumped) and infinite loop..!
« on: April 16, 2014, 07:04:38 AM »
i have been trying very simple nasm programs...
i originally wanted to accept and display an array of numbers...but i am currently stuck at the accepting count stage..
i accept the count and want to convert it from ascii to hex...
Code: [Select]
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro

SECTION .data
msg : db "How many numbers you want add : "
len : equ $-msg
msg1 : db "Enter number : ", 10
len1 : equ $-msg1


SECTION .bss
input: resb 14
count: resb 4
temp: resb 17


SECTION .text
global _start
_start:

print msg,len
accept temp,04  ;accept the number of inputs to be taken

call convert

print msg,len

mov rax,60
mov rdx,0
syscall

convert: ;converts ascii to hex
mov rax,00h
mov rbx,00h
mov dx,2
mov rsi,temp

l1:

print msg,len   ;i put this print statement to check if the loop is being entered

rol rbx,04
mov al,[rsi]
cmp al,39h
jbe sub30
cmp al,'a'
jb sub7
sub al,20h

sub7:
sub al,07h

sub30:

sub al,30h
add rbx,rax
inc rsi
dec dx
jnz l1

ret

this is the code...!!..its actually giving me the segmentation error.i put the print statement in the loop, it is an infifnite loop..!

help please..!

thanks,
avajos..
« Last Edit: April 16, 2014, 07:15:11 AM by Frank Kotler »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: segmentation fault(core dumped) and infinite loop..!
« Reply #1 on: April 16, 2014, 07:31:09 AM »
Well... (edited your post to put in "code tags" - "code" in "[]", "/code" in "[]" blah blah blah...)
Code: [Select]
mov rax,60
mov rdx,0 ; rdi, no?
syscall

convert: ;converts ascii to hex
mov rax,00h
mov rbx,00h
mov dx,2
mov rsi,temp

l1:

print msg,len   ;i put this print statement to check if the loop is being entered
This trashes rax, rdx, and rsi, does it not? I haven't even tried your code yet, but that looks suspicious to me.

Best,
Frank