0 Replies - 1752 Views - Last Post: 01 December 2012 - 08:23 PM

#1 TightCoderEx   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 01-December 12

64 bit X86 Linux --- Display string

Posted 01 December 2012 - 08:23 PM

Description: The design criteria here is to facilitate string display in a loop without needing to know the length of each string. Display an ASCII null terminated string on VT100 or compatible terminal. Developed and tested on Ubuntu 12.04 using NASM
	SYS_WRITE       equ      1
   	   STDOUT	equ	 1

		global	Show

		section	.text
; =============================================================================================

;	ENTER:	RSI = Pointer to string to be displayed

;	LEAVE:	RAX = Strings length including terminator
;		    = 1 Equivalent to NULL string

;		RSI = Points to next avaliable string (assuming there is one)

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

  Show:		push	rdi
		push	rdx			; Preserve
		push	rcx
	
	; Find EOS
	
		or	rcx, -1			; Should be big enough
		mov	rdi, rsi		; RDI needs to be pointer
		mov	 al, 0
		repnz	scasb			; Search for EOS
		neg	rcx
		sub	ecx, 2			; Bump to account for terminator
		push	rdi			; We'll need this later
		jz	.ZeroStr
		
	; Display string
	
		mov	rdx, rcx
		mov	eax, STDOUT
		mov	rdi, rax
		syscall
	
	; Setup registers for return to caller
	
  .ZeroStr	inc	eax			; Bump over terminator
		pop	rsi			; Restore pointer to next position
		
		pop	rcx
		pop	rdx			; Retrieve
		pop	rdi
	
		ret


Is This A Good Question/Topic? 0
  • +

Page 1 of 1