Nasm操作系统有计数器吗?

发布于 2024-12-29 08:45:21 字数 1029 浏览 3 评论 0原文

您好,我正在尝试在 nasm 中添加一个计数器,它只会显示一定数量的字符。

我知道我可以简单地从数据库中删除它们,但我想了解有关 16 位操作系统编程的更多信息。

BITS 16

start:
    mov ax, 07C0h       ; Set up 4K stack space after this bootloader
    add ax, 288     ; (4096 + 512) / 16 bytes per paragraph
    mov ss, ax
    mov sp, 4096

    mov ax, 07C0h       ; Set data segment to where we're loaded
    mov ds, ax


    mov si, text_string ; Put string position into SI


    call print_string   ; Call our string-printing routine

    jmp $           ; Jump here - infinite loop!


    text_string db 'Cyber Tronic Operating System version one', 0


print_string:           ; Routine: output string in SI to screen
    mov ah, 0Eh     ; int 10h 'print char' function

.repeat:
    lodsb           ; Get character from string
    cmp al, 0
                je .done
    int 10h         ; Otherwise, print it
    jmp .repeat

.done:
    ret


    times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55       ; The standard PC boot signature]

Hi I'm trying to add a counter in nasm where it will only show a certain amount of characters.

I know i could simply remove them from the db but i want to learn more about 16 bit operating system programming.

BITS 16

start:
    mov ax, 07C0h       ; Set up 4K stack space after this bootloader
    add ax, 288     ; (4096 + 512) / 16 bytes per paragraph
    mov ss, ax
    mov sp, 4096

    mov ax, 07C0h       ; Set data segment to where we're loaded
    mov ds, ax


    mov si, text_string ; Put string position into SI


    call print_string   ; Call our string-printing routine

    jmp $           ; Jump here - infinite loop!


    text_string db 'Cyber Tronic Operating System version one', 0


print_string:           ; Routine: output string in SI to screen
    mov ah, 0Eh     ; int 10h 'print char' function

.repeat:
    lodsb           ; Get character from string
    cmp al, 0
                je .done
    int 10h         ; Otherwise, print it
    jmp .repeat

.done:
    ret


    times 510-($-$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55       ; The standard PC boot signature]

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

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

发布评论

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

评论(1

抱着落日 2025-01-05 08:45:21

使用“循环”指令,如下所示:

print_string:           ; Routine: output string in SI to screen
    mov ah, 0Eh     ; int 10h 'print char' function

    mov cx,characters_to_print
.repeat:
    lodsb           ; Get character from string
    cmp al, 0
                je .done
    int 10h         ; Otherwise, print it
    loop .repeat

.done
    ret

Use the "loop" instruction, like this:

print_string:           ; Routine: output string in SI to screen
    mov ah, 0Eh     ; int 10h 'print char' function

    mov cx,characters_to_print
.repeat:
    lodsb           ; Get character from string
    cmp al, 0
                je .done
    int 10h         ; Otherwise, print it
    loop .repeat

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