简单的hello world asembly程序打印出垃圾

时间:2018-04-08 12:56:30

标签: linux assembly

我正在使用x86程序集来制作一个简单的程序,比较两个单词并打印出来,如果它们相等(我知道它只是学习和测试的东西)它的工作正常但是在得到的答案之后我打印出来有很多垃圾,我不明白是什么导致这个错误

    SECTION .bss
    SECTION .text
    SECTION .data
    HelloMsg: db "Helllo",10
    HelloLength: equ $-HelloMsg

    HellloMsg: db "Helllo",10
    HellloLength: equ $-HellloMsg

    One: db "First",10
    OneLen: equ $-One

    Two: db "Second",10
    TwoLen: equ $-Two

    global _start

    _start:
    nop
    mov eax,4
    mov ebx,1
    mov ecx,HellloLength
    mov edx,HelloLength

    cmp ecx,edx
    je true
    mov ecx,One
    mov edx,OneLen
    int 80H

    true:
    mov ecx,Two 
    mov edx,One
    int 80H

    MOV eax,1
    mov ebx,0
    int 80H

输出:

enter image description here

很抱歉,如果我问一个愚蠢的问题,或者我的程序难以阅读

1 个答案:

答案 0 :(得分:3)

代码中有一个小错误。调用write系统时,调用edx必须包含要写入的字符串的长度。但是,如果比较字符串具有相同的长度(true:情况),则代码为:

true:
mov ecx,Two
mov edx,One
int 80H

One引用字符串" First",而不是字符串Two的长度。

通过将其更改为:

来修复它
true:
mov ecx,Two
mov edx,TwoLen
int 80H
相关问题