输出问题,不读取跳转

时间:2009-11-04 22:32:03

标签: linux assembly

.section .data
msgI:
 .ascii "x = y\n"
msgI_end:


msgM:
 .ascii "x > y\n"
msgM_end:


msgL:
 .ascii "x < y\n"
msgL_end:


.section .text
.globl main
main:
    movl $5, %eax            #x = 5
    movl $5, %ebx            #y = 10
    cmp %ebx, %eax

    je IGUAL

    jg  MAYOR

    jl  MENOR

IGUAL:                       #Esta seccion de cogido se encarga
    movl $4, %eax            #de imprimir si x = y usando       
    movl $1, %ebx            #los system calls de Linux     
    pushl $msgI
    call printf             
    #movl $size, %edx           
    int $0x80                           
    jmp EXIT

MAYOR:                       #Esta seccion de cogido se encarga
    movl $4, %eax            #de imprimir si x > y usando       
    movl $1, %ebx            #los system calls de Linux     
    pushl $msgM
    call printf             
    #movl $size, %edx           
    int $0x80                           
    jmp EXIT

MENOR:                       #Esta seccion de cogido se encarga
    movl $4, %eax            #de imprimir si x < y usando       
    movl $1, %ebx            #los system calls de Linux     
    pushl $msgL
    call printf             
    #movl $size, %edx           
    int $0x80                           
    jmp EXIT

EXIT:
    movl $1, %eax            #System calls para salir del programa
    int $0x80

1 个答案:

答案 0 :(得分:2)

    movl $5, %ebx                    #y = 10

代码与评论不符。

    int $0x80                                                   
    jmp EXIT

你为什么要打电话给中断? printf已经完成打印,并覆盖了%eax等注册表。

现在,您将所有消息混杂在一起的原因是:printf采用NUL终止的字符串。如果它没有看到'\0',它会继续前进。

解决方案:在\0字符串的末尾添加msg*。然后printf将停止在那里打印。