All of lore.kernel.org
 help / color / mirror / Atom feed
From: wklux@yahoo.co.uk
To: Jason Roberts <v3ct0r99@hotmail.com>,
	bdavids1@gmu.edu, linux-assembly@vger.kernel.org
Subject: Re: appending \n using registers
Date: Mon, 3 Nov 2003 19:55:51 +0000	[thread overview]
Message-ID: <200311031955.51859.wklux@yahoo.co.uk> (raw)
In-Reply-To: <Law9-F57R88vo2O66rD0001ae77@hotmail.com>

Jason Roberts am Monday 03 November 2003 14:31:
> hehe,
> I gathered what you meant there...but I guess if youre an at&t geek it

I don't like the hybrid att 'syntax', at all, but I prefer AS, because of 
compiling speed, reliability, availability...

> would not be trivial!
> now look here again and tell me I'm whacked: I just want to display a 2
> byte string with a \n!
> *note* I do not want to 'embed' a newline.
> Thanks for help
> pb


> section .data
>
> str         db "96"
>
> section .text
>
> global _start
>
> jmp _start
>
> _start:
> pusha
> call  _test
> popa
> jmp exit
>
>
>
> _test: could this line be culprit?  str is 2 bytes but I'm trying to mov 4
> using edx,no?
>
>          mov  edx,[str]     <-------		==> eax := dword at 'str'

this copies the _content_ at 'str' to edx,
i.e. l.s.bytes in memory copied to l.s.ytes in register, thus whether 2 or 4 
bytes buffer size won't matter while just reading; exactly matching access 
required only to preventing a 'segfault' (linux) when accessing memory just 
'below' top bound of reserved space.

I should think that you missed the meaning of the used operation - which seems  
a common error when migrating from 'masm'-like assemblers to the linux progs.

nasm expects either,
		lea edx,[str]
or,
		mov edx,str
to loading an effective address (hence 'LEA').

>          mov  ecx,edx				; ecx := edx = @str
not necessary. just copies the regs' content.

try 'mov edx,str' or 'lea edx,[str]' instead (I prefer LEA for clarity).

> ----------------------------------------------- <
            lea ecx,[str]	; buffer, i.e. string source
> ;;; mov  edx,[str]
> ;;; mov  ecx,edx
>          mov  edx,2
>          mov  eax,4
>          mov  ebx,1
>          int  0x80
> ------------------------------------------------ <

verify:
where is your buffer :)
how is the buffer related to your data?
what about EDI ?

> ------------------------------------------------ <
		push dword 0x0a0d	; push immediate data, lsb at addr ESP
		mov ecx,esp			; buffer is top dword of r-stack
> ;;; mov  edi,0x0a0d00
> ;;; mov  ecx,edx
>          mov  edx,2
>          mov  eax,4
>          mov  ebx,1
>          int  0x80
		lea esp,[esp+4]		; discard temp. buffer
>          ret
>
> exit:
>
>          mov ebx,eax
>          mov eax,1
>          int 0x80
> ------------------------------------------------ <

best,
	hp
-- 
Linux,Assembly,Forth: http://www.lxhp.in-berlin.de/index-lx.shtml en/de


       reply	other threads:[~2003-11-03 19:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Law9-F57R88vo2O66rD0001ae77@hotmail.com>
2003-11-03 19:55 ` wklux [this message]
     [not found] <Law9-F43TlbI3c57jHV0001de3a@hotmail.com>
2003-11-04 13:30 ` appending \n using registers peter w krause
2003-11-02  2:12 Jason Roberts
2003-11-02 19:15 ` peter w krause
2003-11-03 11:21   ` peter w krause

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200311031955.51859.wklux@yahoo.co.uk \
    --to=wklux@yahoo.co.uk \
    --cc=bdavids1@gmu.edu \
    --cc=linux-assembly@vger.kernel.org \
    --cc=v3ct0r99@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.