CORRECTION: loop command infinite loop code here... - Minix

This is a discussion on CORRECTION: loop command infinite loop code here... - Minix ; My preceding loop command email didn't have infinite loop but this one does. "why? ..define _main ..define beg_loop ..define _print_num ..sect .text _main: push ebp ! Pushes EBP value. mov ebp, esp ! Stores ESP value. ! ------------------------------------------------------------ mov eax, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: CORRECTION: loop command infinite loop code here...

  1. CORRECTION: loop command infinite loop code here...

    My preceding loop command email didn't have infinite loop but this one
    does.
    "why?


    ..define _main
    ..define beg_loop
    ..define _print_num

    ..sect .text

    _main:
    push ebp ! Pushes EBP value.
    mov ebp, esp ! Stores ESP value.

    ! ------------------------------------------------------------
    mov eax, 60 ! Stores constant.
    mov ecx, 5 ! Stores constant.

    beg_loop:
    push eax ! Pushes parameter.
    call _print_num ! Calls function.
    pop eax ! Pops parameter.

    inc eax ! Increments EAX value.

    loop beg_loop ! Conditionally jumps.
    ! ------------------------------------------------------------

    xor eax, eax ! Stores return value.
    leave ! Pops EBP value.
    ret ! Returns from function.

    _print_num:
    push ebp ! Pushes EBP value.
    mov ebp, esp ! Stores ESP value.

    mov eax, 8(ebp) ! Stores parameter value.

    push eax ! Pushes parameter.
    push format_str ! Pushes parameter.
    call _printf ! Calls function.
    pop eax ! Pops parameter.
    pop eax ! Pops parameter.

    leave ! Pops EBP value.
    ret ! Returns from function.

    ..sect rom

    ..sect data

    format_str:
    .ascii "The number is %d .\n\0"

    ..sect bss


  2. Re: CORRECTION: loop command infinite loop code here...

    seberino@spawar.navy.mil wrote:
    > My preceding loop command email didn't have infinite loop but this one
    > does.
    > "why?
    >
    >
    > .define _main
    > .define beg_loop
    > .define _print_num
    >
    > .sect .text
    >
    > _main:
    > push ebp ! Pushes EBP value.
    > mov ebp, esp ! Stores ESP value.
    >
    > ! ------------------------------------------------------------
    > mov eax, 60 ! Stores constant.
    > mov ecx, 5 ! Stores constant.
    >
    > beg_loop:
    > push eax ! Pushes parameter.
    > call _print_num ! Calls function.
    > pop eax ! Pops parameter.
    >
    > inc eax ! Increments EAX value.
    >
    > loop beg_loop ! Conditionally jumps.
    > ! ------------------------------------------------------------
    >
    > xor eax, eax ! Stores return value.
    > leave ! Pops EBP value.
    > ret ! Returns from function.
    >
    > _print_num:
    > push ebp ! Pushes EBP value.
    > mov ebp, esp ! Stores ESP value.
    >
    > mov eax, 8(ebp) ! Stores parameter value.
    >
    > push eax ! Pushes parameter.
    > push format_str ! Pushes parameter.
    > call _printf ! Calls function.
    > pop eax ! Pops parameter.
    > pop eax ! Pops parameter.
    >
    > leave ! Pops EBP value.
    > ret ! Returns from function.
    >
    > .sect rom
    >
    > .sect data
    >
    > format_str:
    > .ascii "The number is %d .\n\0"
    >
    > .sect bss
    >


    Inside the loop there is a call to _print_num, which then calls _printf.
    The latter is probably modifying the ecx register. General purpose
    registers are not saved across function calls.

    Ciao
    Giovanni
    --
    A computer is like an air conditioner,
    it stops working when you open Windows.
    Registered Linux user #337974 < http://giovanni.homelinux.net/ >

  3. Re: CORRECTION: loop command infinite loop code here...

    Giovanni

    wow, thanks, I never would have seen that

    cs


+ Reply to Thread