pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pgubook-readers] high-level conditional branches


From: modular modular
Subject: [Pgubook-readers] high-level conditional branches
Date: Mon, 27 Jun 2005 10:34:03 +0200

Hello,

I'm trying to write programs to mimic C "for loops". I seem to come up
with a new idea for an algorithm daily, so I'm sure there are many
ways to do this.

#forloop.s
#modular <address@hidden>
.section .data
output:
 .asciz "%d\n"
.section .text
.globl _start
_start:
 nop
 movl $1, -4(%esp)
compare:
    cmpl $10, -4(%esp)
    jle forloop
    jmp end
forloop:
    pushl -4(%esp)
    pushl $output
    call printf
    addl $8, %esp
    incl -4(%esp)
    jmp compare
end:
    pushl $0
    call exit

I'm using -4(%esp) to store the counter in, but really want to use
registers in the program. If I use %ecx for example, it just keeps get
reset. I just popl off the stack, but I keep getting infinite loops.
Any hints to how this can be done?

Regards,
modular




reply via email to

[Prev in Thread] Current Thread [Next in Thread]