I don't understand what's wrong with the code

54 views Asked by At

I've copied a code from an assembly book and used an image I've converted from PNG to BMP, and called the file "doeshe.bmp" however, I don't see the picture. (I saved my picture in my TASM folder, but not inside BIN).
it also does not work when the picture is inside BIN.

This is the code:

IDEAL
MODEL small
STACK 100h
DATASEG
    filename db 'doeshe.bmp',0
    filehandle dw ?
    Header db 54 dup (0)
    Palette db 256*4 dup (0)
    ScrLine db 320 dup (0)
    ErrorMsg db 'Error', 13, 10 ,'$'
CODESEG
proc OpenFile
    mov ah, 3Dh
    xor al, al
    mov dx, offset filename
    int 21h
    jc openerror
    mov [filehandle], ax
    ret
    openerror :
    mov dx, offset ErrorMsg
    mov ah, 9h
    int 21h
    ret
endp OpenFile
proc ReadHeader
    mov ah,3fh
    mov bx, [filehandle]
    mov cx,54
    mov dx,offset Header
    int 21h
    ret
endp ReadHeader 
proc ReadPalette
    mov ah,3fh
    mov cx,400h
    mov dx,offset Palette
    int 21h
    ret
endp ReadPalette

proc CopyPal
    mov si,offset Palette
    mov cx,256
    mov dx,3C8h
    mov al,0
    out dx,al
    inc dx
    PalLoop:
        mov al,[si+2] 
        shr al,2 
        out dx,al 
        mov al,[si+1]
        shr al,2
        out dx,al
        mov al,[si]
        shr al,2
        out dx,al
        add si,4 
        loop PalLoop
    ret
endp CopyPal
proc CopyBitmap
    mov ax, 0A000h
    mov es, ax
    mov cx,200
    PrintBMPLoop :
        push cx
        mov di,cx
        shl cx,6
        shl di,8
        add di,cx
        mov ah,3fh
        mov cx,320
        mov dx,offset ScrLine
        int 21h
        cld 
        mov cx,320
        mov si,offset ScrLine
        rep movsb
        pop cx
        loop PrintBMPLoop
        ret
endp CopyBitmap
start :
    mov ax, @data
    mov ds, ax
    mov ax, 13h
    int 10h
    call OpenFile
    call ReadHeader
    call ReadPalette
    call CopyPal
    call CopyBitmap
    mov ah,1
    int 21h
    mov ah, 0
    mov al, 2
    int 10h
exit:
    mov ax, 4c00h
    int 21h
END start

I was expecting to see the image I've created, however I saw "Error".

0

There are 0 answers