gpt4 book ai didi

linux - 简单的 hello world 汇编程序打印出垃圾

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:44:34 24 4
gpt4 key购买 nike

我正在使用 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

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

最佳答案

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

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

One 指的是字符串“First”,而不是字符串 Two 的长度。

修改为:

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

关于linux - 简单的 hello world 汇编程序打印出垃圾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49718061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com