I an a newbie to assembly language, been reading jeff duntemann's book, and I have been trying to write some code by myself too. There is an example in the book on converting binary values to hex values. I decided to re-write the code again by myself for self-practice but i get a segmentation fault. Here is the code:

section .bss
	BUFFLEN equ 16
	BUFF resb 16

section .data
	HexStr: db " 00h 00h 00h 00h 00h 00h 00h 00h 00h 00h 00h 00h 00h 00h 00h 00h",10
	HexLen equ $-HexStr
	Digits: db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,61h,62h,63h,64h,65h,66h

section .text
	global _start
_start:

Read:
	mov eax,3
	mov ebx,0
	mov ecx,BUFFLEN
	mov edx,BUFF
	INT 80H
	cmp eax,0
	je Done
	  
	mov ebp,eax 
	mov ebx,Digits
	xor ecx,ecx
	xor eax,eax
	xor edx,edx

Translate:
	  mov al,byte [BUFF+ecx] 
	  mov edx,eax 
	  and eax,0fh
	  xlat 
	  mov byte [HexStr+4*ecx+2],al

	  shr dl,4
	  mov al,dl
	  xlat
	  mov byte [HexStr+4*ecx+1],al
	
	  inc ecx
	  cmp ecx,ebp

	  jb Translate

Write:
	  mov eax,4
	  mov ebx,1
	  mov ecx,HexLen
	  mov edx,HexStr
	  int 80h
	  jmp Read

Done: 
	mov eax,1
	mov ebx,0
	int 80h

anw i found the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.