使用 FASM 在汇编编程中打印

发布于 2025-01-02 18:22:59 字数 336 浏览 1 评论 0原文

我正在尝试使用下面的代码打印一条消息:

org 100h
start:
    jmp begin

begin:
    mov ah, 9
    mov dx, msg
    msg db 'Ascii sign:.$'
    int 21h

finish:
    mov ax, 4c00h
    int 21h

它能够编译,但根本不显示任何内容。但是,如果我将“msg db 'Ascii sign:.$'”行移到“jmp begin”下方,则可以显示该消息。

我想知道这背后的逻辑。我在哪里声明消息有什么不同吗?

这只是出于好奇,谢谢!

I am trying to print a message by using the code below:

org 100h
start:
    jmp begin

begin:
    mov ah, 9
    mov dx, msg
    msg db 'Ascii sign:.

It is able to compile but it display nothing at all. But if I move the line "msg db 'Ascii sign:.$'" below "jmp begin", the message is able to display.

I want to know the logic behind this. Does that make a difference where I declare the message ?

This is just out of curiosity, thank you!

int 21h finish: mov ax, 4c00h int 21h

It is able to compile but it display nothing at all. But if I move the line "msg db 'Ascii sign:.$'" below "jmp begin", the message is able to display.

I want to know the logic behind this. Does that make a difference where I declare the message ?

This is just out of curiosity, thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我老 2025-01-09 18:22:59

是的。现在,msg 定义在代码中间,CPU 将尝试执行它。您通常希望在数据段中单独定义数据。我不记得 FASM 的语法,但使用 MASM 或 TASM,您通常会执行以下操作:

.model small
.data

msg db 'ASCII sign: .


.code
main proc
     mov ah, 9
     mov dx, offset msg
     int 21h
     mov ax, 4c00h
     int 21h
main endp
     end main

Yes. Right now, msg is defined in the middle of the code, where the CPU will attempt to execute it. You normally want to define data separately, in the data segment. I don't remember the syntax for FASM, but with MASM or TASM, you'd normally do something like this:

.model small
.data

msg db 'ASCII sign: .


.code
main proc
     mov ah, 9
     mov dx, offset msg
     int 21h
     mov ax, 4c00h
     int 21h
main endp
     end main
沦落红尘 2025-01-09 18:22:59

如果您确实必须将字符串放在代码部分中,那么只需跳过它们即可。

begin:
    mov ah, 9
    mov dx, msg
    jmp overstring
    msg db 'Ascii sign:.

overstring:
    int 21h

finish:
    mov ax, 4c00h
    int 21h

If you really must have your strings in the code section, then just jump over them.

begin:
    mov ah, 9
    mov dx, msg
    jmp overstring
    msg db 'Ascii sign:.

overstring:
    int 21h

finish:
    mov ax, 4c00h
    int 21h
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文