assemblyx86osdevfasmvideo-memory

Write string 16-bit fasm assembly


I made driver that should to work with vmem, but it doesn't work. I think mistake is registers that I uses to direct to the memory.

there is code of driver:

;;;;;;; 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

I am analyzed code, but can't find no one mistake.

P.S.: I tested only .twritezs function, maybe another doesn't work too.


Solution

  • These are the things that are wrong in the code snippets:

        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
    

    You can get your .twritezs code faster if you store the ASCII (at even address) and the Attribute (at next odd address) together in one instruction.
    Do notice that (E)SI is modified. You didn't push it.


    It's not clear why you would want to multiply by 2, the value in EAX in the other code snippets. Isn't EAX already a ready-to-use offset in the video buffer, just like in the .twritezs code?