at&t汇编------循环

.section .rodata
    .LC0:.string "%d\n"

.section .text

print_7:
    pushl %ebp
    movl %esp,%ebp
    pushl %ebx
    
    movl $1,%ebx
    jmp .L1
.L2:
    movl %ebx,%eax
    cltd
    movl $7,%ecx
    idivl %ecx
    
    cmpl $0,%edx
    jne .L3
    
    pushl %ebx
    pushl $.LC0
    call printf
    addl $8,%esp
    
.L3:
    addl $1,%ebx
.L1:
    cmpl $1000,%ebx
    jl .L2
    
    popl %ebx
    movl %ebp,%esp
    popl %ebp
    ret


print_7_2:
    pushl %ebp
    movl %esp,%ebp
    pushl %ebx
    
    movl $1,%ebx
    jmp .L4
.L5:   
    pushl %ebx
    pushl $.LC0
    call printf
    addl $8,%esp
    
    
    addl $1,%ebx
.L4:
    imull $7,%ebx,%eax
    cmpl $1000,%eax
    jl .L5 
    
    popl %ebx
    movl %ebp,%esp
    popl %ebp
    ret
    
   

print_rand:
    pushl %ebp
    movl %esp,%ebp
    pushl %ebx
    
    movl $0,%ebx
    jmp .L6
.L7:
    
    call rand
    cltd
    movl $100,%ecx
    idivl %ecx
    
    pushl %edx
    pushl $.LC0
    call printf
    addl $8,%esp
    
    
    addl $1,%ebx    
.L6:
    cmpl $100,%ebx
    jl .L7    
    
    popl %ebx
    movl %ebp,%esp
    popl %ebp
    ret

 

print:
    pushl %ebp
    movl %esp,%ebp
    pushl %ebx
    
    movl $0,%ebx
    jmp .L8
.L9:
       
    pushl %ebx
    pushl $.LC0
    call printf
    addl $8,%esp
    
    addl $1,%ebx
.L8:
    cmpl $100,%ebx
    jl .L9
    
    popl %ebx
    movl %ebp,%esp
    popl %ebp
    ret



looploop:
    pushl %ebp
    movl %esp,%ebp
    pushl %esi
    pushl %edi
    
    movl $0,%esi
    jmp .L10
.L11:
    
    
    movl $0,%edi
    jmp .L12
.L13:
    
    pushl $'*'
    call putchar
    addl $4,%esp
    
    addl $1,%edi
.L12:
    cmpl $6,%edi
    jl .L13
    
    
    pushl $'\n'
    call putchar
    addl $4,%esp
    
    addl $1,%esi
.L10:
    cmpl $5,%esi
    jl .L11
    
    
    popl %edi
    popl %esi
    movl %ebp,%esp
    popl %ebp
    ret



looploop2:
    pushl %ebp
    movl %esp,%ebp
    pushl %esi
    pushl %edi
    
    movl $1,%esi
    jmp .L14
.L15:    
    
    movl $0,%edi
    jmp .L16
.L17:    
    
    pushl $'*'
    call putchar
    addl $4,%esp
    
    addl $1,%edi
.L16:
    cmpl %esi,%edi
    jl .L17
    
    pushl $'\n'
    call putchar
    addl $4,%esp
        
    addl $1,%esi
.L14:
    cmpl $10,%esi
    jl .L15    
    
    popl %edi
    popl %esi
    movl %ebp,%esp
    popl %ebp
    ret




//void print_range(int m,int n);
print_range:
    pushl %ebp
    movl %esp,%ebp
    pushl %ebx
    
    movl 8(%ebp),%ebx
    jmp .L18
.L19:
    
    pushl %ebx
    pushl $.LC0
    call printf
    addl $8,%esp
    
    addl $1,%ebx
.L18:
    cmpl 12(%ebp),%ebx
    jle .L19
    
    
    popl %ebx
    movl %ebp,%esp
    popl %ebp
    ret



rand_num:
    pushl %ebp
    movl %esp,%ebp
    pushl %ebx
    
    movl $0,%ebx
    call rand
    cltd
    movl $50,%ecx
    idivl %ecx
    movl %edx,%esi
    
    jmp .L20
.L21:
    
    addl $1,%ebx

    call rand
    cltd
    movl $50,%ecx
    movl %edx,%edi
    
.L20:
    cmpl %esi,%edi
    jne .L21
    
    pushl %ebx
    pushl $.LC0
    call printf
    addl $8,%esp
    
    
    popl %ebx
    movl %ebp,%esp
    popl %ebp
    ret




 

上一篇:自制编译器 青木峰郎 笔记 Ch15 编译表达式和语句


下一篇:C语言编译过程:预编译、编译、汇编、链接