linux - 输出有问题,不读跳转

标签 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

最佳答案

    movl $5, %ebx                    #y = 10

代码与注释不匹配。

    int $0x80                                                   
    jmp EXIT

为什么要调用中断? printf 已经完成打印,并且覆盖了像 %eax 这样的寄存器。

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

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

关于linux - 输出有问题,不读跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1677134/

相关文章:

linux - 在 Amazon Ec2 上为 apache 用户设置路径变量

c - ARM 程序集 : Access array elements residing in C type struct

c - 堆栈清理不起作用(__stdcall MASM 函数)

c - 32 位字的镜像位

assembly - x86 程序集 - 为什么 [e]bx 保留在调用约定中?

android - 从命令行打开 Android 应用程序并与之交互

linux - 查找所有正在运行的进程的 ProcessorId 和 Cpu 使用情况

node.js - 如何将 32 位 node.js(8.5.0) 安装到 64 位 ubuntu(17.0)?

c - SSE指令MOVSD(扩展:x86,x86-64上的浮点标量和 vector 运算)

linux - 如何在 shell 脚本中使用 grep 在文件中查找单词