;-----------------------------
;文件满足256色调的
;-----------------------------
Stack    Segment
         Stk          db    65535    dup(?)
Stack    Ends
Data     Segment
         ImageBuffer  db    65078    dup(?)
         ImageSrc     db    'bitmap.bmp',0                 ;修改同目录下图片的文件名
         Eflag        db    ?
         OpenErrorMsg db    'file not found',24h
         Not256Color  db    'Not a 256 color bitmap',24h
         handle       dw    ?
Data     Ends
Code     Segment
         Assume cs:Code,ds:Data,ss:Stack
Start:
         mov ax,Data
         mov ds,ax
         mov di,0                ;修改读取开始的Y坐标
     mov si,0        ;修改读取开始的X坐标
         mov dx,offset ImageSrc
         push si
         push di
         push dx
         call Bitmap
         mov ax,0
         int 16h
         mov ax,4c01h
         int 21h
         
BitMap   Proc ;===========================================================================          push bp
         mov bp,sp
         sub sp,20
         push ax
         push bx
         push cx
         push dx
         push si
         push di
         push es
         mov dx,[bp+4]
         mov ax,3d00h
         int 21h           ;Open the bitmap file
         jnc OpenOk
         mov Eflag,0
Error:                     ;Show error message
         cmp Eflag,0
         jz  OpenError
         cmp Eflag,1
         jz  Not256
OpenError:
         mov dx,offset OpenErrorMsg
         jmp showtext
Not256:
         mov dx,offset Not256Color
         jmp ShowText
ShowText:
         mov ah,09h
         int 21h
         jmp exit
OpenOk: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;
;        Read  first 4 byte of the file in order to get the file size      ;;;;;;;;;;;;
;                                                                          ;         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;         ;;
                                                                                     ;;
         mov bx,ax                                                                   ;;
         mov handle,bx                                                               ;;
         mov dx,offset ImageBuffer                                                   ;;
         mov cx,4                                                                    ;;
         mov ax,3f00h                                                                ;;
         int 21h           ;Read the first 4 byte to memory                          ;;
         mov ax,3e00h                                                                ;;
         mov bx,handle                                                               ;;
         int 21h           ;Close the bitmap file                                    ;;
                                                                                     ;;
;====================================================================================;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;     
;        Read The entire bitmap file to memory                             ;;;;;;;;;;;;
;                                                                          ;         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;         ;;
                                                                                     ;;
         mov si,2                                                                    ;;
         mov cx,[si]       ;Save the bitmap file entire size to CX Register          ;;
         mov dx,[bp+4]     ;                                                         ;;
         mov ax,3d00h                                                                ;;
         int 21h           ;Open the bitmap file again                               ;;
         mov bx,ax                                                                   ;;
         mov handle,bx                                                               ;;
         mov dx,offset ImageBuffer                                                   ;;
         mov ax,3f00h                                                                ;;
         int 21h           ;Read the entire bitmap file to memory                    ;;
         mov ax,3e00h                                                                ;;
         mov bx,handle                                                               ;;
         int 21h           ;Close the bitmap file                                    ;;
                                                                                     ;;
;====================================================================================;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;
;        Save Information to local variable                                ;;;;;;;;;;;;
;                                                                          ;         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;         ;;
                                                                                     ;;
         mov si,012h                                                                 ;;
         mov ax,[si]                                                                 ;;
         mov [bp-2],ax     ;Save BmpWidth                                            ;;
         mov [bp-4],ax     ;Save BmpOnScreenWidth                                    ;;
         mov [bp-6],ax     ;Save BytePerRow                                          ;;
         mov cl,4                                                                    ;;
         div cl                                                                      ;;
         cmp ah,0                                                                    ;;
         jz  NoDwAA        ;No Dword align adjust                                    ;;
         mov cl,4                                                                    ;;
         sub cl,ah                                                                   ;;
         add [bp-6],cl                                                               ;;
NoDwAA:                                                                              ;;
         mov cx,0                                                                    ;;
         mov [bp-8],cx     ;Save LeftCutWidth,Default = 0                            ;;
         mov si,016h                                                                 ;;
         mov ax,[si]                                                                 ;;
         mov [bp-10],ax    ;Save BmpHeight                                           ;;
         mov [bp-12],ax    ;Save BmpOnScreenHeight                                   ;;
         mov si,01ch                                                                 ;;
         mov ax,[si]                                                                 ;;
         mov [bp-14],ax    ;Save BitPerPixel                                         ;;
         mov si,0eh                                                                  ;;
         mov ax,[si]       ;Save bmpfileheader length                                ;;
         add ax,14                                                                   ;;
         mov [bp-16],ax    ;Save PaletteOffset                                       ;;
         mov si,0ah                                                                  ;;
         mov ax,[si]                                                                 ;;
         mov [bp-18],ax    ;Save ImgDataOffset                                       ;;
         ;mov [bp-20],0     ;Save RowOffset                                          ;;
                                                                                     ;;
;====================================================================================;; ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;                                                                                    
;        Seve the value to Local variable
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>          jmp CoorDinateX
exitzz:
         jmp exit
CoordinateX:         
         mov ax,[bp+6]     ;X coordinate
         push ax
         and ah,80
         pop ax
         jz  PositiveX     ;If X coordinate>=0,jump
         mov ax,[bp+6]
         push ax
         not ax
         inc ax
         mov [bp-8],ax     ;Save LeftCutWidth
         pop ax
         add ax,[bp-2]     ;X coordinate add BmpWidth
         jnc exitzz        ;Exit if X coordinate add BmpWidth < 0
         jz exitzz         ;Exit if X coordinate add BmpWidth = 0
         push ax
         mov cx,320
         sub cx,ax
         mov [bp-20],cx    ;Save RowOffset
         add ax,[bp-8]     
         mov [bp-4],ax     ;Save BmpOnScreenWidth + LeftCut
         pop ax
         mov cx,320
         cmp cx,ax
         jnc NoWOverf      ;No Width Overflow
         mov ax,[bp-8]
         add ax,320
         mov [bp-4],ax     ;Save BmpOnScreenWidth = 320 + LeftCutWidth
         mov ax,0
         mov [bp-20],ax
NoWOverf:
         mov ax,0
         mov [bp+6],ax
         jmp CoordinateY
PositiveX:
         cmp ax,320
         jnc exitzz
         mov cx,320
         sub cx,[bp-2]
         mov [bp-20],cx
         add ax,[bp-2]
         mov cx,320
         cmp cx,ax
         jnc CoordinateY
         mov ax,320
         sub ax,[bp+6]
         mov [bp-4],ax     ;Save OnScreenWidth
         mov cx,320
         sub cx,ax
         mov [bp-20],cx    ;SaveRowOffset
CoordinateY:
         mov ax,[bp+8]     ;Y coordinate
         push ax
         and ah,80
         pop ax
         jz PositiveY
         add ax,[bp-10]
         jnc exitzz1
         jz exitzz1
         mov [bp-10],ax    ;Save BmpHeight
         mov [bp-12],ax    ;Save OnScreenHeight
         mov cx,0
         mov [bp+8],cx
         mov cx,200
         cmp cx,ax
         jnc SetInt10      ;No Height Overflow
         mov cx,200
         mov [bp-12],cx
NoHOverf:        
         jmp SetInt10
exitzz1:
         jmp exit
PositiveY:
         cmp ax,200
         jnc exitzz1
         add ax,[bp-10]
         mov cx,200
         cmp cx,ax
         jnc SetInt10
         mov ax,200
         sub ax,[bp+8]
         mov [bp-12],ax ;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> ;**************************************************************************************
;                                                                                    
;        Set the Palette register and copy image data to video buffer which
;        address start at A000:0000.
;
;************************************************************************************** SetInt10:
         mov ax,013h     
         int 10h          ;Set Video Mode to 13h
         mov dx,03c6h
         mov ax,0ffh
         out dx,ax
         mov si,[bp-16]
         mov di,0
         mov cx,256
SetPalette:        
         mov dx,03c8h
         mov ax,di
         out dx,al
         mov dx,03c9h
         mov al,byte ptr[si+2]
         push bx
         mov bl,63
         mul bl
         mov bl,0ffh
         div bl
         pop bx
         out dx,al
         mov al,byte ptr[si+1]
         push bx
         mov bl,63
         mul bl
         mov bl,0ffh
         div bl
         pop bx
         out dx,al
         mov al,byte ptr[si]
         push bx
         mov bl,63
         mul bl
         mov bl,0ffh
         div bl
         pop bx
         out dx,al
               add si,4
         inc di
         loop SetPalette
Showbmp:
         mov ax,0a000h    ;Video memory start address   
         mov es,ax
         mov ax,[bp+8]
         mov cx,320
         mul cx
         add ax,[bp+6]
         mov di,ax
vertical:
         cmp word ptr[bp-12],0
         jz exit
         dec word ptr[bp-10]
         dec word ptr[bp-12]
         mov ax,[bp-10]
         mul word ptr[bp-6]
         mov bx,ax
         add bx,[bp-18]
         mov si,0
         add si,[bp-8]
horizon:
         cmp si,word ptr[bp-4]
         jz horizonend
         mov al,[bx][si]
         mov es:[di],al
         inc si
         inc di
         jmp horizon
horizonend:
         add di,[bp-20]
         jmp Vertical
       
;************************************************************************************** exit:
         pop es
         pop di
         pop si
         pop dx
         pop cx
         pop bx
         pop ax
         add sp,20
         pop bp
         ret 6
Bitmap   endp
Code     Ends
         End Start

masm编译后
在同目录下放入.bmp图片文件
然后运行bitmap.exe

可以看到全屏显示了T00LS的logo了
按任意键可以退出

代码中修改文件名和从X、Y读取的地方我做了注释

【assembly】用汇编写的一个BMP图片读取器的更多相关文章

  1. 【Android】内存卡图片读取器,图库app

    上一篇<[Android]读取sdcard卡上的全部图片而且显示,读取的过程有进度条显示>(点击打开链接)在真机上測试非常有问题.常常遇到内存溢出.卡死的情况.由于如今真机上的内存上,2G ...

  2. 恶意软件开发——编写第一个Loader加载器

    一.什么是shellcode loader? 上一篇文章说了,我们说到了什么是shellcode,为了使我们的shellcode加载到内存并执行,我们需要shellcode加载器,也就是我们的shel ...

  3. 图片拾取器-PicPicker

    最近报名参加了360前端星计划,想当一名前端实习生,学习更多更流行的前端知识.然后需要完成一个作业,才能进培训,进了培训还得看运气才能留下,流程不少.书归正传,请看: 课后作业题目 请从下面两个题目中 ...

  4. mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换等

    mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换(上) MP3文件格式(二)---ID3v2 图:ID3V1标签结构 图:ID3V2标签 ...

  5. 关于Opengl中将24位BMP图片加入�一个alpha通道并实现透明的问题

    #include <windows.h>#include <GL/glut.h>#include <GL/glaux.h>#include <stdio.h& ...

  6. 关于Opengl中将24位BMP图片加入一个alpha通道并实现透明的问题

    #include <windows.h>#include <GL/glut.h>#include <GL/glaux.h>#include <stdio.h& ...

  7. bmp图片格式及读取

    C++读取bmp图片的例子 #include <windows.h> #include <stdio.h> #include <stdlib.h> #include ...

  8. [转]opengl入门例题(读取bmp图片,并显示)

    #include<gl/glut.h> #define FileName "bliss.bmp" static GLint imagewidth; static GLi ...

  9. 用Delphi直接获取bmp图片的像素

    用Delphi直接获取bmp图片的像素,并存储显示出.(此像素主要用在LED上显示).希望高手能给出代码啊!! function getImagePixels(f: string): Integer; ...

随机推荐

  1. 免費域名申請.me .im .in .co .la .do .ms .kz .tk .ru .mu .pn .tt

    免費申請域名 .la .la 域名 – 原先是ICANN分配給老撾的國家頂級域名,不過後來被同時作為了美國洛杉矶市的域名後綴. 免費申請地址: http://www.idv.la http://www ...

  2. mysql取字段名注意事项!!!!千万不能和关键字同名

    今天就碰到一个恶心的问题,更新时update sql语句报错,查了半天感觉没问题啊,后来一行一行定位,终于找到原因了, 原来是有个字段是show,和mysql关键字冲突了,坑爹! 改了个名字就好了,或 ...

  3. python学习之argparse模块的使用

    以下内容主要来自:http://wiki.jikexueyuan.com/project/explore-python/Standard-Modules/argparse.html argparse ...

  4. Linux Module框架【转】

    转自:http://www.cnblogs.com/LittleHann/p/4558719.html catalog 1. 概述 2. 使用模块 3. 插入和删除模块 4. 自动化与热插拔 5. 版 ...

  5. 007_苹果Mac系统锁屏不待机效果设置方法介绍

    Mac如何设置锁屏不断网?Mac如何设置锁屏不待机?这是一个非常麻烦的设置,有时候一锁屏幕电脑就跟着待机了,这非常的麻烦,所以今天小编就用图文教程的方式教大家Mac如何设置锁屏不断网Mac如何设置锁屏 ...

  6. python网络编程-动态导入和断言

    一:动态导入importlib 在程序运行的过程中,根据变量或者配置动态的决定导入哪个模块,可以使用模块importlib importlib使用示例 二:断言assert 如果接下来的程序依赖于前面 ...

  7. CSS3小黄人

    CSS3实现小黄人 效果图: 代码如下,复制即可使用: <!DOCTYPE HTML> <HTML> <head> <title>CSS3实现小黄人&l ...

  8. T-sql语句修改数据库逻辑名、数据库名、物理名(sql2000)

    --更改MSSQL数据库物理文件名Sql语句的写法 --注意:要在活动监视器里面确保没有进程连接你要改名的数据库!!!!!!!!!!!!!!!!!!!! -- Sql语句如下 USE master - ...

  9. jboss各种测试方式归类

      不跨工程访问(如:HBase) 跨工程访问(如:Business) 不部署到服务器上 部署到服务器上 不部署到服务器上 部署到服务器上 Junit测试 实例化直接调用 true true Fals ...

  10. XeLaTeX下如何以原大小显示PNG

    在XeLaTeX里直接使用\includegraphics{test.png}这样的命令引入PNG,可能会发现图片直接被缩放到占满文档宽度,这是因为PNG这种bitmap类型的图片里通常不会带上met ...