Display an ASCII string on console UBUNTU 12.04 using int 80H
; =========================================================================================================
; Display ASCII string on console (monitor)
; ENTRY: RDX = Pointer to null terminated string to be displayed.
; LEAVE: RAX = Bytes displayed not including null.
; All other registers preseved.
; FLAGS: ZR = 1 If nothing was displayed.
; ---------------------------------------------------------------------------------------------------------
Console: push rbx
push rcx ; Preserve the registers we don't want to change
push rdx
; Determine where the end of null terminated string is
xor rax, rax
mov rbx, rax
inc ebx ; EBX = STDOUT
mov rcx, rax
dec rcx ; Should be sufficiently large
push rdi
mov rdi, rdx ; Set pointer
repnz scasb ; Find end of string
pop rdi ; Restore index to its original value
; We can do this a couple of ways, but I haven't experimented to see which way is best
neg ecx
dec ecx
dec ecx ; ECX = Actual size now
xchg rdx, rcx ; Swap so they are in proper position
mov al, WRITE ; Set sys_write number
int 0x80
mov rax, rdx ; Set return value
or rax, rax ; and set ZR
; Clean-up and go back
pop rdx
pop rcx ; Restore preserved registers
pop rbx
ret ; Return with string size in RAX and ZR=1 if string empty.
Null terminated strings are unconventional for nix's, but as using EDX in other platforms is a habit, I'm adopting the same philosophy here. Not sure what goot the return value is going to be now, but I'm sure somewhere down the road it'll come in handy.