* looping_code
@ 2002-08-26 9:19 ssams
2002-08-26 14:59 ` looping_code Maciej Hrebien
2002-08-31 6:17 ` looping_code Scott Lanning
0 siblings, 2 replies; 8+ messages in thread
From: ssams @ 2002-08-26 9:19 UTC (permalink / raw)
To: linux-assembly
i really new in linux assembly. i want to know how i loop
some code..?
i feel it is different with tasm, i have try tasm way for
looping but
it was not run cleanly in gnu assembly. are there any body
want to help me....?
by this code:
.data
msg: .byte 65,10
.text
.globl mulai
mulai:
mov $10,%edx
ulang:
mov $4,%eax
mov $1,%ebx
mov $msg,%ecx
int $0x80
loop ulang
mov $1,%eax
int $0x80
--------------------- Yang Mudah dan Menghibur ----------------------------
Hosting menjadi mudah dan murah hanya di PlasaCom. Klik http://idc.plasa.com
F1 Mania!! Ikuti F1 Game di Obelix Game Corner di http://www.plasa.com/infotel/f1.html
---------------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: looping_code
2002-08-26 9:19 looping_code ssams
@ 2002-08-26 14:59 ` Maciej Hrebien
2002-08-31 6:17 ` looping_code Scott Lanning
1 sibling, 0 replies; 8+ messages in thread
From: Maciej Hrebien @ 2002-08-26 14:59 UTC (permalink / raw)
To: linux-assembly
ssams wrote:
>
> i really new in linux assembly. i want to know how i loop
> some code..?
> i feel it is different with tasm, i have try tasm way for
> looping but
> it was not run cleanly in gnu assembly. are there any body
> want to help me....?
I think it's NTG but lets see...
> by this code:
>
> .data
> msg: .byte 65,10
>
> .text
> .globl mulai
> mulai:
> mov $10,%edx
Why $10 if Your msg is two bytes long?
> ulang:
> mov $4,%eax
> mov $1,%ebx
> mov $msg,%ecx
> int $0x80
> loop ulang
>
> mov $1,%eax
> int $0x80
--
Maciej Hrebien
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: looping_code
2002-08-26 9:19 looping_code ssams
2002-08-26 14:59 ` looping_code Maciej Hrebien
@ 2002-08-31 6:17 ` Scott Lanning
2002-08-31 15:05 ` looping_code Robert Plantz
2002-08-31 15:51 ` looping_code Maciej Hrebien
1 sibling, 2 replies; 8+ messages in thread
From: Scott Lanning @ 2002-08-31 6:17 UTC (permalink / raw)
To: linux-assembly
On Mon, 26 Aug 2002, ssams wrote:
> .data
> msg: .byte 65,10
>
> .text
> .globl mulai
> mulai:
> mov $10,%edx
>
> ulang:
> mov $4,%eax
> mov $1,%ebx
> mov $msg,%ecx
This moves the value at 'msg'
rather than a pointer to 'msg'.
Try this:
leal msg, %ecx
Also, how many times do you think it will loop? :)
(hint: which register is the loop counter)
> int $0x80
> loop ulang
>
> mov $1,%eax
> int $0x80
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: looping_code
2002-08-31 6:17 ` looping_code Scott Lanning
@ 2002-08-31 15:05 ` Robert Plantz
2002-08-31 17:36 ` looping_code Scott Lanning
2002-08-31 15:51 ` looping_code Maciej Hrebien
1 sibling, 1 reply; 8+ messages in thread
From: Robert Plantz @ 2002-08-31 15:05 UTC (permalink / raw)
To: linux-assembly; +Cc: Scott Lanning
On Friday, August 30, 2002, at 11:17 PM, Scott Lanning wrote:
> On Mon, 26 Aug 2002, ssams wrote:
>> .data
>> msg: .byte 65,10
>>
>> .text
>> .globl mulai
>> mulai:
>> mov $10,%edx
>>
>> ulang:
>> mov $4,%eax
>> mov $1,%ebx
>> mov $msg,%ecx
>
> This moves the value at 'msg'
> rather than a pointer to 'msg'.
Sorry, but the gas assembler *will* treat the address
as an immediate. Proof:
When I did this ---
mov $msg,%ecx
leal msg,%edx
and looked in the debugger, I got ---
(gdb) i r
eax 0x4 4
ecx 0x80494c8 134517960
edx 0x80494c8 134517960
ebx 0x1 1
Furthermore, if you look at the listing --
12 000f B9000000 mov $msg,%ecx
12 00
13 0014 8D150000 leal msg,%edx
13 0000
you see that the leal instruction costs one more byte.
I have only done this in a very simple teaching environment
using linux. I may be missing something here in a dos or
windows environment. On the other hand, one probably would
use gas only in linux.
-- bob
-------------------------------------------------------
Robert G. Plantz, PhD |
Professor of Computer Science | cs.sonoma.edu/~bob
Sonoma State University | plantz@sonoma.edu
1801 E. Cotati Ave. | ph: 707.664.2806
Rohnert Park, CA 94928 | fax: 707.664.3012
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: looping_code
2002-08-31 6:17 ` looping_code Scott Lanning
2002-08-31 15:05 ` looping_code Robert Plantz
@ 2002-08-31 15:51 ` Maciej Hrebien
2002-08-31 17:10 ` looping_code Robert Plantz
1 sibling, 1 reply; 8+ messages in thread
From: Maciej Hrebien @ 2002-08-31 15:51 UTC (permalink / raw)
To: linux-assembly
Scott Lanning wrote:
>
> On Mon, 26 Aug 2002, ssams wrote:
> > .data
> > msg: .byte 65,10
> >
> > .text
> > .globl mulai
> > mulai:
> > mov $10,%edx
> >
> > ulang:
> > mov $4,%eax
> > mov $1,%ebx
> > mov $msg,%ecx
>
> This moves the value at 'msg'
> rather than a pointer to 'msg'.
> Try this:
>
> leal msg, %ecx
"mov $msg,%ecx" and "lea msg,%ecx" does the same thing in this example -
moves ptr to 'msg' to the ecx register. The only difference is that the
first one is coded one byte shorter.
Regards,
--
Maciej Hrebien
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: looping_code
2002-08-31 15:51 ` looping_code Maciej Hrebien
@ 2002-08-31 17:10 ` Robert Plantz
2002-09-01 9:21 ` looping_code Maciej Hrebien
0 siblings, 1 reply; 8+ messages in thread
From: Robert Plantz @ 2002-08-31 17:10 UTC (permalink / raw)
To: m_hrebien; +Cc: linux-assembly
On Saturday, August 31, 2002, at 08:51 AM, Maciej Hrebien wrote:
>> On Mon, 26 Aug 2002, ssams wrote:
>>> .data
>>> msg: .byte 65,10
>>>
>>> .text
>>> .globl mulai
>>> mulai:
>>> mov $10,%edx
>>>
>>> ulang:
>>> mov $4,%eax
>>> mov $1,%ebx
>>> mov $msg,%ecx
>
> "mov $msg,%ecx" and "lea msg,%ecx" does the same thing in this example -
> moves ptr to 'msg' to the ecx register. The only difference is that the
> first one is coded one byte shorter.
>
which can be seen if you do:
mov $msg,%ecx
leal msg,%edx
and look in the debugger ---
(gdb) i r
eax 0x4 4
ecx 0x80494c8 134517960
edx 0x80494c8 134517960
ebx 0x1 1
Furthermore, if you look at the listing --
12 000f B9000000 mov $msg,%ecx
12 00
13 0014 8D150000 leal msg,%edx
13 0000
--- Bob Plantz
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: looping_code
2002-08-31 15:05 ` looping_code Robert Plantz
@ 2002-08-31 17:36 ` Scott Lanning
0 siblings, 0 replies; 8+ messages in thread
From: Scott Lanning @ 2002-08-31 17:36 UTC (permalink / raw)
To: Robert Plantz; +Cc: linux-assembly
On Sat, 31 Aug 2002, Robert Plantz wrote:
> On Friday, August 30, 2002, at 11:17 PM, Scott Lanning wrote:
> > On Mon, 26 Aug 2002, ssams wrote:
> >> mov $msg,%ecx
> >
> > This moves the value at 'msg'
> > rather than a pointer to 'msg'.
>
> Sorry, but the gas assembler *will* treat the address
> as an immediate. Proof:
Right, sorry. ssams, ignore that part.
Fix the %ecx loop count.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: looping_code
2002-08-31 17:10 ` looping_code Robert Plantz
@ 2002-09-01 9:21 ` Maciej Hrebien
0 siblings, 0 replies; 8+ messages in thread
From: Maciej Hrebien @ 2002-09-01 9:21 UTC (permalink / raw)
To: linux-assembly
Robert Plantz wrote:
>
> > "mov $msg,%ecx" and "lea msg,%ecx" does the same thing in this example -
> > moves ptr to 'msg' to the ecx register. The only difference is that the
> > first one is coded one byte shorter.
> >
>
> which can be seen if you do:
> mov $msg,%ecx
> leal msg,%edx
>
> and look in the debugger ---
> (gdb) i r
> eax 0x4 4
> ecx 0x80494c8 134517960
> edx 0x80494c8 134517960
> ebx 0x1 1
>
> Furthermore, if you look at the listing --
> 12 000f B9000000 mov $msg,%ecx
> 12 00
> 13 0014 8D150000 leal msg,%edx
> 13 0000
Yes, that's right. Sorry for the mess - (don't know why) i received Your
"proof reply" just after i send my. In final we got two messages saying
the same :)
Regards,
--
Maciej Hrebien
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2002-09-01 9:21 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-26 9:19 looping_code ssams
2002-08-26 14:59 ` looping_code Maciej Hrebien
2002-08-31 6:17 ` looping_code Scott Lanning
2002-08-31 15:05 ` looping_code Robert Plantz
2002-08-31 17:36 ` looping_code Scott Lanning
2002-08-31 15:51 ` looping_code Maciej Hrebien
2002-08-31 17:10 ` looping_code Robert Plantz
2002-09-01 9:21 ` looping_code Maciej Hrebien
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).