美文网首页
[015][x86汇编语言]BIOS中断,从键盘读取字符并显示

[015][x86汇编语言]BIOS中断,从键盘读取字符并显示

作者: AkuRinbu | 来源:发表于2018-05-26 05:32 被阅读0次

    学习笔记

    《x86汇编语言:从实模式到保护模式》
    https://www.jianshu.com/p/d481cb547e9f

    使用BIOS中断,从键盘读取字符并显示

    使用BIOS中断,从键盘读取字符并显示

    代码参考

    配书代码 c09_2.asm

    BIOS 与 DOS 的区别

    BIOS 与 DOS 的区别-1
    BIOS 与 DOS 的区别-2

    《汇编语言(第三版)》王爽 第258-259页

    BIOS是如何建立起调用中断的?

    BIOS是如何建立起调用中断的-1
    BIOS是如何建立起调用中断的-2

    《x86汇编语言:从实模式到保护模式》第164-165页

    中断类型:硬件中断、内部中断 、软中断

    中断类型:硬件中断、内部中断 、软中断

    完整源程序:用户程序 code_9-2.asm(增加注释)

             ;代码清单9-2
             ;文件名:code_9-2.asm
             ;文件说明:用于演示BIOS中断的用户程序 
             ;创建日期:5:02 2018/5/27
             
    ;===============================================================================
    SECTION header vstart=0                     ;定义用户程序头部段 
        program_length  dd program_end          ;程序总长度[0x00]
        
        ;用户程序入口点
        code_entry      dw start                ;偏移地址[0x04]
                        dd section.code.start   ;段地址[0x06] 
        
        realloc_tbl_len dw (header_end-realloc_begin)/4
                                                ;段重定位表项个数[0x0a]
        
        realloc_begin:
        ;段重定位表           
        code_segment    dd section.code.start   ;[0x0c]
        data_segment    dd section.data.start   ;[0x14]
        stack_segment   dd section.stack.start  ;[0x1c]
        
    header_end:                
        
    ;===============================================================================
    SECTION code align=16 vstart=0           ;定义代码段(16字节对齐) 
    start:
            mov ax,[stack_segment]
            mov ss,ax
            mov sp,ss_pointer
            mov ax,[data_segment]
            mov ds,ax
            
            mov cx,msg_end - message
            mov bx,message
            
        .putc:
            mov ah,0x0e     ;在寄存器ah中指定功能号0x0e
            mov al,[bx]     ;在寄存器al中指定要显示的字符
            int 0x10        ;执行中断0x10 的 0x0e号功能
            inc bx          ;       在屏幕上的光标处写一个字符,并且推进光标位置
            loop .putc  
    
        .reps:
            mov ah,0x00     ;在寄存器ah中指定功能号0x00
            int 0x16        ;执行中断0x16的0x00号功能:从键盘读字符
                            ;返回字符的ASCII码到寄存器al
            mov ah,0x0e     
            mov bl,0x07     ;???
            int 0x10        ;执行中断0x10的0x0e号功能
            
            jmp .reps
            
    ;===============================================================================
    SECTION data align=16 vstart=0
    
        message       db 'Hello, friend!',0x0d,0x0a
                      db 'This simple procedure used to demonstrate '
                      db 'the BIOS interrupt.',0x0d,0x0a
                      db 'Please press the keys on the keyboard ->'
        msg_end:
                       
    ;===============================================================================
    SECTION stack align=16 vstart=0
               
                     resb 256
    ss_pointer:
     
    ;===============================================================================
    SECTION program_trail
    program_end:
    

    相关文章

      网友评论

          本文标题:[015][x86汇编语言]BIOS中断,从键盘读取字符并显示

          本文链接:https://www.haomeiwen.com/subject/cjnvjftx.html