简体   繁体   English

使用FASM在装配编程中打印

[英]printing in assembly programming using FASM

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:.$'
    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. 但是,如果将“ msg db'Ascii sign:。$'”行移到“ jmp begin”下方,则该消息将能够显示。

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! 这只是出于好奇,谢谢!

Yes. 是。 Right now, msg is defined in the middle of the code, where the CPU will attempt to execute it. 现在,在代码中间定义了msg ,CPU将尝试在其中执行它。 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: 我不记得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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM