Untitled
raw download clone
TEXT
views 22
,
size 706 b
.globl _start

.data
	
var:	.byte	14<<4+1		#some initial value...

outstr:	.ascii	"value = 0xhl\n"
.equ	strlen, . - outstr
 
.text
	
_start:

#pass only the necessary arguments

mov var,%al
mov $outstr+10,%edi



#invoke conversion
		
	call	convert_byte

#print the result

	mov	$1,%eax
	mov	$1,%edi	
	mov	$outstr,%rsi
	mov	$strlen,%edx
	syscall

#and exit

	mov	$60,%eax
	xor	%edi,%edi 
	syscall


#convert byte to a string (hex)

convert_byte:
mov %al,%cl
and $0x0F,%al
call convert_nibble
mov %al,%ah
shr $4,%al
call convert_nibble
mov %ax,(%edi)
	ret

	
convert_nibble:
cmp $10,%al
jb below10
add $55,%al
ret
below10:
add $48,%al
ret
close fullscreen
Login or Register to edit or fork this paste. It's free.