繁体   English   中英

写字符串 16 位 fasm 程序集

[英]Write string 16-bit fasm assembly

我制作了应该与 vmem 一起使用的驱动程序,但它不起作用。 我认为错误是我用来指向内存的寄存器。

有驱动程序代码:

;;;;;;; Primary Video Driver
PVideo:
                .treadbyte:    ; in:eax=ID, [0 - 3440]; out:cl=BYTE [0 - 255]
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        inc eax
                        add ebx, eax
                        mov cl, byte[ebx]
                        pop eax ebx di
                        ret
                .treadattr:    ; in:eax=ID, [0 - 3440]; out:cl=BYTE [0 - 255]
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        add ebx, eax
                        mov cl, byte[ebx]
                        pop eax ebx
                        ret
                .twritebyte:   ; in:eax=ID, [0 - 3440]/dl=BYTE, [0 - 255]; out:none
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        inc ax
                        add ebx, eax
                        mov byte[ebx], dl
                        pop eax ebx
                        ret
                .twriteattr:   ; in:eax=ID, [0 - 3440]/dl=BYTE, [0 - 255]; out:none
                        push eax ebx
                        mov ebx, 0xb8000
                        imul eax, 2
                        add ebx, eax
                        mov byte[ebx], dl
                        pop eax ebx
                        ret
                .twritezs:     ; in:eax=POS, [0 - 3440-len(ZS)]/si=ZS, offset[0 - 32512]/dl=BYTE; out:none
                        push eax ebx
                        mov ebx, 0xb8000
                        ;imul eax, 2
                        ;inc eax
                        add ebx, eax
                    .l:
                        lodsb
                        cmp al, 0x00
                        je .ret
                        mov byte[ebx], dl
                        inc ebx
                        mov byte[ebx], al
                        inc ebx
                        jmp .l
                    .ret:
                        pop eax ebx
                        ret

我分析了代码,但找不到任何错误。

PS:我只测试了 .twritezs 函数,也许另一个也不起作用。

这些是代码片段中错误的地方:

  • push堆栈的所有内容都需要以相反的顺序关闭(如果使用pop )。
  • 在 0x000B8000 的视频存储器中,字符代码 (ASCII) 进入偶数地址的字节,颜色代码(属性)进入奇数地址的字节。
    push eax ebx
    lea  ebx, [0x000B8000 + eax]
    mov  ah, dl      ; Attribute
  .next:
    lodsb            ; ASCII
    cmp  al, 0
    je   .ret
    mov  [ebx], ax   ; Store ASCII at even address and Attribute at next odd address
    add  ebx, 2
    jmp  .next
  .ret:
    pop  ebx eax
    ret

如果将 ASCII(在偶数地址)和属性(在下一个奇数地址)存储在一条指令中,则可以更快地获得.twritezs代码。
请注意(E)SI已修改。 你没有push


不清楚为什么要乘以其他代码片段中EAX中的值 2。 .twritezs代码一样, EAX是不是已经是视频缓冲区中的一个现成的偏移量?

暂无
暂无

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

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