Skip to contentSkip to conversation

looping_code

DISCUSSION ssams 4 participants 8 messages Aug 26, 2002 – Sep 1, 2002

lore
Share & tools
lore

ssams

author
#0 lore raw

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

---------------------------------------------------------------------------------------

#1 lore raw
Quoted 7 lines · ssams

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...

Quoted 9 lines

by this code:

.data
msg: .byte 65,10

.text
.globl mulai
mulai:

    mov $10,%edx

Why $10 if Your msg is two bytes long?

Quoted 9 lines

ulang:
mov $4,%eax
mov $1,%ebx
mov $msg,%ecx
int $0x80
loop ulang

mov $1,%eax
int $0x80

Signature · 1 line
Maciej Hrebien
#2 lore raw
In reply to ssams
Quoted 6 lines · ssams

.data
msg: .byte 65,10

.text
.globl mulai
mulai:

Quoted 6 lines
    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)

Quoted 5 lines

int $0x80
loop ulang

mov $1,%eax
int $0x80

#3 lore raw
Quoted 9 lines · Scott Lanning
Quoted 8 lines · ssams

.data
msg: .byte 65,10

.text
.globl mulai
mulai:

    mov $10,%edx
Quoted 7 lines
Quoted 4 lines

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 | [email protected]
1801 E. Cotati Ave. | ph: 707.664.2806
Rohnert Park, CA 94928 | fax: 707.664.3012

#4 lore raw
Quoted 9 lines · Robert Plantz
Quoted 5 lines · Scott Lanning
Quoted 1 line · ssams

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.

#5 lore raw
In reply to Scott Lanning
Quoted 15 lines · Scott Lanning
Quoted 6 lines · ssams

.data
msg: .byte 65,10

.text
.globl mulai
mulai:

Quoted 6 lines
    mov $10,%edx

ulang:
mov $4,%eax
mov $1,%ebx
mov $msg,%ecx

Quoted 5 lines

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,

Signature · 1 line
Maciej Hrebien
#6 lore raw
Quoted 9 lines · Maciej Hrebien
Quoted 9 lines · ssams
Quoted 8 lines

.data
msg: .byte 65,10

.text
.globl mulai
mulai:

    mov $10,%edx
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

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

#7 lore raw
Quoted 17 lines · Robert Plantz
Quoted 5 lines

"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
Quoted 5 lines

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,

Signature · 1 line
Maciej Hrebien