zoukankan      html  css  js  c++  java
  • Hello,world! x86版本

    1. 使用nasm编译,得到boot.bin
    2. 烧写到U盘MBR(注意,一旦U盘MBR被修改,Windows将无法读取U盘内容,所以请先备份MBR)
    3. 从USB启动

    程序主要用到BIOS中断,关于BIOS中断大体就是用寄存器做参数,中断号是功能。编译过程

    >nasm boot.asm –o boot.bin


    ; boot.asm 

    ;%define bootloader     ;如果是MBR定义这行宏

    %ifdef bootloader
    %define org_start 7c00h
    %else
    %define
    org_start 0100h
    %endif

    boot:
        org
    org_start ;告诉编译器,以后的代码从org_start算偏移地址;
       
    mov ax,cs      ;让ds es都为cs内容;
       
    mov ds,ax      ;11行cx的[]可以正确得到地址的内容;
       
    mov es,ax      ;10行bp es:bp指向正确的串地址;
       
    call print      ;打印hello ;
       
    jmp $          ;死循环 ;


    print:
        mov
    bp,str_hello        ;ES:BP = 串地址,基地址指针
       
    mov cx,[str_hello_size] ;CX = 串长度
       
    mov ax,01301h            ;AH = 13, AL = 01h
       
    mov bx,000ch            ;BH页号 BL 黑底红字(BL = 0Ch)
       
    mov dx,0000h            ;DH行 DL列
       
    int 10h                    ;10h号中断 BIOS调用
       
    ret 

    str_hello
        db
    "Hello,world!" 
    str_hello_size:
        db $-
    str_hello
    fill
    :
        times
    510-($-$$) db 0 ;填充剩余空间 
       
    dw 0xaa55              ;MBR标志
  • 相关阅读:
    2020面向对象程序设计寒假作业2 题解
    题解 P3372 【【模板】线段树 1】
    Global variant VS local variant
    u2u
    深入浅出PowerShell系列
    深入浅出WF系列
    debug
    深入浅出SharePoint系列
    InfoPath debug
    深入浅出Nintex系列
  • 原文地址:https://www.cnblogs.com/iwasmu/p/1525108.html
Copyright © 2011-2022 走看看